playground:playground

This is an old revision of the document!


Numeric integration of symbolic expressions is implemented in newRPL via the NUMINT command which implements the Adaptive Simpson's method.

NUMINT accepts four arguments:

  • the mono-variate function to integrate, either in symbolic or program form;
  • the lower integration limit;
  • the upper integration limit;
  • the error tolerance.

If the function to integrate is expressed in symbolic form it must respect a precise syntax:

  • it must be written as an equation;
  • the left side must be in the form func(var) where var is the integrating variable and func is the function's name;
  • the right side is a function, expressed in terms of var.

For example valid expressions are:

F(X)=X*LN(X)
G(Z)=Z^2-2*COS(Z)
VEL(T)=ACC*T

As shown above, the functions may refer to global or local variables; the function's name is only descriptive and bears no relevance to the calculation.

Alternatively, the function can be written as a program which accepts exactly one numeric argument and returns exactly one numeric result. The expressions above can be rewritten as:

« DUP LN * »
« DUP SQ SWAP COS 2 * - »
« 'ACC' RCL * »

The integration limits can be either real or complex finite numbers; symbolic constants are accepted and silently converted to numerical values.

The error tolerance is a real number used to specify the required precision of the calculation: when two successive iterations differ by a value which is less than the tolerance the calculation stops.


Examples

The following examples are calculated with 16 precision digits using three different tolerances. If available, the analytic result is provided for comparison.

Function Tolerance Exact Solution
1E-4 1E-8 1E-12
$ \int^{5/4}_{0} \cos x^2 \,dx $ 0.977 4 0.977 437 67 0.977 437 670 720 $ \sqrt\frac{\pi}{2} C\left(\sqrt\frac{2}{\pi} x\right) \Biggr|^{x=5/4}_{x=0} $ 0.977 437 670 720 3…
$ \int^{2}_{0} e^{-2x}\left(14x-11x^{2}\right) \,dx $ 1.084 2 1.084 260 41 1.084 260 409 719 $ \frac{3}{4}+\frac{73}{4e^{4}} $ 1.084 260 409 719 3…
$ \int^{2}_{0} x^{10}e^{\left(4x^{3}-3x^{4}\right)} \,dx $ 7.258 4 7.258 395 17 7.258 395 170 615 No analytic solution exists 7.258 395 170 614 3…
Warning! The user must take care of implicit substitutions when the expression to integrate contains trigonometric functions. For example, if the angle mode is set to degrees, the expression $ \sin x $ is actually interpreted as $ \sin\left(\frac{\pi}{180}x\right) $, whose anti-derivative is not $-\cos x$, but $-\frac{180}{\pi}\cos\left(\frac{\pi}{180}x\right) $. Unexpected results will follow if the user disregards this occurrence!
  • playground/playground.1632774387.txt.gz
  • Last modified: 2021/09/27 13:26
  • by jojo1973