Integral: Difference between revisions

From NARS2000
Jump to navigationJump to search
No edit summary
No edit summary
Line 23: Line 23:
</table>
</table>


==Introduction==
TBD
<br />
<br />
<br />
==Variants==
There are several different algorithms which may be used for Numerical Integration, two of which are [https://en.wikipedia.org/wiki/Gaussian_quadrature Gauss-Legendre] and [https://en.wikipedia.org/wiki/Newton%E2%80%93Cotes_formulas 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
<apll><pre>
      ⎕FPC←128
      {1+1○⍵}∫⍠'g' ○2<_x/>  ⍝ Gauss-Legendre
6.2831853071795864769252867665590057683<_mark>9</_mark>
      {1+1○⍵}∫⍠'n' ○2<_x/>  ⍝ Newton-Cotes
6.2831853071795864769252867665<_mark>5</_mark>899537749
      ○2<_x/>    ⍝ Exact answer
6.28318530717958647692528676655900576839
</pre></apll>
The Order of the Numerical Integration (the number of rectangles used to approximate the result) is, by default, <apll>50</apll>.  That number may be changed via the Variant operator as in
<apll><pre>
      N←17<_x/>
      {÷1+⍵*2}∫⍠'g' N
1.5120405040<_mark>7</_mark>629183188001289665203330309
      {÷1+⍵*2}∫⍠('g' 60) N
1.5120405040791739<_mark>2</_mark>727026418786910512212
      {÷1+⍵*2}∫⍠('g' 70) N
1.512040504079173926<_mark>3</_mark>3179507126314397112
      {÷1+⍵*2}∫⍠('g' 80) N
1.512040504079173926329<_mark>1</_mark>42042030891168
      {÷1+⍵*2}∫⍠('g' 90) N
1.512040504079173926329138<_mark>3</_mark>9289394666393
      ¯3○N    ⍝ Exact answer
1.51204050407917392632913838918797965662
</pre></apll>
==Examples==
For example,
The Integral of <apll>{⍵*2}</apll> is <apll>{(⍵*3)÷3}</apll>, and so the Integral of that function from <apll>0</apll> to <apll>1</apll> is <apll>÷3</apll>:
<apll><pre>
      ⎕FPC←128
      {⍵*2}∫1
0.333333333333333333333333333333333333334   
</pre></apll>
The Integral of the 1+Sine function from <apll>0</apll> to <apll>○2</apll> is <apll>○2</apll>:
<apll><pre>
      {1+1○⍵}∫○2<_x/> ⋄ ○2<_x/>
6.28318530717958647692528676655900576839
6.28318530717958647692528676655900576839
</pre></apll>


==Introduction==
and the Integral of the Sine function from <apll>0</apll> to <apll>○2</apll> is (essentially) <apll>0</apll>
 
<apll><pre>
      {1○⍵}∫○2<_x/>
¯5.12499200004882449667902954237053816394<_E/>¯40
</pre></apll>
 
A [https://en.wikipedia.org/wiki/Normal_distribution Normal Distribution] is defined as <apll>nd←{(*¯0.5×⍵*2)÷√○2<_x/>}</apll>.  Integrating it over the entire width from <apll>¯∞</apll> to <apll>∞</apll> yields an answer of <apll>1</apll> (the area under the curve).  However, this Integration code doesn't handle infinities as yet, so instead we integrate the function over 10 standard deviations on either side to yield a number very close to the correct answer:
 
<apll><pre>
      ¯10 nd∫ 10
0.999999999999207065378727724161962509243
</pre></apll>
 
Integrating this same function for one, two, and three standard deviations on either side yields the [https://en.wikipedia.org/wiki/68%E2%80%9395%E2%80%9399.7_rule 3-sigma rule] of :
 
<apll><pre>
      ⍪¯1 ¯2 ¯3 nd∫¨ 1 2 3
0.682689492137085897170465091264075844955    ⍝ 68%
0.954499736103641585599434725666933125056    ⍝ 95%
0.997300203936739810946696370464810045244    ⍝ 99.7%
</pre></apll>
 
which describes about how many of the values in a normal distribution lie within one, two, and three standard deviations from the mean.

Revision as of 20:53, 10 January 2020

Z←{L} f R returns the definite Integral of the function f between the points L and R.
L is an optional numeric singleton which represents the lower bound of the definite Integral. If it is omitted, 0 is used.
R is a numeric singleton which represents the upper bound of the definite Integral.
f is an arbitrary monadic function.

Introduction

TBD



Variants

There are several different algorithms which 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

      ⎕FPC←128
      {1+1○⍵}∫⍠'g' ○2x  ⍝ Gauss-Legendre
6.28318530717958647692528676655900576839 
      {1+1○⍵}∫⍠'n' ○2x  ⍝ Newton-Cotes
6.28318530717958647692528676655899537749 
      ○2x    ⍝ Exact answer
6.28318530717958647692528676655900576839

The Order of the Numerical Integration (the number of rectangles used to approximate the result) is, by default, 50. That number may be changed via the Variant operator as in

      N←17x
      {÷1+⍵*2}∫⍠'g' N
1.51204050407629183188001289665203330309
      {÷1+⍵*2}∫⍠('g' 60) N
1.51204050407917392727026418786910512212 
      {÷1+⍵*2}∫⍠('g' 70) N
1.51204050407917392633179507126314397112 
      {÷1+⍵*2}∫⍠('g' 80) N
1.512040504079173926329142042030891168
      {÷1+⍵*2}∫⍠('g' 90) N
1.51204050407917392632913839289394666393 
      ¯3○N    ⍝ Exact answer
1.51204050407917392632913838918797965662

Examples

For example,

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

      ⎕FPC←128
      {⍵*2}∫1
0.333333333333333333333333333333333333334    

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

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

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

      {1○⍵}∫○2x
¯5.12499200004882449667902954237053816394E¯40

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 10 standard deviations on either side to yield a number very close to the correct answer:

      ¯10 nd∫ 10
0.999999999999207065378727724161962509243

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.