Professional Documents
Culture Documents
Integration
Topic: Trapizoidal Rule
Integration
• The inverse process of differentiation
• Dictionary definition of integrate - “to bring together,
as parts, into a whole; to unite; to indicate the total
amount”
• Mathematically, it is the total value or summation of
f(x)dx over a range of x. In fact the integration
symbol is actually a stylized capital S intended to
signify the connection between integration and
summation.
What is Integration
Integration:
The process of measuring the f(x)
area under a function plotted on
a graph.
b
I f ( x )dx
a
Where:
f(x) is the integrand
a= lower limit of integration
a x b
b= upper limit of integration
Numerical Integration
When we have integral from point a to point b, such an integral is
known a definite integral and it is a solution of a simple ordinary
differential equation.
x
Newton-Cotes Integration
• It is a Common numerical integration scheme
• Based on the strategy of replacing a complicated function or
tabulated data with some approximating function:
b b
I f x dx f x dx
n
a a fn(x) is an nth order
f n x a0 a1 x .... an x n polynomial
f(x) f(x)
x x
a b a b
We can also approximate the integral by using a series of polynomials
applied piece-wise.
Single trapezoid
You can fit a straight line and / or a polynomial between two data points.
f(x) f(x)
a b x a b x
Single trapezoid
You can just fit a straight
line as approximation to f(x)
actual function and say
what is area under this
straight line.
For a single trapezoid within the range [a, b], the area or integral can
be approximated as: 1
T (0)
( f a f b )(b a)
2
Single Segment Trapezoidal rule
In this case we fit a straight line as approximate function between a
and b and then find area under the curve. This area will be full of
errors. However, let us find the area.
(b a )
area f (b)(b a ) f (a) f (b) f(x)
2
(b a ) f(a)
area 2 f (b) f (a) f (b)
2
f(b)
(b a )
area f (a) f (b)
2
a b x
Error in the area from the Trapezoidal Rule
1
error f ' ' b a
3
12
where a b
When the function being integrated is linear, the area under curve
from the trapezoidal rule will give exact results as its error will be
zero.
When the function has the second and higher order derivatives (that
is with curvature) then the error can occur.
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
I (30 8) 11868 m
2
Example 1 (continued)
b) The exact value of the above integral is
30
140000
x 2000 ln 9.8t dt 11061 m
8 140000 2100t
Et True Value Approximate Value
11061 11868
807 m
c)
The absolute relative true error,t , would be
11061 11868
t 100 7.2959%
11061
Multiple Application of the Trapezoidal Rule
b
gb g a f ( x )dx
a a x b
(b a )
area f ( xo ) 2 f ( x1 ) 2 f ( x2 ) 2 f ( x3 ) f ( x4 )
2 4
When there are eight sub-divisions in the same range [a, b], the area is
(b a )
area [ f ( xo ) 2 f ( x1 ) 2 f ( x2 ) 2 f ( x3 ) 2 f ( x4 )
28
2 f ( x5 ) 2 f ( x6 ) 2 f ( x7 ) f ( x8 ) ]
The Multiple Application: Trapezoidal Rule
One way to improve the accuracy of the trapezoidal rule is to
divide the integration interval from a to b into a number of
segments and apply the method to each segment.
ba
h a x0 b xn
n
x1 x2 xn
I
x0
f ( x ) dx f ( x ) dx
x1
xn 1
f ( x ) dx
f ( x0 ) f ( x1 ) f ( x1 ) f ( x2 ) f ( xn 1 ) f ( xn )
I h h h
2 2 2
18
Integral for N trapezoids
The integral in general using N compound trapezoids within the
range, is given by
h
Integral f ( x0 ) 2 f ( x1 ) 2 f ( x2 ) 2 f ( xN 1 ) f ( xN )
2
(b a)
where, h
N
xi a nh, n 0, 1, 2, 3, , N
(b a )(h) 2 ( 2 )
error f ( )
12
Example 2
The vertical distance covered by a rocket from to seconds is
given by:
30
140000
x 2000 ln 9.8t dt
8 140000 2100t
22
f ( 8 ) 2 f ( 19 ) f ( 30 )
4
22
177.27 2( 484.75 ) 901.67
4
11266 m
Solution (cont)
b) The exact value of the above integral is
30
140000
x 2000 ln 9.8t dt 11061 m
8 140000 2100t
1.8534%
Solution (cont)
30
140000
x 2000 ln 140000 2100t 9 .8t dt
8
f o f (2.5) 0.16
f 1 f (4.5) 0.0494
a b x
The approximate area under the curve is
(4.5 2.5)
Area (0.16 0.0494) 0.2094
2 1
Example 3
For two subdivisions, we need to have:
f o f (2.5) 0.16
f1 f (3.5) 0.0816
f 2 f (4.5) 0.0494
(b a )
area f ( xo ) 2 f ( x1 ) f ( x2 )
2 2
(4.5 2.5)
Integral (0.16 2. 0.0816 0.0494)
2 2
1863
Example 3
If we divide the interval into four segments, then
h (4.5 2.5) / 4 0.5 f o f ( 2.5) 0.16
f 1 f (4.5) 0.0494
f1 f (3.0) 0.111
f 2 f (3.5) 0.0816
f 3 f (4.0) 0.0625
(b a )
area f ( xo ) 2 f ( x1 ) 2 f ( x2 ) 2 f ( x3 ) f ( x4 )
2 4
(4.5 2.5)
area [0.16 2. (0.111 0.0816 0.0625) 0.0494]
2 4
area 0.1799
Example 3
c integral over an interval [a, b] by trapezoidal rule.
c It calls an external function trapez.m using inputs of a, b
and N (number of sub-divisions).
• Initialize N = 8; a = 2.5; b = 4.5; exact_value =
0.177778;
• Compute delta_x = (b - a)/N;
• Initialize x(1) = a;
• decide : if(x(1) == 0), error('A is zero, change it')
• Initialize values: sum = 0; f(1) = 1.0/(x(1)^2);
• Start a loop1 : from i=2 to N+1
• (a) compute x(i) = x(i-1) + delta_x;
• (b) compute f(i) = 1/(x(i)^2);
• End of loop1
• Start another loop2: from i=2 to N,
• compute sum = sum + f(i);
• End of the loop2
• Compute integral = (delta_x/2)*(f(1) + 2*sum + f(N+1));
• error = abs(100*(exact_value - estimated_value)/exact_value)
Example 3
• The exact value of the Number Area from Percentage
integral is 0.17778. of equal Trapezoidal Error
• A file for algorithm on Sub- Rule
trapezoidal rule is given divisions
and its use for several 1 0.2094 17.8%
sub-intervals is shown as
Table. 2 0.1863 4.8%
• It shows that the error
decreases rapidly as the 4 0.1799 1.2%
number of subdivisions in
the range of integration is 8 0.1783 0.3%
increased.
16 0.1779 0.08%
32 0.1778 0.02%