Professional Documents
Culture Documents
Lecture 5.
Numerical integration
• Trapezoidal rule
• Multi-segment trapezoidal rule
• Richardson extrapolation
• Romberg's method
• Simpson's rule
• Gaussian method
b
I = ∫ f ( x )dx Y
f(x)
a
n
S = ∑ f (ci )Δxi a b X
i =1
xi ≤ ci ≤ xi +1
b
⎡ f ( a ) + f (b ) ⎤ b
∫ f ( x ) dx = (b − a ) ⎢
a ⎣ 2 ⎥⎦ ∫ f ( x)dx ≈ area of trapezoid
a
Y
f(x)
f(b) fI(x)
f(a)
a b X
Example 1:
Velocity v(t) of a rocket from t1=8 s to t2=30 s is given by:
⎡ 140000 ⎤
v(t ) = 2000 ln ⎢ ⎥ − 9.8t
⎣140000 − 2100t ⎦
a) ⎡ f (a ) + f (b) ⎤
I ≈ (b − a ) ⎢ ⎥ a =8 s b = 30 s
⎣ 2 ⎦
⎡ 140000 ⎤
f (t ) = 2000 ln ⎢ ⎥ − 9.8t
⎣140000 − 2100t ⎦
⎡ 140000 ⎤
f (8) = 2000 ln ⎢ ⎥ − 9.8(8) = 177.27 m / s
⎣140000 − 2100(8) ⎦
⎡ 140000 ⎤
f (30) = 2000 ln ⎢ ⎥ − 9.8(30) = 901.67 m / s
⎣140000 − 2100(30) ⎦
30⎛ ⎞
⎡ 140000 ⎤
Δx = ∫ ⎜⎜ 2000 ln ⎢ ⎥ − 9.8t ⎟⎟dt = 11061 m
8⎝ ⎣140000 − 2100t ⎦ ⎠
11061 − 11868
∈t = × 100 = 7 .2959 %
11061
b−a
h=
n a b−a a+2
b−a
a+3
b−a b X
a+ 4
4
for n=4 4
b a+h a + 2h a + ( n −1 ) h b
∫ f ( x )dx = ∫ f ( x )dx + ∫ f ( x )dx + ... + ∫ f ( x )dx + ∫ f ( x )dx
a a a+h a + ( n − 2 )h a + ( n −1 )h
⎡ f (a ) + f (a + h) ⎤ ⎡ f (a + h) + f (a + 2h) ⎤
= h⎢ ⎥ + h⎢ ⎥ + ...
⎣ 2 ⎦ ⎣ 2 ⎦
⎡ f ( a + ( n − 1) h ) + f (b ) ⎤
... + [b − ( a + ( n − 1) h ]⎢ ⎥
⎣ 2 ⎦
b
b−a⎡ ⎧ n −1
⎫ ⎤
∫ f ( x )dx = ⎢ f ( a ) + 2⎨ ∑ f ( a + ih )⎬ + f ( b )⎥
a 2n ⎣ ⎩ i =1 ⎭ ⎦
Example 2:
Velocity v(t) of a rocket from t1=8 s to t2=30 s is given by:
⎡ 140000 ⎤
v(t ) = 2000 ln ⎢ ⎥ − 9.8t
⎣140000 − 2100t ⎦
b−a ⎡ ⎧n −1 ⎫ ⎤
a) I= ⎢ f ( a ) + 2 ⎨∑ f ( a + ih ) ⎬ + f (b ) ⎥
2n ⎣ ⎩ i =1 ⎭ ⎦
b − a 30 − 8
n=2 a=8s b = 30 s h= = = 11s
n 2
30 − 8 ⎡ ⎧2−1 ⎫ ⎤
I= ⎢ f (8) + 2⎨ ∑ f (a + ih)⎬ + f (30)⎥
2( 2) ⎣ ⎩ i =1 ⎭ ⎦
22 22
= [ f (8) + 2 f (19) + f (30)] = [177.27 + 2( 484.75 ) + 901.67]
4 4
= 11266 m
b) true value:
30
⎛ ⎡ 140000 ⎤ ⎞
x = ∫ ⎜ 2000ln⎢ ⎥ − 9.8t ⎟dt = 11061 m
8⎝ ⎣140000 − 2100t ⎦ ⎠
11061 − 11266
∈t = × 100 = 1.8534%
11061
n ∆x Et ∈t % ∈a %
1 11868 -807 7.296 ---
2 11266 -205 1.853 5.343
3 11153 -91.4 0.8265 1.019
4 11113 -51.5 0.4655 0.3594
5 11094 -33.0 0.2981 0.1669
6 11084 -22.9 0.2070 0.09082
7 11078 -16.8 0.1521 0.05482
8 11074 -12.9 0.1165 0.03560
( b − a )3
Et = f " ( ζ ), a < ζ < b
12
The relative error in the multi-segment trapezoidal rule is a sum of errors
for each segment. The relative error within the first segment is given by:
[( a + h ) − a ]3
E1 = f " ( ζ 1 ), a < ζ 1 < a + h
12
h3
= f " ( ζ1 )
12
By analogy:
Ei =
[(a + ih) − (a + (i − 1)h)]
3
f " (ζ i ), a + (i − 1)h < ζ i < a + ih
12
h3
= f " ( ζi )
12
for n-th segment :
[b − {a + ( n − 1 )h}]3
En = f " ( ζ n ), a + ( n − 1 )h < ζ n < b
12
h3
= f" (ζn )
12
The total error in the complex trapezoidal rule is a sum of the errors for a single
segment:
n
3 ∑ f " ( ζi )
n h3 n (b − a ) i =1
Et = ∑ Ei = ∑ f " ( ζi ) =
i =1
12 i =1 12n 2 n
n
∑ f" (ζi )
Formula: i =1
n
yields an approximate average value of the second derivative in the range of
a< x<b
1
Et ∝ α 2
n
Numerical Methods lecture 5 18
Estimation of error
n Value Et ∈t % ∈a %
2 11266 -205 1.854 5.343
Since:
Et = TV − I n
C
≅ TV − I n
(n ) 2
C
≅ TV − I 2 n
(2 n ) 2
I 2n − I n
We get: TV ≅ I 2 n +
3
Example 3:
⎡ 140000 ⎤
v(t ) = 2000 ln ⎢ ⎥ − 9.8t
⎣140000 − 2100t ⎦
n ∆x Et ∈t % ∈a %
1 11868 -807 7.296 ---
2 11266 -205 1.853 5.343
3 11153 -91.4 0.8265 1.019
4 11113 -51.5 0.4655 0.3594
5 11094 -33.0 0.2981 0.1669
6 11084 -22.9 0.2070 0.09082
7 11078 -16.8 0.1521 0.05482
8 11074 -12.9 0.1165 0.03560
a)
I 2 = 11266m I 4 = 11113m
I 2n − I n
TV ≅ I 2n + for n=2
3
I4 − I2 11113− 11266
TV ≅ I 4 + = 11113+
3 3
= 11062m
⎛
30
⎡ 140000 ⎤ ⎞
x = ∫ ⎜ 2000 ln ⎢ ⎥ − 9 . 8t ⎟dt = 11061 m
8⎝ ⎣140000 − 2100t ⎦ ⎠
Et = 11061− 11062 = −1 m
n ∆x (m) ∈t % ∆x (m) ∈t %
Trapezoidal Richardson
Trapezoidal rule Richardson
rule extrapolation
extrapolation
1 11868 7.296 -- --
2 11266 1.854 11065 0.03616
4 11113 0.4655 11062 0.009041
8 11074 0.1165 11061 0.0000
I 2n − I n
TV ≅ I 2 n +
3
The true value TV is replaced by the result of the
Richardson extrapolation
(I 2n )R
Note also that the sign ≅ is replaced by the sign =
I 2n − I n I 2n − I n
(I 2n )R = I 2n + = I 2n + 2−1
3 4 −1
I k −1, j +1 − I k −1, j
I k , j = I k −1, j +1 + k −1
,k ≥ 2
4 −1
k=1 represents the values obtained from the regular trapezoidal rule
k=2 represents the values obtained using the true error estimate as O(h2)
Example 4:
⎡ 140000 ⎤
v(t ) = 2000 ln ⎢ ⎥ − 9.8t
⎣140000 − 2100t ⎦
n ∆x Et ∈t % ∈a %
1 11868 -807 7.296 ---
2 11266 -205 1.853 5.343
3 11153 -91.4 0.8265 1.019
4 11113 -51.5 0.4655 0.3594
5 11094 -33.0 0.2981 0.1669
6 11084 -22.9 0.2070 0.09082
7 11078 -16.8 0.1521 0.05482
8 11074 -12.9 0.1165 0.03560
From this table, the initial values from the trapezoidal rule are:
I1,2 − I1,1
I 2 ,1 = I1,2 +
3
11266 − 11868
= 11266 +
3
Similarly,
I 1,3 − I 1, 2 I 1, 4 − I 1,3
I 2, 2 = I 1,3 + I 2,3 = I 1, 4 +
3 3
= 11062 = 11061
I 2 ,2 − I 2 ,1
I 3 ,1 = I 2 ,2 +
15
11062 − 11065
= 11062 +
15
= 11062
I 2,3 − I 2, 2
Similarly, I 3, 2 = I 2,3 +
15
11061 − 11062
= 11061 +
15
= 11061
Numerical Methods lecture 5 35
Romberg's method
I 3 ,2 − I 3,1
I 4 ,1 = I 3 ,2 +
63
11061 − 11062
= 11061 +
63
= 11061m
b b
I = ∫ f ( x )dx ≈ ∫ f 2 ( x )dx
a a
where:
f 2 ( x ) = a0 + a1 x + a2 x 2
( b , f ( b ))
f ( a ) = f 2 ( a ) = a 0 + a1 a + a 2 a 2
a b X
2
⎛a + b⎞ ⎛a + b⎞ ⎛a + b⎞ ⎛a + b⎞
f⎜ ⎟ = f2 ⎜ ⎟ = a0 + a1 ⎜ ⎟ + a2 ⎜ ⎟
⎝ 2 ⎠ ⎝ 2 ⎠ ⎝ 2 ⎠ ⎝ 2 ⎠
f ( b ) = f 2 ( b ) = a 0 + a1b + a 2 b 2
2 ⎛a + b⎞ 2
a f ( b ) + abf ( b ) − 4abf ⎜ ⎟ + abf ( a ) + b f(a)
a0 = ⎝ 2 ⎠
a 2 − 2ab + b 2
⎛a + b⎞ ⎛a + b⎞
af ( a ) − 4af ⎜ ⎟ + 3af ( b ) + 3bf ( a ) − 4bf ⎜ ⎟ + bf ( b )
a1 = − ⎝ 2 ⎠ ⎝ 2 ⎠
a 2 − 2ab + b 2
⎛ ⎛a + b⎞ ⎞
2⎜ f ( a ) − 2 f ⎜ ⎟ + f ( b ) ⎟
⎝ ⎝ 2 ⎠ ⎠
a2 =
a 2 − 2ab + b 2
Since: b
I ≈ ∫ f 2 ( x )dx
a
= ∫ (a0 + a1 x + a2 x 2 )dx
b
3 b
⎡ x x ⎤
2
= ⎢a0 x + a1 + a2 ⎥
⎣ 2 3 ⎦a
b2 − a2 b3 − a 3
= a0 ( b − a ) + a1 + a2
2 3
b
b−a⎡ ⎛a + b⎞ ⎤
∫ f 2 ( x )dx = ⎢ f(a)+ 4 f ⎜ ⎟ + f ( b )⎥
a 6 ⎣ ⎝ 2 ⎠ ⎦
b−a
h=
2
It follows that:
h⎡ ⎛ a+b⎞ ⎤
b
∫
a
f 2 ( x)dx = ⎢ f (a ) + 4 f ⎜
3⎣ ⎝ 2 ⎠
⎟ + f (b)⎥
⎦
it is called Simpson’s 1/3 rule
b
⎡ f ( x0 ) + 4 f ( x1 ) + f ( x2 )⎤ x0 x2 xn-2 xn
∫ f ( x )dx = ( x2 − x0 )⎢ ⎥ + ...
a ⎣ 6 ⎦ xi − xi − 2 = 2 h
⎡ f ( x2 ) + 4 f ( x3 ) + f ( x4 )⎤ i = 2, 4, ..., n
+ ( x4 − x2 )⎢ ⎥ + ...
⎣ 6 ⎦
⎡ f ( xn − 4 ) + 4 f ( xn − 3 ) + f ( xn − 2 ) ⎤
... + ( xn − 2 − xn − 4 )⎢ ⎥ + ...
⎣ 6 ⎦
⎡ f ( xn − 2 ) + 4 f ( xn −1 ) + f ( xn )⎤
+ ( xn − xn − 2 )⎢ ⎥⎦
⎣ 6
Numerical Methods lecture 5 43
Simpson's rule
b
⎡ f ( x0 ) + 4 f ( x1 ) + f ( x2 )⎤
∫ f ( x )dx = 2h ⎢ ⎥ + ...
a ⎣ 6 ⎦
⎡ f ( x2 ) + 4 f ( x3 ) + f ( x4 )⎤
+ 2h ⎢ ⎥ + ...
⎣ 6 ⎦
⎡ f ( xn − 4 ) + 4 f ( xn − 3 ) + f ( x n − 2 ) ⎤
+ 2h ⎢ ⎥ + ...
⎣ 6 ⎦
⎡ f ( xn − 2 ) + 4 f ( xn −1 ) + f ( xn )⎤
+ 2h ⎢ ⎥⎦
⎣ 6
b h
∫ f ( x )dx = 3 [ f ( x0 ) + 4{ f ( x1 ) + f ( x3 ) + ... + f ( xn −1 )} + ...]
a
( x2 − x0 ) ( 4 )
5 h5 ( 4 ) x0 < ζ1 < x2
E1 = − f ( ζ1 ) = − f ( ζ1 ),
2880 90
( x4 − x2 )5 ( 4 ) h5 ( 4 )
E2 = − f ( ζ2 ) = − f ( ζ 2 ), x2 < ζ 2 < x4
2880 90
( x2i − x2( i −1 ) )5 h 5
Ei = − f ( 4 ) ( ζ i ) = − f ( 4 ) ( ζ i ), x2( i −1 ) < ζ i < x2i
2880 90
True error
n n n
5 5
=
2
−
h
∑
2
( 4)
( ζ ) (b − a ) 2
Et = ∑ Ei f i =− ∑ f ( 4)
(ζ i )
i =1 90 i =1 5
90n i =1
n
2 ( 4)
∑f (ζ i )
(b − a ) 5
i =1
=−
90n 4 n
n
2
∑f
( 4)
(ζ i ) (b − a) 5 ( 4)
( 4) Et = − f
f = i =1 90n 4
n
the average value of the derivative
b
I = ∫ f ( x )dx ≈ c1 f ( x1 ) + c2 f ( x2 )
a
constant coefficients
Points x1 and x2, which define the value of the integrand are not fixed
(as before), but there are a priori distributed randomly within <a,b>.
There are four unknowns x1, x2, c1, c2. These are found by
assuming that the formula gives exact results for integrating a
general third order polynomial:
f ( x ) = a0 + a1 x + a2 x 2 + a3 x 3 .
( )dx
b b
2 3
∫ f ( x )dx = a +
∫ 0 1 a x + a 2 x + a 3 x
a a b
⎡ x 2
x x ⎤ 3 4
= ⎢a0 x + a1 + a 2 + a3 ⎥
⎣ 2 3 4 ⎦a
⎛ b2 − a2 ⎞ ⎛ b3 − a3 ⎞ ⎛ b4 − a4 ⎞
= a0 (b − a ) + a1 ⎜⎜ ⎟⎟ + a 2 ⎜⎜ ⎟⎟ + a3 ⎜⎜ ⎟⎟
⎝ 2 ⎠ ⎝ 3 ⎠ ⎝ 4 ⎠
( ) (
= a0 (c1 + c2 ) + a1 (c1 x1 + c2 x2 ) + a 2 c1 x1 + c2 x2 + a3 c1 x1 + c2 x2
2 2 3 3
)
The formula would then give:
( )dx
b b
2 3
∫ f ( x )dx = ∫ 0 1
a + a x + a 2 x + a 3 x
a a
⎛ b2 − a2 ⎞ ⎛ b3 − a3 ⎞ ⎛ b4 − a4 ⎞
= a0 (b − a ) + a1 ⎜⎜ ⎟⎟ + a 2 ⎜⎜ ⎟⎟ + a3 ⎜⎜ ⎟⎟
⎝ 2 ⎠ ⎝ 3 ⎠ ⎝ 4 ⎠
( ) (
a0 (c1 + c2 ) + a1 (c1 x1 + c2 x2 ) + a2 c1 x12 + c2 x2 2 + a3 c1 x13 + c2 x2 3 )
⎛ b2 − a2 ⎞ ⎛ b3 − a3 ⎞ ⎛ b4 − a4 ⎞
= a0 (b − a ) + a1 ⎜⎜ ⎟⎟ + a 2 ⎜⎜ ⎟⎟ + a3 ⎜⎜ ⎟⎟
⎝ 2 ⎠ ⎝ 3 ⎠ ⎝ 4 ⎠
b − a = c1 + c2 b2 − a2
= c1 x1 + c 2 x 2
2
b3 − a3 2 2 b4 − a4
= c1 x1 + c2 x2 3
= c1 x1 + c 2 x 2
3
3 4
Hence:
∫ f ( x )dx ≈ c1 f ( x1 ) + c2 f ( x2 )
a
b
∫ f ( x )dx ≈ c1 f ( x1 ) + c 2 f ( x 2 ) + . . . . . . . + c n f ( x n )
a
2 c1 = 1.000000000 x1 = -0.577350269
c2 = 1.000000000 x2 = 0.577350269
3 c1 = 0.555555556 x1 = -0.774596669
c2 = 0.888888889 x2 = 0.000000000
c3 = 0.555555556 x3 = 0.774596669
4 c1 = 0.347854845 x1 = -0.861136312
c2 = 0.652145155 x2 = -0.339981044
c3 = 0.652145155 x3 = 0.339981044
c4 = 0.347854845 x4 = 0.861136312
5 c1 = 0.236926885 x1 = -0.906179846
c2 = 0.478628670 x2 = -0.538469310
c3 = 0.568888889 x3 = 0.000000000
c4 = 0.478628670 x4 = 0.538469310
c5 = 0.236926885 x5 = 0.906179846
6 c1 = 0.171324492 x1 = -0.932469514
c2 = 0.360761573 x2 = -0.661209386
c3 = 0.467913935 x3 = -0.2386191860
c4 = 0.467913935 x4 = 0.2386191860
c5 = 0.360761573 x5 = 0.661209386
c6 = 0.171324492 x6 = 0.932469514
[a , b]
a
The answer lies in that any integral with limits of
Let, x = mt + c
It follows that:
if x = a, t = −1
b−a
m=
ir x = b, t= 1 2
b+a
c=
2
Numerical Methods lecture 5 57
Gauss-Quadrature Method
b−a b+a
Hence: x= t+
2 2
b−a
dx = dt
2
1
⎛b−a b+a⎞b−a
b
∫
a
f ( x )dx = ∫ f ⎜
−1 ⎝
2
t+ ⎟
2 ⎠ 2
dt
⎡ 140000 ⎤
v(t ) = 2000 ln ⎢ ⎥ − 9.8t
⎣140000 − 2100t ⎦
30
30 − 8 1 ⎛ 30 − 8 30 + 8 ⎞
∫ f ( t )dt = ∫ f⎜ x+ ⎟dx
8 2 −1 ⎝ 2 2 ⎠
1
= 11 ∫ f (11x + 19 )dx
−1
The weighting factors and function c1 = 1 .000000000
argument values are (n=2):
x1 = − 0 .577350269
c 2 = 1 .000000000
x 2 = 0 .577350269
1
11 ∫ f (11x + 19 )dx ≈ 11c1 f (11x1 + 19 ) + 11c 2 f (11x 2 + 19 )
−1
= 11 f ( 12.64915 ) + 11 f ( 25.35085 )
= 11058.44 m
Since:
⎡ 140000 ⎤
f ( 12.64915 ) = 2000 ln ⎢ ⎥ − 9.8( 12.64915 )
⎣140000 − 2100( 12.64915 )⎦
= 296.8317
⎡ 140000 ⎤
f ( 25.35085 ) = 2000 ln ⎢ ⎥ − 9.8( 25.35085 )
⎣140000 − 2100( 25.35085 )⎦
= 708.4811
Et = 11061.34 − 11058.44
= 2.9000 m
11061.34 − 11058.44
∈t = × 100%
11061.34
= 0.0262%