You are on page 1of 63

Numerical Methods

Lecture 5.

Numerical integration

dr hab. inż. Katarzyna Zakrzewska, prof. AGH

Numerical Methods lecture 5 1


Outline

• Trapezoidal rule
• Multi-segment trapezoidal rule
• Richardson extrapolation
• Romberg's method
• Simpson's rule
• Gaussian method

Numerical Methods lecture 5 2


Numerical integration - idea

b
I = ∫ f ( x )dx Y
f(x)
a

The integral can


be approximated
b
by: ∫ f ( x)dx
a

n
S = ∑ f (ci )Δxi a b X
i =1

xi ≤ ci ≤ xi +1

Numerical Methods lecture 5 3


Newton–Cotes methods

Newton – Cotes integration belongs to a class of


methods with fixed nodes: function f(x) is interpolated
by a polynomial (e.g. Lagrange polynomial)
f ( x ) ≈ fn( x )
where: n −1
f n ( x ) = a0 + a1 x + ... + an −1 x + an x n

Then, the integral of f(x) can be approximated as an


integral of the interpolated function fn(x)
b b
I = ∫ f ( x) dx ≈ ∫ f n ( x) dx
a a

Numerical Methods lecture 5 4


Trapezoidal rule

The trapezoidal rule f1 ( x) = a0 + a1 x


assumes: n = 1, thus:
b b b
I = ∫ f ( x) dx ≈ ∫ f1 ( x) dx = ∫ (a0 + a1 x)dx
a a a
b2 − a 2
= a0 (b − a ) + a1
2
But what is a0 and a1 ?
Now if one chooses, (a,f(a)) i (b,f(b)) as the two points to
approximate f(x) by a straight line from a to b. It follows that:
f (a)b − f (b)a
f (a ) = f1 (a ) = a0 + a1a a0 =
b−a
f (b) = f1 (b) = a0 + a1b f (b) − f (a)
a1 =
b−a
Numerical Methods lecture 5 5
Trapezoidal rule

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

Numerical Methods lecture 5 6


Trapezoidal rule

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) Use the single segment trapezoidal rule to find the distance


covered by the rocket from t1=8 s to t2=30 s
b) Find the true relative error.

Numerical Methods lecture 5 7


Trapezoidal rule

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) ⎦

⎡177.27 + 901.67 ⎤ = 11868 m


I = (30 − 8) ⎢ ⎥⎦
⎣ 2

Numerical Methods lecture 5 8


Trapezoidal rule

b) The true value

30⎛ ⎞
⎡ 140000 ⎤
Δx = ∫ ⎜⎜ 2000 ln ⎢ ⎥ − 9.8t ⎟⎟dt = 11061 m
8⎝ ⎣140000 − 2100t ⎦ ⎠

The relative error:

11061 − 11868
∈t = × 100 = 7 .2959 %
11061

Numerical Methods lecture 5 9


Multi-segment trapezoidal rule

The true error using a


Y
single segment trapezoidal f(x)
rule was large. We can
divide the interval from a to
b into smaller n segments
of equal length – h and
apply the trapezoidal rule
over each segment:

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 + 3h a+4h


I = ∫ f ( x)dx = ∫ f ( x)dx + ∫ f ( x)dx + ∫ f ( x)dx + ∫ f ( x)dx
a a a+h a+2h a + 3h

Numerical Methods lecture 5 10


Multi-segment trapezoidal rule

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 ⎭ ⎦

Numerical Methods lecture 5 11


Multi-segment trapezoidal rule

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 ⎦

a) Use the complex segment trapezoidal rule to find the distance


covered from t1=8 s to t2=30 s for n = 2
b) Find the true relative error.

Numerical Methods lecture 5 12


Multi-segment trapezoidal rule

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

Numerical Methods lecture 5 13


Multi-segment trapezoidal rule

b) true value:

30
⎛ ⎡ 140000 ⎤ ⎞
x = ∫ ⎜ 2000ln⎢ ⎥ − 9.8t ⎟dt = 11061 m
8⎝ ⎣140000 − 2100t ⎦ ⎠

The relative error:

11061 − 11266
∈t = × 100 = 1.8534%
11061

Numerical Methods lecture 5 14


Multi-segment trapezoidal rule

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

Numerical Methods lecture 5 15


