0% found this document useful (0 votes)
28 views29 pages

Numerical Integration: Trapezoidal Rule

Lecture Notes under Computational science and Numerical Methods

Uploaded by

nanyaobiefule
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views29 pages

Numerical Integration: Trapezoidal Rule

Lecture Notes under Computational science and Numerical Methods

Uploaded by

nanyaobiefule
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 29

Trapezoidal Rule of

Integration

Authors: Autar Kaw, Charlie Barker

http://numericalmethods.eng.usf.e
du
Transforming Numerical Methods Education for STEM
Undergraduates

http://
12/29/24 numericalmethods.eng.usf.edu 1
Trapezoidal Rule of
Integration

http://numericalmethods.eng.usf.
edu
What is Integration
b

f ( x )dx
Integration: y
a

f(x)
The process of
measuring the 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 b x

b= upper limit of
3 integration http://numericalmethods.eng.usf.edu
Basis of Trapezoidal Rule
Trapezoidal Rule is based on the Newton-Cotes
Formula that states if one can approximate the
integrand as an nth order polynomial…

b
I f ( x )dx where f ( x )  fn( x )
a

and f n ( x ) a0  a1 x  ...  an  1 x n  1  an x n

4 http://numericalmethods.eng.usf.edu
Basis of Trapezoidal Rule
Then the integral of that function is approximated
by the integral of that nth order polynomial.

b b

f ( x ) f n ( x )
a a

Trapezoidal Rule assumes n=1, that is, the


area under the linear polynomial,
b
 f ( a )  f ( b )
f ( x )dx ( b  a ) 
a
2

5 http://numericalmethods.eng.usf.edu
Derivation of the Trapezoidal
Rule

6 http://numericalmethods.eng.usf.edu
Method Derived From
Geometry
b

f ( x )dx
1

The area under the y


a

f(x)
curve is a
trapezoid. The
b integral
f ( x)dx  Area of
a
trapezoid
f1(x)
1
 ( Sum of parallel sides )( height )
2
1
  f ( b )  f ( a )( b  a )
2
 f ( a )  f ( b )
( b  a )  a b x
 2
Figure 2: Geometric Representation

7 http://numericalmethods.eng.usf.edu
Example 1
The vertical distance covered by a rocket from t=8
to t=30 seconds is given by:

30
  140000  
x   2000 ln    9 .8t  dt
8  140000  2100t  

a) Use single segment Trapezoidal rule to find the distance


covered. Et
b) Find the true error, for part (a).a
c) Find the absolute relative true error, for part (a).

8 http://numericalmethods.eng.usf.edu
Solution
 f ( a )  f ( b )
a) I ( b  a ) 
 2
a 8 b 30
 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 )

9 http://numericalmethods.eng.usf.edu
Solution (cont)
 177.27  901.67 
a) I ( 30  8 ) 
 2

11868 m

b)The exact value of the above integral is

30
  140000  
x   2000 ln    9 .8t  dt 11061 m
8  140000  2100t  

10 http://numericalmethods.eng.usf.edu
Solution (cont)
b) 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

11 http://numericalmethods.eng.usf.edu
Multiple Segment Trapezoidal
Rule

In Example 1, the true error using single segment trapezoidal rule


was large. We can divide the interval [8,30] into [8,19] and
[19,30] intervals and apply Trapezoidal rule over each segment.

 140000 
f ( t )  2000 ln   9.8t
 140000  2100t 
30 19 30

f ( t )dt  f ( t )dt  f ( t )dt


8 8 19

 f ( 8 )  f ( 19 )  f ( 19 )  f ( 30 )
( 19  8 )   ( 30  19 ) 
 2   2
12 http://numericalmethods.eng.usf.edu
Multiple Segment Trapezoidal
Rule
With

f ( 8 ) 177.27 m / s

f ( 30 ) 901.67 m / s
f ( 19 ) 484.75 m / s
Hence:

30
 177.27  484.75   484.75  901.67 

8
f ( t ) dt (19  8)  2   ( 30  19 )  2 

11266 m
13 http://numericalmethods.eng.usf.edu
Multiple Segment Trapezoidal
Rule
The true error is:
Et 11061  11266
 205 m

The true error now is reduced from -807 m to -205


m.

Extending this procedure to divide the interval into


equal segments to apply the Trapezoidal rule; the
sum of the results obtained for each segment is
the approximate value of the integral.

14 http://numericalmethods.eng.usf.edu
Multiple Segment Trapezoidal
Rule
y
f(x)
Divide into equal
segments as shown in
Figure 4. Then the width
of each segment
b  a is:
h
n
The integral I is:

b
I  f ( x )dx
a a b x
b a b a b a
a a2 a 3
4 4 4

Figure 4: Multiple (n=4) Segment Trapezoidal


Rule

