MuParser: Difference between revisions
(Created page with "The constants _e=e=E and _pi=pi=PI=Pi are defined, as well as the operators and functions listed below. muParser is purely a parser for mathematical expressions and as such does not support executing complex scripts. However, you can make formulas easier to read and modify by assigning sub-expressions to variables and inserting comments. Variable assignments evaluate to the assigned value, so they can be used in the middle of a formula. They can also stand on a line of...") |
No edit summary |
||
Line 28: | Line 28: | ||
|- | |- | ||
|&& | |&& | ||
|logical and (returns 0 or 1) - works only if | |logical and (returns 0 or 1) - works only if LabRPS is built using muParser >= 2.0.0 | ||
|- | |- | ||
|ΙΙ | |ΙΙ | ||
|logical or (returns 0 or 1) - works only if | |logical or (returns 0 or 1) - works only if LabRPS is built using muParser >= 2.0.0 | ||
|- | |- | ||
|< | |< | ||
Line 210: | Line 210: | ||
|- | |- | ||
|e1?e2:e3 | |e1?e2:e3 | ||
|if e1 is true, e2 is executed else e3 is executed (C++ style syntax; works only if | |if e1 is true, e2 is executed else e3 is executed (C++ style syntax; works only if LabRPS is built using muParser >= 2.0.0). | ||
|} | |} | ||
Use these in Table Controls formula tabe, fitting and function2D/3D Plot formulas | Use these in Table Controls formula tabe, fitting and function2D/3D Plot formulas |
Latest revision as of 11:14, 7 August 2022
The constants _e=e=E and _pi=pi=PI=Pi are defined, as well as the operators and functions listed below. muParser is purely a parser for mathematical expressions and as such does not support executing complex scripts. However, you can make formulas easier to read and modify by assigning sub-expressions to variables and inserting comments.
Variable assignments evaluate to the assigned value, so they can be used in the middle of a formula. They can also stand on a line of their own, or separated from other parts of the formula by a semicolon (;). The result of evaluating the last line of a multi-line formula is taken as the result of the whole formula.
Comments start with a hash mark (#) and run till the end of the line.
It is important to note that the muParser commands listed in this section are intended to be used to work inside the Formula tab of a Table, i.e. most of them will not work as a script in a Note. Of course, if one try to execute something like 'a=cos(pi*pi)' in a Note, it will run without errors, but the 'a' value will not be known by the user.
Supported Mathematical Operators
Mathematical Operators | |
---|---|
+ | Addition |
- | Substraction |
* | Multiplication |
/ | Divition |
^ | Exponentiation (raise a to the power of b) |
&& | logical and (returns 0 or 1) - works only if LabRPS is built using muParser >= 2.0.0 |
ΙΙ | logical or (returns 0 or 1) - works only if LabRPS is built using muParser >= 2.0.0 |
< | less then (returns 0 or 1) |
<= | less then or equal (returns 0 or 1) |
== | equal (returns 0 or 1) |
>= | grater then or equal (returns 0 or 1) |
> | grater then (returns 0 or 1) |
!= | not equal (returns 0 or 1) |
Use these in Table Controls formula tabe, fitting and function2D/3D Plot formulas
Mathematical Functions
Mathematical Functions | |
---|---|
abs(x) | absolute value of x |
acos(x) | inverse cosine |
acosh(x) | inverse hyperbolic cosine |
asin(x) | inverse sine |
asinh(x) | inverse hyperbolic sine |
atan(x) | inverse tangent |
atanh(x) | inverse hyperbolic tangent |
avg(x1,x2,x3,...) | average value, this command accept a list of arguments separated by commas |
bessel_j0(x) | Regular cylindrical Bessel function of zeroth order, J0(x). |
bessel_j1(x) | Regular cylindrical Bessel function of first order, J1(x). |
bessel_jn(x,n) | Regular cylindrical Bessel function of nth order, Jn(x). |
bessel_jn_zero(n, s) | sth zero of regular cylindrical Bessel function of nth order, Jn(bessel_jn_zero(n,s))=0 |
bessel_y0(x) | Irregular cylindrical Bessel function of zeroth order, Y0(x) for x>0. |
bessel_y1(x) | Irregular cylindrical Bessel function of first order, Y1(x) for x>0. |
bessel_yn(x,n) | Irregular cylindrical Bessel function of nth order, Yn(x) for x>0. |
beta(a,b) | Computes the Beta Function, B(a,b) = Gamma(a)*Gamma(b)/Gamma(a+b) for a > 0 and b > 0. |
ceil(x) | ceiling; smallest integer greater or equal to x |
cos(x) | cosine of x |
cosh(x) | hyperbolic cosine of x |
erf(x) | error function of x |
erfc(x) | Complementary error function erfc(x) = 1 - erf(x). |
erfq(x) | The upper tail of the Gaussian probability function Q(x). |
erfz(x) | The Gaussian probability density function Z(x). |
exp(x) | Exponential function: e raised to the power of x. |
floor(x) | floor; largest integer less than or equal to x. |
gamma(x) | Computes the Gamma function, subject to x not being a negative integer. |
gammaln(x) | Gamma(x)|) is returned. |
hazard(x) | Computes the hazard function for the normal distribution h(x) = erfz(x)/erfq(x). |
ln(x) | natural logarithm of x |
log(x) | decimal logarithm of x |
log2(x) | base 2 logarithm of x |
w0(x) | Principal branch of Lambert's W function, W0(x). W0 is defined as a solution to the equation W0(x)*exp(W0(x))=x. For x<0, there are tow real-valued branches; this function computes the one where W>-1 for x<0 (compare w1(x)). |
w1(x) | Secondary branch of Lambert's W function, W-1(x). W-1 is defined as a solution to the equation W-1(x)*exp(W-1(x))=x. For x<0, there are tow real-valued branches; this function computes the one where W<-1 for x<0 (compare w0(x)). |
min(x1,x2,x3,...) | Minimum of the list of arguments |
max(x1,x2,x3,...) | Maximum of the list of arguments |
mod(x,y) | x modulo y; remainder of integer division x/y |
pow(x,y) | x to the power of y, x^y |
rint(x) | Round to nearest integer. |
sign(x) | Sign function: -1 if x<0; 1 if x>0. |
sin(x) | sine of x |
sinh(x) | hyperbolic sine of x |
sqrt(x) | square root of x |
tan(x) | tangent of x |
tanh(x) | hyperbolic tangent of x |
Use these in Table Controls formula tabe, fitting and function2D/3D Plot formulas
Non Mathematical Functions
Non Mathematical Functions | |
---|---|
cell(a,b) | In the context of a matrix, returns the value at row a and column b. In the context of a table, returns the value at column a and row b (remember that tables use column logic). Everywhere else, this function is undefined. In the case of tables, the column is specified as a path string; see the documentation of column() for supported path formats. |
cell_(column, row) | In the context of a table, return the value of a cell specified using 1-based indexes. Wherever possible, you should use cell() instead, because inserting/removing/moving columns will break formulas using cell_(). |
column("path") | In a column formula, returns the value in the given column and current row (i). The column path can either be the name of column in the current table, more generally a relative path to a column in another table (e.g. "../otherTable/col") or an absolute path (i.e., relative to the project root; e.g. "/folder/otherTable/col"). Searching for a table anywhere in the project using "otherTable/col" (without the leading slash) is supported for backward-compatibility reasons, but is strongly discouraged - a future release will drop the requirement of project-wide unique table names, at which point this usage will cease to be well-defined. |
column_(index) | In a column formula, returns the value in the column given by 1-based index and current row (i). You should use column() wherever possible because inserting/ removing/moving columns will break formulas using column_(). |
e1?e2:e3 | if e1 is true, e2 is executed else e3 is executed (C++ style syntax; works only if LabRPS is built using muParser >= 2.0.0). |
Use these in Table Controls formula tabe, fitting and function2D/3D Plot formulas