You are on page 1of 32

5/15/2016

Numerical Integration

Trapezoidal and Simpson Rule


Romberg Formula

prepared by Razana Alwee

Numerical Integration

Many definite integrals of interest can’t be evaluated


analytically.
Probably the best-known example is the integral that
gives the area under the standard bell-shaped curve,
given by x
1 1 z 2 2
F ( x)    e dz
2 2 0

This integral appears very frequently in probability and


statistics and is extensively tabulated.
prepared by Razana Alwee

prepared by Razana Alwee 1


5/15/2016

Numerical Integration

The integral is tabulated because it is a fact that there is


no way to express the antiderivative of exp(-z2) in terms
of elementary functions.
Because of cases like this we need methods to perform
approximate integration; for other cases it may be more
convenient to use a numerical method than a symbolic
one.
Often we’re given values of f(x) at various points but not
a formula for f and so have no choice but to use a
numerical method (for example, data from an
experiment)

prepared by Razana Alwee

Numerical Integration

The Newton-Cotes formula


Trapezoidal Rule
Simpson’s Rule
Romberg Integration
Gaussian Quadrature

prepared by Razana Alwee

prepared by Razana Alwee 2


5/15/2016

Trapezoidal Rule

The trapezoidal rule is equivalent to approximating the


area of the trapezoid under the straight line connecting
f(a) and f(b).

f(b)
f(a)

a b
prepared by Razana Alwee

Trapezoidal Rule

One way to improve the accuracy of the trapezoid rule is


to divide the integration interval from a to b into a
number of segments (N).
The areas of individual segment can then be added to
yield the integral for the entire interval.
There are N+1 equally spaced nodes
x0, x1, …., xN

prepared by Razana Alwee

prepared by Razana Alwee 3


5/15/2016

Trapezoidal Rule

Let, x0=a and xN=b

Assume
xk  x0  kh, k  0,1,2,..., N

are equally spaced nodes


ba
h
N

prepared by Razana Alwee

Trapezoidal Rule

Therefore

b x1 x2 xN
 f ( x) dx   f ( x) dx   f ( x) dx  ...   f ( x) dx
a x0 x1 x N 1

x k 1 x k 1
with
 xk
f ( x ) dx  
xk
p n ( x ) dx

prepared by Razana Alwee

prepared by Razana Alwee 4


5/15/2016

Trapezoidal Rule

Let

pn ( x)  f k  rf k

with
x  xk  rh (dx  hdr)

prepared by Razana Alwee

Trapezoidal Rule

x k 1 xk 1
 f ( x) dx   p n ( x) dx
xk xk

xk  h

xk
 f k  r f k  dx

1
 h
0
 f k  rf k  dr

prepared by Razana Alwee

10

prepared by Razana Alwee 5


5/15/2016

Trapezoidal Rule

1
 r2   1 
 h rf k  f k   h f k  f k 
 2 0  2 

 1 
 h  f k   f k 1  f k 
 2 

h
  f k  f k 1 
2

prepared by Razana Alwee

11

Trapezoidal Rule

h
 f 0  f 1   h  f 1  f 2   ...  h  f N 1  f N 
b
 f ( x) dx 
a 2 2 2
h
  f 0  2 f1  2 f 2  ...  2 f N 1  f N 
2

N 1
b h 
 f ( x) dx   f 0  f N  2 f i 
a 2 i 1 

prepared by Razana Alwee

12

prepared by Razana Alwee 6


5/15/2016

Example

Approximate the following integral using the Trapezoidal


rule with h=0.5 and h=0.25.

4 x
 dx
1
x4

prepared by Razana Alwee

13

Example

For h=0.5, a=1 and b=4

b  a 4 1
N  6
h 0.5

prepared by Razana Alwee

14

prepared by Razana Alwee 7


5/15/2016

Example

xi
i xi f ( xi ) 
xi  4
0 1 .0 0.4472
1 1 .5 0.6396
2 2. 0 0.8165
3 2 .5 0.9806
4 3. 0 1.1339
5 3 .5 1.2780
6 4. 0 1.4142
Total 1.8614
prepared by Razana Alwee
4.8486
15

Example

4 x 4
 1
x4
dx   f ( x) dx
1

h
 f  f 6  2 f 1  f 2  f 3  f 4  f 5 
2 0

0 .5
 1.8614  24.8486
2
 2.8896

prepared by Razana Alwee

16

prepared by Razana Alwee 8


5/15/2016

Example

For h=0.25, a=1 and b=4

b  a 4 1
N   12
h 0.25

prepared by Razana Alwee

17

