Sie sind auf Seite 1von 6

Numerical Integration (nite integrals)

Trapezoid method

In order to nd the integral

Z b

f (x) dx

in the interval [a, b], we use the area under the curve method.

Divide the area under the curve into n tapezoids (Fig. (a))
Calculate the area of each trapezoid
Sum all areas
Total area is denoted by T (f ; P ), where P (a = x0 < x1 < x2 < ...................... < xn = b).

Area of the ith trapezoid (Fig. (b))


Ai =

Z xi+1
xi

f (x) dx = {xi+1 xi }

o
1n
f (xi) + f (xi+1 )
2

Total area
T (f ; P ) =

Z b

f (x) dx =

n1
X

n
o
X
1 n1
{xi+1 xi } f (xi) + f (xi+1 )
2 i=0

Ai =

i=0

Here we have not specied the nature of division into n trapezoids. Without loss of generality,
we can divide uniform spacing between xi and xi+1 . This implies that the spacing between the
two iintervals
h=

ba
n

so that xi = a + ih and xi+1 xi = h. Then


T (f ; P ) =

Z b

f (x) dx =

o
X n
h n1
f (xi) + f (xi+1 )
2 i=0

h
{[f (x0 ) + f (x1 )] + [f (x1 ) + f (x2 )] + [f (x2 ) + f (x3 )] + ....................... + [f (xn1 ) + f (xn )]}
2
Since each xi term gets added twice other than x0 and xn , we can write

T (f ; P ) =

Z b

f (x) dx =

n1
X
h
{f (a) + f (b)} + h
f (a + ih)
2
i=1

This is the basic trapezoid method.


1

(1)

Problem:

Write a Fortran 90 program to nd the integral


Z 1
0

4
dx
1 + x2

using Eqn. (1).


Recursive Trapezoid

We see that the accuracy of the calculation depends on the number of intervals n. Thus we can
use the recursive method to improve the accuracy. In this case, we divide the interval [a, b] into
2n equal intervals rather than n intervals and replace the notation T (f ; P ) by R(n, 0). Then
R(n, 0) =

Z b

f (x) dx = hC + h

n 1
2X

(2)

f (a + ih)

i=1

We see that while calculating R(n, 0), we also evaluate the function at points which is already
evauated by R(n 1, 0). This repeatation of the calculation can be avoided by the following
simplication. Take for example,
R(2, 0) = h00 C + h00 {f (a + h00 ) + f (a + 2h00 ) + f (a + 3h00 )}
R(3, 0) = h000 C + h000 {f (a + h000 ) + f (a + 2h000 ) + f (a + 3h000 ) + f (a + 4h000 )
+ f (a + 5h000 ) + f (a + 6h000 ) + f (a + 7h000 )}

Since h000 = h00 /2


