Chapter 7. Mathematical Expressions and Scripting

Table of Contents
muParser
Python

QtiPlot supports two different interpreters for evaluating mathematical expressions and for executing scripts: muParser and Python. muParser can be only used for the evaluation of mathematical expressions, whereas Python can be used to execute scrips. The default interpreter is muParser therefore if you want to execute scripts you should first enable the Python scripting engine via the Scripting language dialog. Also, you can define the default scripting interpreter via the General tab of the Preferences dialog.

muParser

The constants _e=e=E and _pi=pi=PI=Pi are defined, as well as the following fundamental physical constants, operators and functions. Please note that the fundamental constants cannot be redefined. Doing so will raise an error message. The values of the physical constants listed bellow are defined using the standard MKSA unit system (meters, kilograms, seconds, amperes):

Table 7-1. muParser: Predefined Fundamental Physical Constants in the standard MKSA unit system

NameDescription
cThe speed of light in vacuum
eVThe energy of 1 electron volt
gThe standard gravitational acceleration on Earth
GThe gravitational constant
hPlanck's constant
hbarPlanck's constant divided by 2 pi
kThe Boltzmann constant
NaAvogadro's number
R0The molar gas constant
V0The standard gas volume
RyThe Rydberg constant, in units of energy

Table 7-2. muParser: Supported Mathematical Operators

NameDescription
+Addition
-Subtraction
*Multiplication
/Division
%Modulus operator (returns the remainder of a when divided by b)
^Exponentiation (raise a to the power of b)
<less than (returns 0 or 1)
<=less than or equal (returns 0 or 1)
==equal (returns 0 or 1)
>=greater than or equal (returns 0 or 1)
>greater than (returns 0 or 1)
!=not equal (returns 0 or 1)
?:if-then-else operator: condition ? return value if true : return value if false.

Table 7-3. muParser: Mathematical Functions

NameDescription
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_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.
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).
erfz(x)The Gaussian probability density function Z(x).
erfq(x)The upper tail of the Gaussian probability function Q(x).
exp(x)Exponential function: e raised to the power of x.
gamma(x)Computes the Gamma function, subject to x not being a negative integer
gammaln(x)Computes the logarithm of the Gamma function, subject to x not a being negative integer. For x<0, log(|Gamma(x)|) is returned.
hazard(x)Computes the hazard function for the normal distribution h(x) = erfz(x)/erfq(x).
ln(x)natural (base e) logarithm of x
log(x)natural (base e) logarithm of x
log10(x)decimal (base 10) logarithm of x
log2(x)base 2 logarithm of x
min(x1,x2,x3,...)Minimum of the list of arguments
max(x1,x2,x3,...)Maximum of the list of arguments
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

Table 7-4. muParser: Other functions

NameDescription
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.
col(c)Only works in the context of a table. Returns the value at column c and row i (the current row) in the context table. c can either be the column's number, or its name in doublequotes.
if(e1,e2,e3)if e1 is true, e2 is executed else e3 is executed. The evaluation of e1, e2 and e3 must return numerical values only. Strings of characters are not accepted.
tablecol(t,c)Only works in the context of a table. Returns the value at column c and row i (the current row) in the table t. t is the table's name in doublequotes, c is either the column's number or its name in doublequotes.
derivative(yCol, xCol, row)Calculates the derivative of column with index yCol with respect to column with index xCol from the current table.
interp(y,i,x)Takes a column name y, in doublequotes, and the corresponding abscissae stored in the column with index i from the same data table and linearly interpolates an ordinate at a given abscissa x. Only works in the context of a table.
AVG(n,i,j)The average of all cells from row i to j in column with name n (in doublequotes). A negative value of the end row j means the last table row. Only works in the context of a table.
MIN(n,i,j)The minimum value of all cells from row i to j in column with name n (in doublequotes). A negative value of the end row j means the last table row. Only works in the context of a table.
MAX(n,i,j)The maximum value of all cells from row i to j in column with name n (in doublequotes). A negative value of the end row j means the last table row. Only works in the context of a table.
SD(n,i,j)The standard deviation of all cells from row i to j in column with name n (in doublequotes). A negative value of the end row j means the last table row. Only works in the context of a table.
SUM(n,i,j)The sum of all cells from row i to j in column with name n (in doublequotes). A negative value of the end row j means the last table row. Only works in the context of a table.
rms(n,i,j)The root mean square of all cells from row i to j in column with name n (in doublequotes). A negative value of the end row j means the last table row. Only works in the context of a table.