xi
i xi f ( xi ) 
Example
xi  4
0 1 . 00 0 . 4472
1 1 . 25 0 . 5455
2 1 . 50 0 . 6396
3 1 . 75 0 . 7298
4 2 . 00 0 . 8165
5 2 . 25 0 . 9000
6 2 . 50 0 . 9806
7 2 . 75 1 . 0585
8 3 . 00 1 . 1339
9 3 . 25 1 . 2070
10 3 . 50 1 . 2780
11 3 . 75 1 . 3470
12 4prepared
. 00 by Razana Alwee 1 . 4142
Total 1 . 8614 10 . 6364 18

prepared by Razana Alwee 9


5/15/2016

Example

4 x 4
 1
x4
dx   f ( x) dx
1
11
h 
  f 0  f 12  2 f i 
2 i 1 
0.25
 1.8614  210.6364
2
 2.8918

(Note: The exact value of the integral is 2.8925)


prepared by Razana Alwee

19

Example

For h=0.5, N=6, the error is 0.0029


For h=0.25, N=12, the error is 0.0007

The error decreases as the number of segments (N)


increases.
When h is reduced by a factor of ½ the successive errors
are diminished by approximately ¼.

prepared by Razana Alwee

20

prepared by Razana Alwee 10


5/15/2016

Exercise

Approximate the following integrals using the


Trapezoidal rule with N=10.

2 2
(a)  e x dx (b)  x 3  1 dx
0 1

prepared by Razana Alwee

21

Simpson’s Rule

The trapezoidal rule usually requires a large number of


function evaluations to achieve an accurate answer.
Another way to obtain a more accurate estimate of an
integral is to use higher-order polynomials to connect the
points.

prepared by Razana Alwee

22

prepared by Razana Alwee 11


5/15/2016

Simpson’s Rule

Let

1
p2 ( x )  f k  rf k  r (r  1) 2 f k
2

prepared by Razana Alwee

23

Simpson’s Rule

xk  2 xk  2 h  1 2 
 f ( x) dx    f k  rf k  r ( r  1)  f k  dx
xk xk
 2 
2  1 2 
 h  f k  rf k  r ( r  1)  f k  dr
0
 2 
2
 r2 1  r3 r2  
 h rf k  f k     2 f k 
 2 2 3 2  0

prepared by Razana Alwee

24

prepared by Razana Alwee 12


5/15/2016

Simpson’s Rule

 1 
 h 2 f k  2 f k  2 f k 
 3 
 1 
 h 2 f k  2 f k 1  f k    f k 2  2 f k 1  f k 
 3 

h
  f  4 f k 1  f k  2 
3 k

prepared by Razana Alwee

25

Simpson’s Rule

Subdivide the interval [a,b] into N subintervals (N is


even).
b x2 x4
 f ( x) dx   f ( x) dx   f ( x ) dx
a x0 x2
xN
 ...   f ( x) dx
xN 2

h
  f  4 f 1  2 f 2  4 f 3  2 f 4 ...4 f N 1  f N 
3 0

prepared by Razana Alwee

26

prepared by Razana Alwee 13


5/15/2016

Simpson’s Rule

This equation is known as Simpson’s 1/3 rule.

N /2 N / 2 1
b h 
 f ( x) dx   f 0  f N   4  f 2 i 1  2  f 2i 
a 3 i 1 i 1 

Where N is even.

prepared by Razana Alwee

27

Simpson’s 3/8 Rule

Let,

1 1
p3 ( x)  f k  rf k  r ( r  1) 2 f k  r (r  1)( r  2) 3 f k
2 6

xk  3 xk  3
 xk
f ( x ) dx  
xk
p3 ( x ) dx

prepared by Razana Alwee

28

prepared by Razana Alwee 14


5/15/2016

Simpson’s 3/8 Rule

N /3 N / 3 1
b 3h  
 f ( x) dx   f 0  f N   3  f 3i  2  f 3i 1   2  f 3i 
a 8  i 1 i 1 

where N= 3, 6, 9, 12, ..…

This equation is called Simpson’s 3/8 rule because h is


multiplied by 3/8.

prepared by Razana Alwee

29

Example

Approximate the following integrals using the Simpson’s


1/3 rule with h=0.5 and h=0.25.

4 x
 dx
1
x4

prepared by Razana Alwee

30

prepared by Razana Alwee 15


5/15/2016

Example

For h=0.5, a=1 and b=4

b  a 4 1 (N is even)
N  6
h 0 .5

prepared by Razana Alwee

31

Example
xi
i xi f i  f ( xi ) 
xi  4
0 1.0 0.4472
1 1.5 0.6396
2 2.0 0.8165
3 2.5 0.9806
4 3.0 1.1339
5 3.5 1.2780
6 4.0 1.4142
Total 1.8614 prepared by Razana Alwee 2.8982 1.9504
32

prepared by Razana Alwee 16