h00
h00
h00
3
R(3, 0) = C +
f (a + ) + f (a + h00 ) + f (a + h00 ) + f (a + 2h00 )
2
2
2
2
(

7
5
+ f (a + h00 ) + f (a + 3h00 ) + f (a + h00 )
2
2
1
While calculating R(3, 0), we can use 2 R(2, 0) and then the remaining terms in R(3, 0).


1
h00
h00
3
5
7
R(3, 0) R(2, 0) =
f (a + ) + f (a + h00 ) + f (a + h00 ) + f (a + h00 )
2
2
2
2
2
2
(

= h000 {f (a + h000 ) + f (a + 3h000 ) + f (a + 5h000 ) + f (a + 7h000 )}

This implies that

1
R(3, 0) = R(2, 0) +
2

1
R(3, 0) R(2, 0)
2

This can be generalized as


1
R(n, 0) = R(n 1, 0) +
2

1
R(n, 0) R(n 1, 0)
2

(3)

From eqn.(2), we have


R(n, 0) = hC + h

n 1
2X

f (a + ih)

i=1
0

R(n 1, 0) = h C + h

n 1
2X

f (a + jh0 )

j=1

But h = 2h. Hence


0

R(n 1, 0) = 2hC + 2h

n 1
2X

f (a + 2jh)

j=1
n

n1

2X
1
2X
1
2X
1
f (a + ih) h
f (a + 2jh) = h
f (a + [2k 1]h)
R(n, 0) R(n 1, 0) = h
2
i=1
j=1
k=1

Hence Eqn. (3) can be written as


n1

2X
1
f (a + [2k 1]h)
R(n, 0) = R(n 1, 0) + h
2
k=1

(4)

For example
1
R(3, 0) = R(2, 0) + h {f (a + h) + f (a + 3h) + f (a + 5h) + f 9(a + 7h)}
2

which is same as the one calcuated earlier. All the even terms get calculaed in the R(2, 0) term,
and the odd terms are added to the new term.
Problem:

Write a Fortran 90 program to nd the integral


Z 1
0

4
dx
1 + x2

using Eqn. (4).


Romberg Algorithm

The recursive trapezoid can be further extrapolated using Romberg Algorithm to improve the
accuracy. Instead of calculating R(n, 0), one can calculate R(n, m), extraplated from R(n, 0)
using the equation
R(n, m) = R(n, m 1) +

1
{R(n, m 1) R(n 1, m 1)}
4m 1

This will form a triangular matrix of the form


R(0, 0)
R(1, 0)
R(2, 0)

....
R(n, 0)

R(1, 1)
R(2, 1) R(2, 2)

.......
......

.....
........

..........
........ R(n, n)

For exampe:
R(2, 1) = R(2, 0) +

while R(0, 0) is given by

h=ba
h1 = h/2
h2 = h1 /2
hn = hn1 /2

1
{R(2, 0) R(1, 0)}
3

1
R(0, 0) = (b a) {f (a) + f (b)}
2

(5)

Problem:

Write a Fortran 90 program to nd the integral


Z 1
0

4
dx
1 + x2

using Eqn. (5).

Simpson's rule for integration


Basic Simson's equation
Z a+2h

h
{f (a) + 4f (a + h) + f (a + 2h)}
3

f (x) dx

(6)

Problem:

Write a Fortran 90 program to nd the integral


Z 1
0

4
dx
1 + x2

using Eqn. (5).


Error Estimation

h2 00 h3 000 h4 0000
f + f + f + ...............
2
6
24
2
3
4h 00 8h 000 16h4 0000
f (a + 2h) = f (a) + 2hf 0 +
f +
f +
f + ...............
2!
3!
4!
4h3 000 2h4 0000
= f (a) + 2hf 0 + 2h2 f 00 +
f +
f + ...............
3
3
2h3 000 h4 0000
0
2 00
f + f + ...............
4f (a + h) = 4f (a) + 4hf + 2h f +
3
6
5h4 0000
f (a) + 4f (a + h) + f (a + 2h) = 6f (a) + 6hf 0 + 4h2 f 00 + 2h3 f 000 +
f + ...............
6
h
4
2
5h5 0000
{f (a) + 4f (a + h) + f (a + 2h)} = 2hf (a) + 2h2 f 0 + h3 f 00 + h4 f 000 +
f + ............... (7)
3
3
3
18
f (a + h) = f (a) + hf 0 +

Eqn. (7) is the RHS of eqn. (6), the basic Simpson.


Now consider another arbitrary function F and take the expansion at a + 2h. i.e.,
4h3 000 2h4 0000
F (a + 2h) = F (a) + 2hF + 2h F +
F +
F + ...............
3
3
0

If we take
F (x) =

00

Z x

f (t) dt

(8)

then F (a) = 0, F 0 = f , F 00 = f 0 , F 000 = f 00 , ......., etc. Then eqn. (8) can be written as
Z a+2h
a

4h3 00 2h4 000 4h5 0000


f +
f +
f + ...............
3
3
15
h
5h5 0000 4h5 0000
= {f (a) + 4f (a + h) + f (a + 2h)}
f +
f + .........
3
18
15

f (x) dx = F (a + 2h) = 2hf + 2h2 f 0 +

using eqn. (7). This implies


Z a+2h

h
{f (a) + 4f (a + h) + f (a + 2h)} + O(h5 )
3
a
That is, basic Simpson is accuracte upto the order of h5 .
f (x) dx =

(9)
(10)

Adaptive Simpson Method


In order to improve the accuracy further, Adaptive Simpson method is used where the interval
[a,b] is further divided into subintravals and basic Simpson is used in each interval and summed
together. Basic Simpson (1-Simpson) can be written as
I=

Z b

(11)

f (x) dx = S 1 [a, b] + E 1 [a, b]

where integral value


S 1 [a, b] =

h
{f (a) + 4f (a + h) + f (a + 2h)}
3

and the error


E 1 [a, b] =

1 5 0000
hf
90

In 2-Simpson, the inerval [a,b] is divided into two equal subintervals [a,c] and [c,b], where c is
the midpoint of [a,b]. 1-Simpson is calculated in each interval and added together to obtain I .
That is
I = S 2 [a, b] + E 2 [a, b]
(12)
where

(13)

S 2 [a, b] = S 1 [a, c] + S 1 [c, b]


E 2 [a, b] = E 1 [a, c] + E 1 [c, b] =

1
90

h
2

!5

f 0000

1
90

h
2

!5

f 0000 =

1 1
E [a, b]
16

(14)

From eqn. (11) and eqn. (12), we have


(15)

S 2 [a, b] S 1 [a, b] = E 1 [a, b] E 2 [a, b] = 15E 2 [a, b]

From eqn. (12)


I = S 2 [a, b] + E 2 [a, b] = S 2 [a, b] +

o
1 n 2
S [a, b] S 1 [a, b]
15

(16)

Thus we can use the second term as an accuracy check for guiding the adaptive process. i.e.,
check whether


1 2

S [a, b] S 1 [a, b] <
15

for exiting the loop. Otherwise, the intervals are further divided and the Simpsons are calculated
for each interval and summed.
Method:

Since a + 2h = b, h = (b a)/2 and c = (a + b)/2, calculate S 1 [a, b] and S 2 [a, b] using the

following equations

h
S [a, b] =
f (a) + 4f
6
1

a+b
+ f (b)
2

h
a+c
S 2 [a, b] =
f (a) + 4f
+ 2f (c) + 4f
12
2


c+b
+ f (b)
2

If |S 2 S 1 | < 15, where is the required accuracy, then exit and the integral value will

be

I[a, b] =

o
1 n
16S 2 S 1
15

(17)

If |S 2 S 1 | > 15, then divide the interval [a,b] into two subintervals [a,c] and [c,b] and
calculate S 1 and S 2 for each interval.
Check whether the condition, |S 2 S 1 | < 15 2 , is satised for each interval. If it satises
both the intervals, then I[a, b] = I[a, c] + I[c, b] where I[a, c] and I[c, b] are given by the

condition from Eqn. (17).

The process can be continued until the required condition is satised for each subinterval.

Das könnte Ihnen auch gefallen