Next: , Previous: , Up: General concepts   [Contents][Index]


4.6 Textual formulas

MathGL have the fast variant of textual formula evaluation (see Evaluate expression) . There are a lot of functions and operators available. The operators are: ‘+’ – addition, ‘-’ – subtraction, ‘*’ – multiplication, ‘/’ – division, ‘%’ – modulo, ‘^’ – 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, ‘int(x)’ – integer part of x, ‘rnd’ – random number, ‘random(x)’ – random data of size as in x, ‘hypot(x,y)’=sqrt(x^2+y^2) – hypotenuse, ‘cmplx(x,y)’=x+i*y – complex number, ‘pi’ – number π = 3.1415926…, inf=∞

Functions for complex numbers ‘real(x)’, ‘imag(x)’, ‘abs(x)’, ‘arg(x)’, ‘conj(x)’.

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 Γ(x) = ∫0 tx-1 exp(-t) dt, ‘gamma_inc(x,y)’ – incomplete Gamma function Γ(x,y) = ∫y tx-1 exp(-t) dt, ‘psi(x)’ – digamma function ψ(x) = Γ′(x)/Γ(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 Li2(x) = -ℜ∫0xds log(1-s)/s, ‘sinc(x)’ – compute sinc(x) = sin(πx)/(πx) for any value of x, ‘zeta(x)’ – Riemann zeta function ζ(s) = ∑k=1k-s for arbitrary s≠1, ‘eta(x)’ – eta function η(s) = (1 - 21-s)ζ(s) for arbitrary s, ‘lp(l,x)’ – Legendre polynomial Pl(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) = ∫0xdt cos(t)/t, ‘si(x)’ – Sine integral Si(x) = ∫0xdt sin(t)/t, ‘erf(x)’ – error function erf(x) = (2/√π) ∫0xdt exp(-t2) , ‘ei(x)’ – exponential integral Ei(x) = -PV(∫-xdt exp(-t)/t) (where PV denotes the principal value of the integral), ‘e1(x)’ – exponential integral E1(x) = ℜ∫1dt exp(-xt)/t, ‘e2(x)’ – exponential integral E2(x) = ℜ∫1∞dt exp(-xt)/t2, ‘ei3(x)’ – exponential integral Ei3(x) = ∫0xdt exp(-t3) 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(π/2,k), ‘ek(k)’ – complete elliptic integral is denoted by K(k) = F(π/2,k), ‘e(phi,k)’ – elliptic integral E(φ,k) = ∫0φdt √(1 - k2sin2(t)), ‘f(phi,k)’ – elliptic integral F(φ,k) = ∫0φdt 1/√(1 - k2sin2(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 MathGL was compiled without GSL support.

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.

MathGL version 2.5 introduce user-defined functions ‘fn1()...fn9()’ at formula evaluation, which are defined after symbol ‘\’. For example, "fn1(3)\x^_1" will produce "x^3". Also functions ‘sum’, ‘dsum’, ‘prod’ are added at formula evaluation for summation, summation with variable sign and product evaluation. For example, "sum(_i^2,5)" will produce "30"=0+1^2+2^2+3^2+4^2, "dsum(_i^2,5)" will produce "10"=0-1^2+2^2-3^2+4^2, and "prod(1+_i,5)" will produce 5!="120". You can nest them for variables _i,_j,...,_z, like "sum(sum(_j+_i^2,5),5)" will give "200". Also you can use user-defined functions, like "sum(fn1(_i)-fn2(_i),4)\_1^4\_1^3" is the same as "sum(_i^4-_i^3,4)" and will produce "62".


Next: , Previous: , Up: General concepts   [Contents][Index]