Estimation of error

The relative error for a simple trapezoidal rule is

( 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

Numerical Methods lecture 5 16


Estimation of error

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

Numerical Methods lecture 5 17


Estimation of error

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

Table below presents the results for the integral


30
⎛ ⎡ 140000 ⎤ ⎞
∫ ⎜⎝ 2000 ln ⎢⎣140000 − 2100t ⎥⎦ − 9. 8t ⎟dt

8
as a function of the number of segments n. When n twice increases, the
absolute error Et decreases four times!

n Value Et ∈t % ∈a %
2 11266 -205 1.854 5.343

4 11113 -51.5 0.4655 0.3594

8 11074 -12.9 0.1165 0.03560

16 11065 -3.22 0.02913 0.00401

Numerical Methods lecture 5 19


Richardson’s extrapolation and Romberg’s method
of integration

Richardson’s extrapolation and Romberg’s method


of integration constitute an extension of the
trapezoidal method and give better approximation
of the integral by reducing the true error.

Numerical Methods lecture 5 20


Richardson extrapolation

The true error obtained when using the multi-segment


trapezoidal rule with n segments to approximate an integral is
given by: C
Et ≅
n2
where: C is an approximate constant of proportionality

Since:

Et = TV − I n

approximate value using


true value
n-segments

Numerical Methods lecture 5 21


Richardson extrapolation
It can be shown that: C
≅ TV − I 2 n
(2 n ) 2

If the number of segments is doubled from n to 2n:

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

Numerical Methods lecture 5 22


Richardson extrapolation

Example 3:

The velocity v(t) of a rocket from t1=8 s to t2=30 is given by:

⎡ 140000 ⎤
v(t ) = 2000 ln ⎢ ⎥ − 9.8t
⎣140000 − 2100t ⎦

a) Use Richardson extrapolation rule to find the distance covered


for n = 2
b) Find the relative true error

Numerical Methods lecture 5 23


Table of results for n = 8 segments (trapezoidal rule)

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

Numerical Methods lecture 5 24


Richardson extrapolation

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

Numerical Methods lecture 5 25


Richardson extrapolation

b) The true value:


30
⎡ 140000 ⎤ ⎞
x = ∫ ⎜ 2000 ln ⎢ ⎥ − 9 . 8t ⎟dt = 11061 m
8⎝ ⎣140000 − 2100t ⎦ ⎠

The absolute true error:

Et = 11061− 11062 = −1 m

Numerical Methods lecture 5 26


Richardson extrapolation

c) The relative error:


11061 − 11062
∈t = × 100 = 0.00904%
11061
Comparison of different methods:
.

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

Numerical Methods lecture 5 27


Romberg's method

Romberg’s method uses the same pattern as Richardson


extrapolation. However, Romberg used a recursive algorithm for
the extrapolation as follows:

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

Numerical Methods lecture 5 28


Romberg's method

Esimated true value is given by: TV ≅ ( I 2 n ) R + Ch 4


where: Ch4 is the value of the error of approximation
Another value of integral obtained while doubling the number of
segments from 2n to 4n:
I 4n − I 2n
(I 4n )R = I 4n +
3
Estimated true value is given by:
(I 4n )R − (I 2n )R
TV ≅ (I 4 n )R +
15
(I 4 n )R − (I 2 n )R
= ( I 4n ) R +
43−1 − 1
Numerical Methods lecture 5 29
Romberg's method

A general expression for Romberg integration can be written as:

I k −1, j +1 − I k −1, j
I k , j = I k −1, j +1 + k −1
,k ≥ 2
4 −1

The index k represents the order of extrapolation

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)

The value of an integral with for j+ 1 is more accurate than


the value of the integral for j index

Numerical Methods lecture 5 30


Romberg's method

Example 4:

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) Use Romberg’s method to find the distance covered. Use


n = 1, 2, 4, and 8
b) Find the absolute true error and the relative approximate error

Numerical Methods lecture 5 31


Table of results for n = 8 segments (trapezoidal rule)

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

Numerical Methods lecture 5 32


Romberg's method

From this table, the initial values from the trapezoidal rule are:

I 1,1 = 11868 I 1,2 = 11266

I 1,3 = 11113 I 1,4 = 11074

To get the first order extrapolation values:

