Numerical integration
1
Methods for Numerical Integration
2
Newton-Cotes Formulas
Approximate integrand function f(x) by a polynomial that can then be easily integrated
3
Newton-Cotes Quadrature
4
The Trapezoidal Rule
I = ∫ f (x )dx ≅ ∫ f1 (x )dx
b b
a a
f (b ) − f (a )
f1 (x ) = f (a ) + (x - a )
b-a
b f (b ) − f (a ) f (a ) + f (b )
I = ∫ f (a ) + ( x - a ) dx = (b − a )
a
b-a 2
I ≅ width × average height
All the Newton-Cotes formulas can be expressed in this general average height form 5
Example 1 Single Application of the Trapezoidal Rule
f(x) = 0.2 +25x – 200x2 + 675x3 – 900x4 + 400x5
Integrate f(x) from a=0 to b=0.8
b = 0.8
True integral value : I = ∫ f ( x )dx = 1.64053
a =0
Solution: f(a)=f(0) = 0.2 and f(b)=f(0.8) = 0.232
f (a ) + f (b)
Trapezoida l Rule : I = (b − a )
2
0.2 + 0.232
= 0. 8 = 0.1728
2
which represents an error of :
E t = 1.64053 − 0.1728 = 1.46773 ε t = 89.5%
The Multiple-Application Trapezoidal Rule
• The accuracy can be improved by dividing the
interval from a to b into a number of segments
and applying the method to each segment.
• The areas of individual segments are added to
yield the integral for the entire interval.
b−a
h= n = # of seg. a = x0 b = xn
n
x1 x2 xn
I= ∫ f ( x)dx + ∫ f ( x)dx + L + ∫ f ( x)dx
x0 x1 xn−1
Using the trapezoidal rule, we get:
f ( x0 ) + f ( x1 ) f ( x1 ) + f ( x 2 ) f ( x n −1 ) + f ( x n )
I =h +h +L+ h
2 2 2
b−a n −1
I= f ( x 0 ) + f ( x n ) + 2∑ f ( x i )
2n i =1 7
8
Example 2
10
Example 3
11
12
Example 4
The vertical distance covered by a rocket from to seconds is
given by:
30
140000
x = ∫ 2000 ln − 9.8t dt
8 140000 − 2100t
a) Use two-segment Trapezoidal rule to find the distance covered.
b) Find the true error, Et for part (a).
c) Find the absolute relative true error, ∈a for part (a).
Solution
a) The solution using 2-segment Trapezoidal rule is
b−a n −1
I= f ( a ) + 2 ∑ f ( a + ih ) + f ( b )
2n i =1
n=2 a=8 b = 30
b−a 30 − 8
h= = = 11
n 2
Solution (cont)
Then:
30 − 8 2 −1
I= f ( 8 ) + 2 ∑ f ( a + ih ) + f ( 30 )
2( 2 ) i =1
22
= [ f ( 8 ) + 2 f ( 19 ) + f ( 30 )]
4
22
= [177.27 + 2( 484.75 ) + 901.67]
4
= 11266 m
Solution (cont)
b) The exact value of the above integral is
30
140000
x = ∫ 2000 ln − 9 . 8t dt = 11061 m
8 140000 − 2100t
so the true error is
E t = True Value − Approximate Value
= 11061− 11266
Solution (cont)
The absolute relative true error, ∈t , would be
True Error
∈t = × 100
True Value
11061 − 11266
= × 100
11061
= 1.8534%
Solution (cont)
Table 1 gives the values n Value Et ∈t % ∈a %
obtained using multiple 1 11868 -807 7.296 ---
segment Trapezoidal rule for 2 11266 -205 1.853 5.343
30 3 11153 -91.4 0.8265 1.019
140000
x = ∫ 2000 ln − 9. 8t dt 4 11113 -51.5 0.4655 0.3594
8 140000 − 2100t
5 11094 -33.0 0.2981 0.1669
6 11084 -22.9 0.2070 0.09082
Exact Value=11061 m
7 11078 -16.8 0.1521 0.05482
8 11074 -12.9 0.1165 0.03560
Table 1: Multiple Segment Trapezoidal Rule Values
Example 5
19
Example 6
21
22
23
Romberg Integration
Successive application of the trapezoidal rule to attain efficient numerical integrals of functions.
Richardson’s Extrapolation:
Uses two estimates of an integral to compute a third and more accurate approximation.
I = I ( h ) + E ( h) h = (b − a) / n n = (b − a ) / h
I (h1 ) + E (h1 ) = I (h2 ) + E (h2 ) I = exact value of integral E(h) = the truncation error
I(h): trapezoidal rule (n segments, step size h)
b−a 2 2
E ≅ h f ′′ = O ( h ) (assume f ′′ is constant for different step sizes)
12
2
E (h1 ) h 2
h1
≅ 1
2
⇒ E (h1 ) ≅ E (h2 )
E (h2 ) h 2 h2
I (h2 ) − I (h1 )
I (h1 ) + E (h2 )(h1 / h2 ) ≅ I ( h2 ) + E (h2 ) ⇒ E (h2 ) ≅
2
(h1 / h2 )2 − 1
I = I ( h2 ) + E ( h2 ) Improved estimate of the integral.
It is shown that the error of this
I ≅ I ( h2 ) +
1
[I (h2 ) − I (h1 )] estimate is O(h4). Trapezoidal rule
(h1 / h2 ) − 1
2
had an error estimate of O(h2).
I ≅ I (h2 ) +
1
[I (h2 ) − I (h1 )]
(h1 / h2 ) − 1
2
If (h2 = h1 / 2) ⇒ I ≅ I (h2 ) +
1
[I ( h ) − I ( h ) ] =
4
I ( h ) −
1
I (h1 )
2 −1
2 2 1 2
3 3
Example 7
Evaluate the integral of f(x) = 0.2 +25x – 200x2 + 675x3 – 900x4 + 400x5
from a=0 to b=0.8. I (True Integral value) = 1.6405
Segments h Integral εtr% Segments 1 & 2 combined to give :
4 1
1 0.8 0.1728 89.5 I≅ (1.0688) − (0.1728) = 1.3675
3 3
E t = 1.6405 − 1.3675 = 0.273 (ε t = 16.6%)
2 0.4 1.0688 34.9
Segments 2 & 4 combined to give :
4 0.2 1.4848 9.5 4 1
I ≅ (1.4848) − (1.0688) = 1.6234
3 3
In each case, two estimates with E t = 1.6405 − 1.6234 = 0.0171 (ε t = 1%)
error O(h2) are combined to give a
third estimate with error O(h4) 25
Simpson’s Rules
General idea:
Use high order polynomials other than trapezoids to achieve more
accurate integration result but using the similar amount of computation
Parabola Cubic polynomial
26
Simpson’s Rules
• More accurate estimate of an integral is obtained if
a high-order polynomial is used to connect the
points. These formulas are called Simpson’s rules.
Simpson’s 1/3 Rule: results when a 2nd order
Lagrange interpolating polynomial is used for f(x)
a=x0 x1 b=x2
b b
I = ∫ f ( x) dx ≅ ∫ f 2 ( x) dx where f 2 ( x ) is a second - order polynomial.
a a
Using a = x0 b = x2
( x − x1 )( x − x2 ) ( x − x0 )( x − x2 ) ( x − x0 )( x − x1 )
x2
I = ∫ f ( x0 ) + f ( x1 ) + f ( x2 )dx
x0
( x0 − x1 )( x0 − x 2 ) ( x1 − x0 )( x1 − x 2 ) ( x 2 − x0 )( x 2 − x1 )
after integration and algebraic manipulation, the following formula results :
b−a
I≅
h
[ f ( x0 ) + 4 f ( x1 ) + f ( x2 )] h= ⇐ SIMPSON' S 1/3 RULE
3 2
after integration and algebraic manipulation, the following formula results :
b−a
I≅
h
[ f ( x0 ) + 4 f ( x1 ) + f ( x2 )] h= ⇐ SIMPSON' S 1/3 RULE
3 2
28
29
Trapezoidal vs. Simpson’s 1/3 Rule
Example: f(x) = 0.2 + 25x – 200x2 + 675x3 – 900x4 + 400x5 (integral between a=0 and b=0.8)
f (0 ) + f (0.8 )
Trapezoidal: I ≅ (0.8 − 0 ) = 0.1728
2
Et = 1.640533 – 0.1728 = 1.467733 εt = 89.5%
f (0 ) + 4f (0.4 ) + f (0.8 ) 0.2 + 4(2.456 ) + 0.232
Simpson’s 1/3 rule: I ≅ 0.8 = 0.8 = 1.367467
6 6
Et = 1.640533 - 1.367467 = 0.2730667 → ε t = 16.6%
30
Example 8
31
Multiple Application of Simpson’s 1/3 Rule
32
Example 9
33
Example 10
34
35
Example 11
36
37
Simpson’s 3/8 Rule
Simpson’s 1/3 and 3/8 rules can be
Fit a 3rd order Lagrange interpolating applied in tandem to handle
polynomial to four points and integrate multiple applications with odd
number of intervals
b b
I = ∫ f ( x)dx ≅ ∫ f 3 ( x)dx
a a
I ≅ [ f ( x0 ) + 3 f ( x1 ) + 3 f ( x2 ) + f ( x3 )]
3h
8
(b − a )
h =
3
f ( x0 ) + 3 f ( x1 ) + 3 f ( x2 ) + f ( x3 )
I ≅ (b − a )
8 38
Example 12
39
40
Example 13
41
42
Gauss Quadrature
• Gauss quadrature implements a strategy of
positioning any two points on a curve to define a
straight line that would balance the positive and
negative errors.
• Hence the area evaluated under this straight line
provides an improved estimate of the integral.
Gauss Quadrature (cont.)
44
Gauss Quadrature (cont.)
45
Method of Undetermined Coefficients
I ≅ c0 f (a ) + c1 f (b)
• The trapezoidal rule yields exact results when the function
being integrated is a constant or a straight line, such as y=1
and y=x:
(b−a ) / 2
c0 + c1 = ∫ 1 dx
−( b − a ) / 2
(b−a ) / 2
b−a b−a
− c0 + c1 = ∫ x dx
2 2 −( b − a ) / 2
c0 + c1 = b − a
b−a b−a Solve simultaneously
− c0 + c1 =0
2 2
b−a
c0 = c1 =
2
b−a b−a
I= f (a) + f (b) Trapezoidal rule
2 2
Derivation of the Two-Point Gauss-Legendre Formula/
• The object of Gauss quadrature is to determine the equations of
the form
I ≅ c0 f ( x0 ) + c1 f ( x1 )
• However, in contrast to trapezoidal rule that uses fixed end
points a and b, the function arguments x0 and x1 are not fixed
end points but unknowns.
• Thus, four unknowns to be evaluated require four conditions.
• First two conditions are obtained by assuming that the above
eqn. for I fits the integral of a constant and a linear function
exactly.
• The other two conditions are obtained by extending this
reasoning to a parabolic and a cubic functions.
47
Solved simultaneously
c0 = c1 = 1
1
x0 = − = −0.5773503K
3
1
x1 = = −0.5773503K
3
Yields an integral
−1 1
I ≅ f + f estimate that is third
3 3 order accurate
Two-Point Gauss-Legendre Formula
(arbitrary a and b)
I = ∫ f (x )dx
b
a
x=
(b + a ) + (b − a )xd xd = - 1 → x = a
2 xd = 1 → x = b
(b + a ) + (b − a )xd (b + a ) + (b − a )xd
x d =1
I =∫ f d
xd = -1
2 2
b − a 1 (b + a ) + (b − a )xd
I= ∫ f dxd
2 - 1
2
49
Example of Two-Point Gauss-Legendre Formula
Example14: f(x) = 0.2 + 25x – 200x2 + 675x3 – 900x4 + 400x5 (integral between a=0 and b=0.8)
x = 0.4 + 0.4xd x=
(b + a ) + (b − a )xd xd = - 1 → x = a
2 xd = 1 → x = b
dx = 0.4 dxd
I = ∫0 f x dx = 0.4 ∫-1 f (0.4 + 0.4xd )dxd
( )
0.8 1
-1
[
I = 0.4 ∫ 0.2 + 25(0.4 + 0.4xd ) − 200(0.4 + 0.4xd ) 2 + 675(0.4 + 0.4xd ) − 900(0.4 + 0.4xd ) + 400(0.4 + 0.4xd ) dxd
1 3 4 5
]
I ≅ c0 f ( x0 ) + c1 f ( x1 )
I = 0.4 ∫ f d (xd )dxd
1
-1
−1 1
I = 0.4 f d
= 0.4(1.2918525 + 3.2645925) = 1.822578
+ fd
3 3
50
Higher-Point Gauss-Legendre Formula
I ≅ c0 f (x0 ) + c1 f (x1 ) + c2 f (x2 ) + L + cn -1 f (xn -1 )
144 42444 3
two − point
144 44 4244444 3
− point
1444three 44 4442444444443
n − point
Three-point Gauss-Legendre formula: c0 = 0.5555556 x0 = - 0.774596669
c1 = 0.8888889 x1 = 0.0
c2 = 0.5555556 x2 = 0.774596669
Example: f(x) = 0.2 + 25x – 200x2 + 675x3 – 900x4 + 400x5 (integral between a=0 and b=0.8)
I = 0.4 ∫ f d (xd )dxd
1
-1
I = 0.4[c0 f d (x0 ) + c1 f d (x1 ) + c2 f d (x2 )]
I = 0.4[0.555556 f d (- 0.77459669 ) + 0.8888889 f d (0 ) + 0.555556 f d (.77459669 )]
1.640533 51
52
Example 15
53
−1 1
I = 0.5 f d + fd = 0.5(0.768365 + 0.318386 ) = 0.543376
3 3
I = 0.5(0.5555556 * f d (- 0.774596669) + 0.8888889 * f d (0.0) + 0.5555556 * f d (0.774596669 ))
= 0.5(0.5555556 * 0.878598 + 0.8888889 * 0.494845 + 0.5555556 * 0.275778) = 0.540591
54
Gauss Quadrature
Gauss-Chebyshev Formula
55
Gauss Quadrature
Gauss-Hermite Formula
56
Integration Using Matlab
Approximation of Double Integrals Using Matlab
57
Miscellaneous problems #1
58
59
Miscellaneous problems #2
60
61
62
Special Problem 7
63
Homework
1.
2.
3.
4.
5.
6.
64