Numerical integration: Difference between revisions

→‎top: minor: format
(Add Swift)
(→‎top: minor: format)
Line 1:
{{task|Arithmetic operations}}
 
Write functions to calculate the definite integral of a function &nbsp; &nbsp; <big><big> <span style{{math|1="font-family: serif">''ƒ(x)''</span>}} </big></big> &nbsp; &nbsp; using &nbsp; ''all'' &nbsp; five of the following methods:
::* &nbsp; [[wp:Rectangle_method|rectangular]]
::::* &nbsp; * left
::::* &nbsp; * right
::::* &nbsp; * midpoint
::* &nbsp; [[wp:Trapezoidal_rule|trapezium]]
::* &nbsp; [[wp:Simpson%27s_rule|Simpson's]] (composite)
 
<br>
Your functions should take in the upper and lower bounds &nbsp; (<span style="font-family: serif">''a''</span> &nbsp; and &nbsp; <span style="font-family: serif">''b''</span>), &nbsp; and the number of approximations to make in that range &nbsp; (<span style="font-family: serif">''n''</span>).
 
Your functions should take in the upper and lower bounds &nbsp; (<span style="font-family: serif">{{math|''a''</span> &nbsp;}} and &nbsp; <span style="font-family: serif">{{math|''b''</span>}}), &nbsp; and the number of approximations to make in that range &nbsp; (<span style="font-family: serif">{{math|''n''</span>}}).
Assume that your example already has a function that gives values for &nbsp; &nbsp; <big> <span style="font-family: serif">''ƒ(x)''</span>. </big>
 
Assume that your example already has a function that gives values for &nbsp; &nbsp; <big> <span style{{math|1="font-family: serif">''ƒ(x)''</span>.}} </big> .
 
Simpson's method is defined by the following pseudo-code:
Line 28:
 
Demonstrate your function by showing the results for:
* <big> {{math|1=ƒ(x) = x<sup>3</sup>}}, </big> &nbsp; where &nbsp; &nbsp; '''x''' &nbsp; &nbsp; is &nbsp; [0,1], &nbsp; with 100 approximations. &nbsp; The exact result is &nbsp; 1/4, &nbsp; or &nbsp; 0.25.
* <big> {{math|1=ƒ(x) = 1/x}}, </big> &nbsp; where &nbsp; '''x''' &nbsp; is &nbsp; [1,100], &nbsp; with 1,000 approximations. &nbsp; The exact result is the natural log of 100, &nbsp; or about &nbsp; 4.605170
* <big> {{math|1=ƒ(x) = x}}, </big> &nbsp; &nbsp; where &nbsp; '''x''' &nbsp; is &nbsp; [0,5000], &nbsp; with 5,000,000 approximations. &nbsp; The exact result is &nbsp; 12,500,000.
* <big> {{math|1=ƒ(x) = x}}, </big> &nbsp; &nbsp; where &nbsp; '''x''' &nbsp; is &nbsp; [0,6000], &nbsp; with 6,000,000 approximations. &nbsp; The exact result is &nbsp; 18,000,000.
 
<br/>
 
<br>
'''See also'''
* [[Active object]] for integrating a function of real time.
* [[Special:PrefixIndex/Numerical integration/Gauss-Legendre Quadrature]] for anotherother integration methodmethods.
 
<br><br>
<br/>
 
=={{header|ActionScript}}==
17

edits