I1,2 − I1,1
I 2 ,1 = I1,2 +
3
11266 − 11868
= 11266 +
3

Numerical Methods lecture 5 33


Romberg's method

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

11113 − 11266 11074 − 11113


= 11113 + = 11074 +
3 3

= 11062 = 11061

Numerical Methods lecture 5 34


Romberg's method

For the second order extrapolation:

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

For the third order extrapolation

I 3 ,2 − I 3,1
I 4 ,1 = I 3 ,2 +
63
11061 − 11062
= 11061 +
63

= 11061m

Numerical Methods lecture 5 36


Romberg's method

Appr. 1 Appr. 2 Appr. 3


1-segment 11868
11065
2-segment 11262 11062
11062 11061
4-segment 11113 11061
11061
8-segment 11074

Improved estimates of the value of an integral using Romberg


integration

Numerical Methods lecture 5 37


Simpson's rule

The trapezoidal rule was based on approximating the integrand


by a first order polynomial, and then integrating the polynomial
over an interval from a to b. Simpson’s rule assumes that the
integrand can be approximated by a second order polynomial.

b b
I = ∫ f ( x )dx ≈ ∫ f 2 ( x )dx
a a

where:

f 2 ( x ) = a0 + a1 x + a2 x 2

Numerical Methods lecture 5 38


Simpson's rule

A parabola passing through Y


three points : f(x)
( a , f ( a )),
⎛ a + b ⎛ a + b ⎞⎞
⎜ ,f⎜ ⎟ ⎟, fI(x)
⎝ 2 ⎝ 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

Numerical Methods lecture 5 39


Simpson's rule

Coefficients a0,a1,a2 are:

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

Numerical Methods lecture 5 40


Simpson's rule

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

Numerical Methods lecture 5 41


Simpson's rule

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

Numerical Methods lecture 5 42


Multi-segment Simpson's rule
b x2 x4
f(x)
∫ f ( x )dx = ∫ f ( x )dx + ∫ f ( x )dx + .....
a x0 x2
xn − 2 xn
.... + ∫ f ( x )dx + ∫ f ( x )dx . . .
xn − 4 xn − 2
x

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

Numerical Methods lecture 5 44


Simpson's rule

b h
∫ f ( x )dx = 3 [ f ( x0 ) + 4{ f ( x1 ) + f ( x3 ) + ... + f ( xn −1 )} + ...]
a

... + 2{ f ( x2 ) + f ( x4 ) + ... + f ( xn − 2 )} + f ( xn )}]


⎡ −1 − 2

h⎢ n n
= f ( x 0 ) + 4 ∑ f ( xi ) + 2 ∑ f ( xi ) + f ( x n ) ⎥
3⎢ i =1 i =2 ⎥
⎣ i = odd i = even ⎦
⎡ ⎤
b−a⎢ n −1 n − 2
= f ( x 0 ) + 4 ∑ f ( xi ) + 2 ∑ f ( xi ) + f ( x n ) ⎥
3n ⎢ i =1 i =2 ⎥
⎣ i = odd i = even ⎦

Numerical Methods lecture 5 45


Estimation of errors in Simpson's rule

Approximate values of the integral,


using Simpson's rule with multiple segments

n Approximate values Et |Єt |

2 11065.72 4.38 0.0396%


4 11061.64 0.30 0.0027%
6 11061.40 0.06 0.0005%
8 11061.35 0.01 0.0001%
10 11061.34 0.00 0.0000%

Numerical Methods lecture 5 46


Simpson's rule errors
(b − a) 5 ( 4)
Error for one segment Et = − f (ζ ), a < ζ < b
2880

Error for the multi-segment