15 http://numericalmethods.eng.usf.edu
Multiple Segment Trapezoidal
Rule
The integral I can be broken into h integrals
b a h
as: a  2 h 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

Applying Trapezoidal rule on each segment gives:

b
b a n  1  

f ( x )dx 2n  f ( a )  2  f ( a  ih )  f ( b )
a  i 1 

16 http://numericalmethods.eng.usf.edu
Example 2
The vertical distance covered by a rocket from 8 to 30
seconds is given by:
30
  140000  
x   2000 ln    9.8t  dt
8  140000  2100t  

a) Use two-segment Trapezoidal rule to find the distance


covered. Et
b) Find the true error, a
for part (a).
c) Find the absolute relative true error, for part (a).

17 http://numericalmethods.eng.usf.edu
Solution
a) The solution using 2-segment Trapezoidal rule is

b a n  1  
I  f ( a )  2  f ( a  ih )  f ( b )
2n   i 1  

n 2 a 8 b 30

b a 30  8
h  11
n 2

18 http://numericalmethods.eng.usf.edu
Solution (cont)
Then:
30  8  2  1  
I  f ( 8 )  2  f ( a  ih )  f ( 30 )
2( 2 )   i 1  
22
  f ( 8 )  2 f ( 19 )  f ( 30 )
4

22
 177.27  2( 484.75 )  901.67
4

11266 m

19 http://numericalmethods.eng.usf.edu
Solution (cont)
b) The exact value of the above integral is
30
  140000  
x   2000 ln    9 . 8t  dt 11061 m
8  140000  2100t  

so the true error is

E t True Value  Approximat e Value

11061  11266

20 http://numericalmethods.eng.usf.edu
Solution (cont)
The absolute relative true error
, t , would be

True Error
t  100
True Value

11061  11266
 100
11061

1.8534%

21 http://numericalmethods.eng.usf.edu
Solution (cont)
Table 1 gives the values
n Value Et t % a %
obtained using multiple
segment Trapezoidal rule 1 11868 -807 7.296 ---
for 2 11266 -205 1.853 5.343
30 3 11153 -91.4 0.8265 1.019
  140000  
x   2000 ln    9.8t  dt 4 11113 -51.5 0.4655 0.3594
8  140000  2100t  
5 11094 -33.0 0.2981 0.1669
6 11084 -22.9 0.2070 0.0908
Exact Value=11061 m 2
7 11078 -16.8 0.1521 0.0548
2
Table 1: Multiple Segment Trapezoidal Rule
8
Values 11074 -12.9 0.1165 0.0356
0

22 http://numericalmethods.eng.usf.edu
Example 3
Use Multiple Segment Trapezoidal Rule to
find the area under the curve
300 x
f(x) from x 0 to x 10
1 ex

Using two segments, we get 10  0


h 5 and
2

300( 0 ) 300( 5 ) 300( 10 )


f(0) 0
0 f (5)  5
10.039 f ( 10 )  10
0.136
1 e 1 e 1 e

23 http://numericalmethods.eng.usf.edu
Solution
Then:

b a n  1  
I  f ( a )  2  f ( a  ih )  f ( b )
2n   i 1  

10  0  2  1  
  f ( 0 )  2  f ( 0  5 )  f ( 10 )
2( 2 )   i 1  

10 10
  f ( 0 )  2 f ( 5 )  f ( 10 )  0  2( 10.039 )  0.136
4 4

50.535

24 http://numericalmethods.eng.usf.edu
Solution (cont)
So what is the true value of this integral?
10
300 x
 x
dx 246.59
01 e

Making the absolute relative true error:

246.59  50.535
t  100%
246.59

79.506%

25 http://numericalmethods.eng.usf.edu
Solution (cont)
Table 2: Values obtained using Multiple Segment
Trapezoidal Rule for: 10 300 x
 x
dx
01 e

n Approximate
Et t
Value
1 0.681 245.91 99.724%
2 50.535 196.05 79.505%
4 170.61 75.978 30.812%
8 227.04 19.546 7.927%
16 241.70 4.887 1.982%
32 245.37 1.222 0.495%
64 246.28 0.305 0.124%

26 http://numericalmethods.eng.usf.edu
Additional Resources
For all resources on this topic such as digital
audiovisual lectures, primers, textbook chapters,
multiple-choice tests, worksheets in MATLAB,
MATHEMATICA, MathCad and MAPLE, blogs,
related physical problems, please visit

http://numericalmethods.eng.usf.edu/topics/trap
ezoidal_rule.html
2024/2025 Assignment

Due 9 December 2024


Write Python code to:

1)Plot the graph for the equation in Slide


8
2) Use Trapezoidal Rule to calculate the
area of the graph from point a = 8 to
point b = 30 using multiple iterations(n
= 1 to n = 20); calculating the absolute
28
relative true error for every iteration
http://numericalmethods.eng.usf.edu
THE END

http://numericalmethods.eng.usf.edu

You might also like