manpagez: man pages & more
info mathgl
Home | html | info | man
[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

7.2 mglFormula class

Class for evaluating of formula specified by the string. This class is defined in #include <mgl/mgl_eval.h>.

It is the fast variant of formula evaluation. At creation it will be recognized and compiled to tree-like internal code. At evaluation stage only fast calculations are performed. There is no difference between lower or upper case in formulas. If argument value lie outside the range of function definition then function returns NaN.

There are a lot of functions and operators available. The operators are: ‘+’ – addition, ‘-’ – subtraction, ‘*’ – multiplication, ‘/’ – division, ‘^’ – integer power. Also there are logical “operators”: ‘<’ – true if x<y, ‘>’ – true if x>y, ‘=’ – true if x=y, ‘&’ – true if x and y both nonzero, ‘|’ – true if x or y nonzero. These logical operators have lowest priority and return 1 if true or 0 if false.

The basic functions are: ‘sqrt(x)’ – square root of x, ‘pow(x,y)’ power x in y, ‘ln(x)’ – natural logarithm of x, ‘lg(x)’ – decimal logarithm of x, ‘log(a,x)’ – logarithm base a of x, ‘abs(x)’ – absolute value of x, ‘sign(x)’ – sign of x, ‘mod(x,y)’ – x modulo y, ‘step(x)’ – step function, ‘rnd’ – random number, ‘pi’ – number \pi=3.1415926....

Trigonometric functions are: ‘sin(x)’, ‘cos(x)’, ‘tan(x)’ (or ‘tg(x)’). Inverse trigonometric functions are: ‘asin(x)’, ‘acos(x)’, ‘atan(x)’. Hyperbolic functions are: ‘sinh(x)’ (or ‘sh(x)’), ‘cosh(x)’ (or ‘ch(x)’), ‘tanh(x)’ (or ‘th(x)’). Inverse hyperbolic functions are: ‘asinh(x)’, ‘acosh(x)’, ‘atanh(x)’.

There are a set of special functions: ‘gamma(x)’ – Gamma function \Gamma(x) = \int_0^\infty dt t^{x-1} \exp(-t) , ‘psi(x)’ – digamma function \psi(x) = \Gamma'(x)/\Gamma(x) for x!=0, ‘ai(x)’ – Airy function Ai(x), ‘bi(x)’ – Airy function Bi(x), ‘cl(x)’ – Clausen function, ‘li2(x)’ (or ‘dilog(x)’) – dilogarithm Li_2(x) = - \Re \int_0^x ds \log(1-s)/s, ‘sinc(x)’ – compute sinc(x) = \sin(\pi x) / (\pi x) for any value of x, ‘zeta(x)’ – Riemann zeta function \zeta(s) = \sum_{k=1}^\infty k^{-s} for arbitrary s!=1, ‘eta(x)’ – eta function \eta(s) = (1-2^{1-s}) \zeta(s) for arbitrary s, ‘lp(l,x)’ – Legendre polynomial P_l(x), (|x|<=1, l>=0), ‘w0(x)’ – principal branch of the Lambert W function, ‘w1(x)’ – principal branch of the Lambert W function. Function W(x) is defined to be solution of the equation W \exp(W) = x.

The exponent integrals are: ‘ci(x)’ – Cosine integral Ci(x) = \int_0^x dt \cos(t)/t, ‘si(x)’ – Sine integral Si(x) = \int_0^x dt \sin(t)/t, ‘erf(x)’ – error function erf(x) = (2/\sqrt(\pi)) \int_0^x dt \exp(-t^2), ‘ei(x)’ – exponential integral Ei(x) := - PV(\int_{-x}^\infty dt \exp(-t)/t) (where PV denotes the principal value of the integral), ‘e1(x)’ – exponential integral E_1(x) := Re \int_1^\infty dt \exp(-xt)/t , ‘e2(x)’ – exponential integral E_2(x) := Re \int_1^\infty dt \exp(-xt)/t^2, ‘ei3(x)’ – exponential integral Ei_3(x) = \int_0^x dt \exp(-t^3) for x>=0.

Bessel functions are: ‘j(nu,x)’ – regular cylindrical Bessel function of fractional order nu, ‘y(nu,x)’ – irregular cylindrical Bessel function of fractional order nu, ‘i(nu,x)’ – regular modified Bessel function of fractional order nu, ‘k(nu,x)’ – irregular modified Bessel function of fractional order nu.

Elliptic integrals are: ‘ee(k)’ – complete elliptic integral is denoted by E(k) = E(\pi/2, k), ‘ek(k)’ – complete elliptic integral is denoted by K(k) = F(\pi/2, k), ‘e(phi,k)’ – elliptic integral E(\phi,k) = \int_0^\phi dt \sqrt((1 - k^2 \sin^2(t))), ‘f(phi,k)’ – elliptic integral F(\phi,k) = \int_0^\phi dt 1/\sqrt((1 - k^2 \sin^2(t))).

Jacobi elliptic functions are: ‘sn(u,m)’, ‘cn(u,m)’, ‘dn(u,m)’, ‘sc(u,m)’, ‘sd(u,m)’, ‘ns(u,m)’, ‘cs(u,m)’, ‘cd(u,m)’, ‘nc(u,m)’, ‘ds(u,m)’, ‘dc(u,m)’, ‘nd(u,m)’.

Note, some of these functions are unavailable if NO\_GSL is defined during compilation of MathGL library.

Method on mglFormula: mglFormula (const char *str)

Parses the formula str and creates formula-tree. Constructor recursively parses the formula and creates a tree-like structure containing functions and operators for fast further evaluating by Calc() or CalcD() functions.

Method on mglFormula: float Calc (float x, float y=0, float z=0, float u=0)

Evaluates the formula for 'x','r'=x, 'y','n'=y, 'z','t'=z, 'a','u'=u. Error code (if one) can be obtained from function GetError().

Method on mglFormula: float Calc (float x, float y, float z, float u, float v, float w)

Evaluates the formula for 'x'=x, 'y'=y, 'z'=z, 'u'=u, 'v'=v, 'w'=w. Error code (if one) can be obtained from function GetError().

Method on mglFormula: float Calc (float var['z'-'a'+1])

Evaluates the formula for variables in array var['z'-'a']. Error code (if one) can be obtained from function GetError().

Method on mglFormula: float CalcD (float var['z'-'a'+1], char diff)

Evaluates the formula derivation respect to diff for variables in array var['z'-'a']. Error code (if one) can be obtained from function GetError().

Method on mglFormula: int GetError ()

Returns error code: 0 means no error; ERR_LOG means error in logarithm or power functions; ERR_ARC means error in inverse functions (like asin); ERR_SQRT means error in sqrt function.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]
© manpagez.com 2000-2026
Individual documents may contain additional copyright information.