( 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

Numerical Methods lecture 5 47


Simpson's rule errors

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

Numerical Methods lecture 5 48


Gauss-Quadrature Method

Gaussian integral is given by:

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>.

Numerical Methods lecture 5 49


Gauss-Quadrature Method

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 ⎠

Numerical Methods lecture 5 50


Gauss-Quadrature Method
b
I = ∫ f ( x )dx ≈ c1 f ( x1 ) + c2 f ( x2 )
a
Hence:

∫ f ( x )dx = c1 (a0 + a1 x1 + a 2 x1 + a3 x1 ) + c2 (a0 + a1 x2 + a 2 x2 + a3 x2 )


b
2 3 2 3

( ) (
= 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 ⎠

Numerical Methods lecture 5 51


Gauss-Quadrature Method

( ) (
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

Numerical Methods lecture 5 52


Gauss-Quadrature Method

This gives us four equations as follows:


b − a = c1 + c2
b2 − a2
= c1 x1 + c 2 x 2
2
b − a3
3
2 2
= c1 x1 + c2 x2
3
b4 − a4 3 3
= c1 x1 + c 2 x 2
4
we can find that the above four simultaneous nonlinear equations
have only one acceptable solution
⎛ b − a ⎞⎛ 1 ⎞ b + a ⎛ b − a ⎞⎛ 1 ⎞ b + a
x1 = ⎜ ⎟⎜ − ⎟+ x2 = ⎜ ⎟⎜ ⎟ +
⎝ 2 ⎠⎝ 3⎠ 2 ⎝ 2 ⎠⎝ 3 ⎠ 2
b−a b−a
c1 = c2 =
2 2
Numerical Methods lecture 5 53
Gauss-Quadrature Method

Hence:

∫ f ( x )dx ≈ c1 f ( x1 ) + c2 f ( x2 )
a

b−a ⎛b−a ⎛ 1 ⎞ b+a⎞ b−a ⎛b−a ⎛ 1 ⎞ b+a⎞


= f ⎜⎜ ⎜− ⎟+ ⎟⎟ + f ⎜⎜ ⎜ ⎟+ ⎟⎟
2 ⎝ 2 ⎝ 3⎠ 2 ⎠ 2 ⎝ 2 ⎝ 3⎠ 2 ⎠

General n-point rules would approximate the integral:

b
∫ f ( x )dx ≈ c1 f ( x1 ) + c 2 f ( x 2 ) + . . . . . . . + c n f ( x n )
a

Numerical Methods lecture 5 54


Gauss-Quadrature Method

The coefficients and arguments for n-point Gauss method are


given within the range of <-1,1> :
1 n
∫ g ( x )dx ≅ ∑ ci g ( xi )
−1 i =1

n Coefficients Function arguments

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

Numerical Methods lecture 5 55


Gauss-Quadrature Method

n Coefficients Function arguments

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

Numerical Methods lecture 5 56


Gauss-Quadrature Method
1
So if the table is given for: ∫ g ( x )dx integrals, how does one solve
−1
b
∫ f ( x )dx ?

[a , b]
a
The answer lies in that any integral with limits of

can be converted into an integral with limits: [− 1, 1]

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

Substituting our values of x and dx into the integral gives us:

1
⎛b−a b+a⎞b−a
b


a
f ( x )dx = ∫ f ⎜
−1 ⎝
2
t+ ⎟
2 ⎠ 2
dt

Numerical Methods lecture 5 58


Gauss-Quadrature Method
Example 5:
Use two-point Gauss quadrature rule to approximate the distance
covered by a rocket from t = 8 s to t = 30 s if the velocity is given
by:

⎡ 140000 ⎤
v(t ) = 2000 ln ⎢ ⎥ − 9.8t
⎣140000 − 2100t ⎦

a) Use the Gauss-Quadrature Mmethod to find the distance


covered from t1=8 s to t2=30 s
b) Find the true error.

Numerical Methods lecture 5 59


Gauss-Quadrature Method

First, change the limits of integration from from [8,30] to [-1,1]

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

Numerical Methods lecture 5 60


Gauss-Quadrature Method

The formula is:

1
11 ∫ f (11x + 19 )dx ≈ 11c1 f (11x1 + 19 ) + 11c 2 f (11x 2 + 19 )
−1

= 11 f (11( −0.5773503 ) + 19) + 11 f (11( 0.5773503 ) + 19)

= 11 f ( 12.64915 ) + 11 f ( 25.35085 )

= 11( 296.8317 ) + 11( 708.4811 )

= 11058.44 m

Numerical Methods lecture 5 61


Gauss-Quadrature Method

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

Numerical Methods lecture 5 62


Gauss-Quadrature Method

b) The absolute true error:

Et = 11061.34 − 11058.44

= 2.9000 m

c) The relative error: ∈t

11061.34 − 11058.44
∈t = × 100%
11061.34
= 0.0262%

Numerical Methods lecture 5 63

You might also like