5/15/2016

Example

3 2
4 x h 
 dx   f 0  f 6   4 f 2 i 1  2 f 2i 
1
x4 3 i 1 i 1 

0.5
 1.8614  4(2.8982)  2(1.9504)
3
 2.8925

prepared by Razana Alwee

33

Example

For h=0.25, a=1 and b=4

b  a 4 1
N   12 (N is even)
h 0.25

prepared by Razana Alwee

34

prepared by Razana Alwee 17


5/15/2016

xi
i xi f i  f ( xi ) 
xi  4
Example
0 1 .00 0 .4472
1 1 .25 0 .5455
2 1 .50 0 .6396
3 1 .75 0 .7298
4 2 .00 0 . 8165
5 2 . 25 0 . 9000
6 2 .50 0 .9806
7 2 . 75 1 . 0585
8 3 .00 1 .1339
9 3 . 25 1 .2070
10 3 .50 1 .2780
11 3 . 75 1 .3470
12 4 .00 1 .4142
prepared by Razana Alwee
Total 1 .8614 5 . 7878 4 . 8486
35

Example

6 5
4 x h 
 dx   f  f   4  f  2 f
3  
1 0 12 2 i 1 2 i
x4 i 1 i 1 

0.25
 1.8614  4(5.7878)  2(4.8486)
3
 2.8925

prepared by Razana Alwee

36

prepared by Razana Alwee 18


5/15/2016

Example

Approximate the following integrals using the Simpson’s


3/8 rule with h=0.25.

4 x
 dx
1
x4

prepared by Razana Alwee

37

Example

For h=0.25, a=1 and b=4

b  a 4 1
N   12
h 0.25

prepared by Razana Alwee

38

prepared by Razana Alwee 19


5/15/2016

xi
i xi f i  f ( xi ) 
xi  4
0 1 . 00 0 .4472 Example
1 1 .25 0 .5455
2 1 . 50 0 .6396
3 1 .75 0 . 7298
4 2 . 00 0 .8165
5 2 .25 0 .9000
6 2 . 50 0 .9806
7 2 .75 1 . 0586
8 3 . 00 1 . 1339
9 3 .25 1 . 2070
10 3 . 50 1 . 2780
11 3 .75 1 . 3470
12 4 . 00 1 .4142
Total 1 .8614prepared by Razana Alwee
7 .7191 2 . 9174
39

Example

4 3
4 x 3h  
 dx   f  f   3  f  f   2  f
8  
1 0 12 3i  2 3i 1 3i
x4 i 1 i 1 

3(0.25)
 1.8614  3(7.7191)  2(2.9174)
8

 2.8925

prepared by Razana Alwee

40

prepared by Razana Alwee 20


5/15/2016

Simpson’s Rule

Simpson’s 1/3 rule is usually the method of preference


because it attains third-order accuracy with three points
rather than the four points required for the 3/8 version.

prepared by Razana Alwee

41

Exercise

Approximate the following integral

3 1
 dx
0
x3 1
using
a) The Simpson’s 1/3 rule
b) The Simpson’s 3/8 rule
with N=12.

prepared by Razana Alwee

42

prepared by Razana Alwee 21


5/15/2016

Romberg Integration

Romberg integration uses the Trapezoidal rule to give


preliminary approximations and then applies the
Richardson extrapolation process to improve the
approximations.

prepared by Razana Alwee

43

Romberg Integration

The first step in the Romberg process obtains the


Trapezoidal rule approximations.
Start with 1 subinterval,

h1  b  a

h1
R1,1   f 0  f1 
2

prepared by Razana Alwee

44

prepared by Razana Alwee 22


5/15/2016

Romberg Integration

For Ni subintervals, Ni=2i-1 (eg. N2=2, N3=4, N4=8)

1 ba
hi  hi 1 or hi 
2 2i 1

i 2
1 2 
Ri ,1   Ri 1,1  hi 1  f 2 k 1 
2 k 1 
i=2, 3, …

prepared by Razana Alwee

45

Romberg Integration

Example: for i=2, N2=22-1=2

1
h2  h
2 1

1 
R2 ,1  h2   f 0  f 2   f 1 
2 

prepared by Razana Alwee

46

prepared by Razana Alwee 23


5/15/2016

Romberg Integration

1  h1 1 
R2 ,1  h2   f 0  f 2   f 1    2  f 0  f 2   f 1 
2  2

1  h1  1
 
2  2 0
f  f 2   h f
1 1
 R1,1  h1 f 1
 2
 
1
1 
  R1,1  h1  f 2 k 1 
2 k 1 

prepared by Razana Alwee

47

Romberg Integration

Example: for i=3, N3=23-1=4

1
h3  h
2 2

