Anda di halaman 1dari 28

NUMERICAL INTEGRATION

Suppose we want to evaluate the integral of


1
−x 2
∫e dx
0

We cannot do it analytically. For these cases one needs to


take help of numerical methods for doing integrations.

The methods are based on the following general principle:


b

∫ f  xdx= Area under the curve


a
y

f(x)

a b x
Lower and Upper sums: approx. of area under the
curve
(A) Lower sums:

a=x0 x1 x2 x3 x4 x5 x6=b
Let P be a partition of the interval [a,b] given by
P= { a=x 0x 1x 2⋯⋯x n−1x n=b }
with partition points x0, x1, ......,xn that divide [a,b] into n
sub-intervals [xi,xi+1].
Greatest lower bound (infimum, inf) of f(x) on the sub-interval
[xi,xi+1] is: m i=inf { f  x: x ixx i1 }
n−1
Lf ; P=∑ mi  x i1−x i  Underestimates
Lower sum of f(x): i=0
Lower and Upper sums: approx. of area under the
curve
(A) Upper sums:

a=x0 x1 x2 x3 x4 x5 x6=b
Let P be a partition of the interval [a,b] given by
P= { a=x 0x 1x 2⋯⋯x n−1x n=b }
with partition points x0, x1, ......,xn that divide [a,b] into n
sub-intervals [xi,xi+1].
Least upper bound (suppremum, sup) of f(x) on the
Sub-interval [xi,xi+1] is: M i=sup { f  x: x i xx i1 }
n−1

Lower sum of f(x): U f ; P=∑ M i  x i1−x i  Overestimates


i=0
b
Therefore the expression ∫ f x dx which we are trying
to define should satisfy a
b

Lf ; P∫ f  x dxU f ; P


a

for all partitions P


Left Riemann Sum

n−1
L=∑ f  x i  x
i=0
Right Riemann Sum

n−1
R=∑ f  x i1  x
i=0
An example:
1
−x 2
Evaluate the integral of : ∫e dx
0

using the lower sum and upper sum methods


n−1 n−1
xi21
Lf ; P n =∑ h f  x i1 =h ∑ e
i=0 i=0

n−1 n−1
x 2i
U f ; P n =∑ h f  x i =h ∑ e
i=0 i=0

=hf  x 0 Lf ; P n −hf  x n 


−1
=L f ; P n −h1−e 

Note that evaluating U and P in the above way is more efficient


than separately evaluating U & P
program Sums
Psuedocode: integer i; real h, sum_lower, sum_upper, x
integer n 1000; real a 0, b 1
h (b-a)/n
sum 0.0
for i=1 to n step -1 do
x a+ih
sum sum + f(x)
end for
sum_lower (sum)h
sum_upper sum_lower + h[f(a)-f(b)]
output sum_lower, sum_upper

end program Sums

real function f(x)


real x
f e-x²
end function f

Example (2): cosx 
∫e dx
0

If the above integral is to be calculated with absolute error


less than 0.5 x 10-3 and if we want to use upper & lower
sums with a uniform partition, how many sub-intervals are
needed?
cosx 
e is a decreasing function in the interval [0,π]. Therefore
m i=f x i1  M i=f  x i 

If P denote the partition of [0,π] by n+1 equally spaced pts,


then there will be n sub-intervals of width π/n
n−1 n−1
 
Lf ; P= ∑ mi = ∑ f  x i1 
n i=0 n i=0
n−1 n−1
 
U f ; P= ∑ M i= ∑ f  x i 
n i=0 n i=0
The correct value of the integral lies in the interval between
L and P. Let us take the mid point of the interval at the best
estimate. Therefore the error is at the most:

1 1 −3
[U f ; P−Lf ; P] ∗10
2 2
1 −1 −3
/ne −e 10
n7385
Trapezoidal Rule

a=x0 x1 x2 x3 x4 x5=b

Area under the sub-interval, [xi,xi+1]


x i 1
1
∫ f  xdx≈ 2  xi1−xi [f  x i f  xi1 ]
x i

Total area under the curve:


b n−1
1
∫ f  xdx≈ 2 ∑  x i1−xi [f  xi f  xi1 ]
a i=0

Composite Trapezoidal Rule


If the spacing is uniform then
b n−1
h
∫ f  xdx≈ 2 ∑ [f  xi f  x i1 ]
a i=0

where xi+1-xi=h=(b-a)/n
An efficient way of doing it is:
b

{ }
n−1
1
∫ f  xdx≈h 2 [ f  x 0 f  xn ]∑ f  xi 
a i=1
program Trapezoid
integer i; real h, sum, x
integer n 60; real a 0, b 1
h (b-a)/n
sum 1/2[f(a)+f(b)]
for i=1 to n-1 do
x a+ih
sum sum+f(x)
end for
sum (sum)h
output sum
end program Trapezoid

real function f(x)


real x
f e-x²
end function f
Recursive Trapezoidal Formula for Equal Sub-Intervals:

Suppose the interval [a,b] is subdivided into 2n equal parts


b

{ }
n−1
1
∫ f  xdx≈h 2 [ f  x 0 f  xn ]∑ f  xi 
a i=1
n−1
h
=h ∑ f aih [f af b]
i=1 2

Replace n by 2n and use h=(b-a)/2n


2n−1
h
R n , 0=h ∑ f aih [ f af b]
i=1 2
a b
20
R(0,0)
21 R(1,0)

22 R(2,0)

23 R(3,0)

If R(n-1,0) has been computed, we want to use this information


