From NARS2000
Revision as of 03:21, 20 January 2020 by WikiSysop (talk | contribs)
Jump to navigationJump to search
Z←{L} f R returns the definite Integral of the function f between the points L and R.
L is an optional Real numeric singleton which represents the lower bound of the definite Integral. If it is omitted, 0 is used.
R is a Real numeric singleton which represents the upper bound of the definite Integral.
f is an arbitrary monadic function whose argument and result are both Real numeric singletons.




The symbol chosen for this operator is the Integral Sign (), entered from the keyboard as Alt-’S’ or Alt-Shift-'s' (U+222B), and used in mathematics for Integration.


There are many, many applications of Numerical Integration. Here are but a few taken from Whitman College's Mathematics Department's Calculus Online course:

  1. Area between curves
  2. Distance, Velocity, Acceleration
  3. Volume
  4. Average value of a function
  5. Work
  6. Center of Mass
  7. Kinetic energy; improper integrals
  8. Probability
  9. Arc Length
  10. Surface Area

and more taken from the website Interactive Mathematics:

  1. Applications of the Indefinite Integral
  2. Area Under a Curve by Integration
  3. Area Between 2 Curves using Integration
  4. Volume of Solid of Revolution by Integration
  5. Shell Method: Volume of Solid of Revolution
  6. Centroid of an Area by Integration
  7. Moments of Inertia by Integration
  8. Work by a Variable Force using Integration</a>
  9. Electric Charges by Integration
  10. Average Value of a Function by Integration
  11. Force Due to Liquid Pressure by Integration</a>
  12. Arc Length of a Curve using Integration</a>
  13. Arc Length of Curve: Parametric, Polar Coordinates</a>


There are several different algorithms that may be used for Numerical Integration, two of which are Gauss-Legendre and Newton-Cotes. The default algorithm is Gauss-Legendre, however, the faster but less accurate Newton-Cotes algorithm may be selected via the Variant operator as in

      {1+1○⍵}∫⍠'g' ○2x  ⍝ Gauss-Legendre
      {1+1○⍵}∫⍠'n' ○2x  ⍝ Newton-Cotes
      ○2x    ⍝ Exact answer

The Order of the Numerical Integration (the number of rectangles used to approximate the result) is, by default, 128 for the Gauss-Legendre algorithm, and 64 for Newton-Cotes. That number may be changed via the Variant operator as in

      ⎕PP←60 ⋄ ⎕FPC←512
      {÷1+⍵*2}∫⍠'g' N
      {÷1+⍵*2}∫⍠('g' 150) N
      {÷1+⍵*2}∫⍠('g' 170) N
      ¯3○N    ⍝ Exact answer


For example,

The Integral of {⍵*2} is {(⍵*3)÷3}, and so the Integral of that function from 0 to 1 is ÷3:


The Integral of the 1+Sine function from 0 to ○2 is ○2:

      {1+1○⍵}∫○2x ⋄ ○2x

and the Integral of the Sine function from 0 to ○2 is (essentially) 0


A Normal Distribution is defined as nd←{(*¯0.5×⍵*2)÷√○2x}. Integrating it over the entire width from ¯∞ to yields an answer of 1 (the area under the curve). However, this Integration code doesn't handle infinities as yet, so instead we integrate the function over 20 standard deviations on either side with more rectangles used in the approximation to yield a number within rounding error of the correct answer:

      ¯20 nd∫⍠150 20

Integrating this same function for one, two, and three standard deviations on either side yields the 3-sigma rule of :

      ⍪¯1 ¯2 ¯3 nd∫¨ 1 2 3
0.682689492137085897170465091264075844955    ⍝ 68%
0.954499736103641585599434725666933125056    ⍝ 95%
0.997300203936739810946696370464810045244    ⍝ 99.7%

which describes about how many of the values in a normal distribution lie within one, two, and three standard deviations from the mean.

Numerical Differentiation

Note that Derivative, the inverse of this operator, has also been implemented.


This feature is entirely based on Laurent Fousse's Numerical Integration code written in MPFR as described in this paper.