1 
R3,1  h3   f 0  f 4   f 1  f 2  f 3 
2 

prepared by Razana Alwee

48

prepared by Razana Alwee 24


5/15/2016

Romberg Integration

1 
R3,1  h3   f 0  f 4   f 1  f 2  f 3 
2 
h 1 
 2   f 0  f 4   f1  f 2  f 3 
2 2 
1 h 
  2  f 0  f 4   h2 f 2  h2  f 1  f 3 
22 
2
1 1 
2

 R2 ,1  h2  f 1  f 3   
2  R 2 ,1  h 2  f 2 k 1 
k 1 

prepared by Razana Alwee

49

Romberg Integration

i2
1 2 
Ri ,1   Ri 1,1  hi 1  f 2 k 1 
2 k 1 

For i=2, 3, …
1
hi 1  h
2 i 2

prepared by Razana Alwee

50

prepared by Razana Alwee 25


5/15/2016

Romberg Integration

Richardson’s improvement,

4 j 1 Ri , j 1  Ri 1, j 1
Ri , j 
4 j 1  1

for i = 2, 3, …, N and j = 2, 3 …, i.

prepared by Razana Alwee

51

Romberg Integration

4 R2 ,1  R1,1 4 R3,1  R2 ,1
R2 ,2  R3,2 
3 3

16 R3,2  R2 ,2 64 R4 ,3  R3,3
R3,3  R4 ,4 
15 63

prepared by Razana Alwee

52

prepared by Razana Alwee 26


5/15/2016

Romberg Table

ba
i hi  Ri ,1 Ri , 2 Ri , 3 ... Ri , N
2 i 1
1 h1 R1,1
2 h2 R2,1 R 2, 2
3 h3 R3,1 R3, 2 R3,3
... ... ... ... ... ...
N hN R N ,1 RN ,2 R N ,3 ... RN , N

Compute the Romberg table until |Ri,j - Ri,j-1|<


prepared by Razana Alwee

53

Example

Use Romberg integration to approximate

4 x
 dx
1
x4

Compute the Romberg table until |Ri,j  Ri,j-1|<0.0005

prepared by Razana Alwee

54

prepared by Razana Alwee 27


5/15/2016

Example

h1  b  a  4  1  3

h1
R1,1   f 0  f1 
2
3
 0.4472  1.4142
2
 2.7921.

prepared by Razana Alwee

55

Example

1
1 
R2 ,1   R1,1  h1  f 2 k 1 
2 k 1 
1
 R1,1  h1 ( f1 )  1 R1,1  h1 ( f (2.5))
2 2
1
 2.7921  30.9806  2.8670
2

prepared by Razana Alwee

56

prepared by Razana Alwee 28


5/15/2016

Example

4 R2 ,1  R1,1 42.8670  2.7921


R2 , 2    2.8920
3 3

R2 , 2  R2,1  2.8920  2.8670  0.025  0.0005

prepared by Razana Alwee

57

Example

2
1  1
R3,1   R 2 ,1  h2  f 2 k 1   R2,1  h2 ( f1  f 3 )
2 k 1  2
1
 R2,1  h2 ( f (1.75)  f (3.25))
2
1
 2.8670  1.50.7298  1.2070  2.8861
2

prepared by Razana Alwee

58

prepared by Razana Alwee 29


5/15/2016

Example

4 R3,1  R2,1 42.8861  2.8670


R3, 2    2.8925
3 3

R3, 2  R3,1  2.8925  2.8861  0.0064  0.0005

prepared by Razana Alwee

59

Example

16 R3, 2  R2, 2 162.8925  2.8920


R3,3    2.8925
15 15

R3,3  R3, 2  2.8925  2.8925  0.0000  0.0005

prepared by Razana Alwee

60

prepared by Razana Alwee 30


5/15/2016

Example

The solution is,

4 x
 1
x4
dx  R3,3  2.8925

prepared by Razana Alwee

61

Example

The Romberg Table,

ba
i hi  Ri ,1 Ri , 2 Ri ,3
2i 1

1 3 2.7921
2 1 .5 2.8670 2.8920
3 0.75 2.8861 2.8925 2.8925

prepared by Razana Alwee

62

prepared by Razana Alwee 31


5/15/2016

Exercise

Use Romberg integration to approximate:

2 
(a)  ( 4  x 2 ) 1 2 dx (b)  sin x dx
0 0

Compute the Romberg table until |Ri,j  Ri,j-1|<0.005

prepared by Razana Alwee

63

Exercise

Use the two point and three point Gaussian Quadrature


to approximate:

2 1 1
(a)  x 3  1 dx (b)  dx
1 1 1 x2

Do calculations in 4 decimal points.

prepared by Razana Alwee

64

prepared by Razana Alwee 32

You might also like