to compute R(n,0)
1 1
R n , 0= R n−1,0[ R n , 0− R n−1,0]
2 2
h
Let C= [ f af b]
2
2n−1
h
Recall: R n , 0=h ∑ f aih [ f af b]
i=1 2
2n −1
R n ,0=h ∑ f aihC
i=1

The sub-intervals for R(n-1,0) are twice the size of those for
R(n,0), i.e., h should be replaced with 2h
2n−1 −1
R n−1,0=2h ∑ f a2 j h2C
j=1
2n −1 2n−1−1
1
R n ,0− R n−1,0=h ∑ f aih−h ∑ f a2 j h
2 i=1 j=1
n−1
2
=h ∑ f [a2 k−1h]
k=1
Recursive Trapezoid Formula:

If R(n-1,0) is available then R(n,0) is given by:


2n−1
1
R n ,0= R n−1,0h ∑ f [a2k−1h] n1
2 k=1

n
h=b−a/2
1
R 0,0= b−a[ f af b]
2
Advantage: Allows us to compute a sequence of
approximations to a definite integral using the trapezoid rule
without re-evaluating the integrand at points where it has
already been evaluated.
Romberg Algorithm:
✔ Uses a combination of Richardson extrapolation and
Recursive Trapezoid formula.

✔ Produces a triangular array of numbers all of which are


b

numerical estimates of the definite integral ∫ f  x  dx


a

R(0,0)
R(1,0) R(1,1)
R(2,0) R(2,1) R(2,2)
R(3,0) R(3,1) R(3,2) R(3,3)
. . . . .
. . . . .
R(n-1,0) R(n-1,1) . . R(n-1,n-1)
R(n,0) R(n,1) R(n,2) R(n,3) ................R(n,n)
The first column contains estimates using Recursive
Trapezoid Formula
1
R 0,0= b−a[f af b]
2
1 1 ab
R 1,0= R 0,0 b−a f  
2 2 2
n−1
2
1
R n ,0= R n−1,0h ∑ f [a2k−1h]
2 k=1

The second and the successive columns are generated by the


Richardson extrapolation formula:

1
R n , m=R n , m−1 m [ R n , m−1−R n−1, m−1]
4 −1
with n,m≥1
For step size2 hn-1:
h n−1 Error
b−a 4
I=R n−1,0− [f ' b−f ' a] hn−1  n−1 ⋯⋯⋯1
12 720
For step size 2hn:
hn b−a 4
I=R n ,0− [ f ' b−f ' a] hn n ⋯⋯⋯2
12 720
Now, hn=hn-1/2
Eqn (2) becomes:
2
hn−1 b−a 4
I=R n ,0− [ f ' b−f ' a] hn n ⋯⋯⋯3
48 720
4*(3)-(1) we get
4R n , 0−R n−1,0
I= O h 4 =R n , 1
3
In general for R(n,m):
1
R n , m=R n , m−1 m [ R n , m−1−R n−1, m−1]
4 −1
with n,m≥1
R(0,0)
R(1,0) R(1,1)
R(2,0) R(2,1) R(2,2)
R(3,0) R(3,1) R(3,2) R(3,3)
. . . . .
. . . . .
. . . . .
R(n,0) R(n,1) R(n,2) R(n,3) ............. R(n,n)
➢ Convergence along diagonal is faster than along the row.

➢ When 2 diagonal elements R(k-1,k-1) and R(k,k) agree to


the required tolerance, the calculation is said to be
converged.

➢ Perform calculations row wise.

➢ R(k-1, l-1) is used only once to evaluate R(k,j), so no need to


store more than one row of the table.
Newton-Cotes formulae:
b
Aim: To evaluate ∫ f x dx
a

General recipe:

Fit the data point to some polynomial (we will use Lagrangian
polynomial of order n: Pn(x))
b b
Then ∫ f  xdx=∫ Pn  x dx
a a
Case(A): Linear polynomial
x1

Let us evaluate ∫ f x dx


x0
x1 x1
 x−x 1   x−x 0 
∫ f  xdx≈∫ [  x −x  f  x0   x −x  f  x 1 ]dx
x0 x 0
0 1 1 0

 x 1−x 0 
= [ f  x 0 f  x 1 ]
2
Let h=x1-x0
x1
b−a
Then ∫ f  xdx≈ f 0f 1 
x 0
2

This is trapezoidal rule


Error estimation:

The error in the integral is given by the integral of the error


in the polynomial interpolation

For linear interpolation, the interpolation error is:


 x−x 0  x−x 1 
f ' '  x 0x 1
2!

Error in integral:
x1

E T =f ' '
2! x
∫  x−x 0  x−x 1 dx x 0x 1
0

−h3 For a linear polynomial, the integration result


ET = f ' '  using trapezoidal rule has zero error
12
Case(B): Quadratic polynomial

Split interval [a,b] into 2 equal sub-intervals of

size h=(b-a)/2; x0=a, x1=x0+h, x2=x0+2h=b


x2 x2
 x−x 1  x−x 2  x−x 0  x−x 2   x−x 0  x−x 1 
∫ f  x  dx≈∫ [ x −x  x −x  f  x0   x −x  x −x  f  x 1  x −x  x −x  f  x2]dx
x0 x0 0 1 0 2 1 0 1 2 2 0 2 1

x2
b−a
∫ f x dx≈ 6 [ f 04f 1f 2 ] Simpson's Rule
x0

−h5 4
Error: E S = f 
90

Simpson's rule is exact for all polynomials of degree 3


Newton-Cotes closed formula:
Newton-Cotes open formula:

Anda mungkin juga menyukai