Math (Trapezoidal Rule For Area Calculation)

Download as pdf or txt
Download as pdf or txt
You are on page 1of 16

Chapter 07.

02
Trapezoidal Rule of Integration

After reading this chapter, you should be able to:


1.
2.
3.
4.
5.

derive the trapezoidal rule of integration,


use the trapezoidal rule of integration to solve problems,
derive the multiple-segment trapezoidal rule of integration,
use the multiple-segment trapezoidal rule of integration to solve problems, and
derive the formula for the true error in the multiple-segment trapezoidal rule of
integration.

What is integration?
Integration is the process of measuring the area under a function plotted on a graph. Why
would we want to integrate a function? Among the most common examples are finding the
velocity of a body from an acceleration function, and displacement of a body from a velocity
function. Throughout many engineering fields, there are (what sometimes seems like)
countless applications for integral calculus. You can read about some of these applications in
Chapters 07.00A-07.00G.
Sometimes, the evaluation of expressions involving these integrals can become daunting, if
not indeterminate. For this reason, a wide variety of numerical methods has been developed
to simplify the integral.
Here, we will discuss the trapezoidal rule of approximating integrals of the form
b

I = f ( x )dx
where

f (x) is called the integrand,


a = lower limit of integration
b = upper limit of integration

What is the trapezoidal rule?


The trapezoidal rule is based on the Newton-Cotes formula that if one approximates the
integrand by an n th order polynomial, then the integral of the function is approximated by

07.02.1

07.02.2

Chapter 07.02

the integral of that n th order polynomial. Integrating polynomials is simple and is based on
the calculus formula.

Figure 1 Integration of a function


b

b n +1 a n +1
a x dx = n + 1 , n 1
So if we want to approximate the integral
n

(1)

I = f ( x)dx

(2)

to find the value of the above integral, one assumes


f ( x) f n ( x)
where
f n ( x) = a 0 + a1 x + ... + a n 1 x n 1 + a n x n .

(3)
(4)

where f n (x) is a n th order polynomial. The trapezoidal rule assumes n = 1 , that is,
approximating the integral by a linear polynomial (straight line),
b

f ( x)dx f1 ( x)dx
a

Derivation of the Trapezoidal Rule


Method 1: Derived from Calculus
b

f ( x)dx f ( x)dx
1

= (a 0 + a1 x)dx
a

b2 a2
= a 0 (b a ) + a1
2

(5)

Trapezoidal Rule

07.02.3

But what is a 0 and a1 ? Now if one chooses, (a, f (a )) and (b, f (b)) as the two points to
approximate f (x) by a straight line from a to b ,
f (a) = f1 (a ) = a 0 + a1 a
f (b) = f1 (b) = a 0 + a1b

(6)
(7)

Solving the above two equations for a1 and a 0 ,


f (b) f (a )
a1 =
ba
f (a )b f (b)a
a0 =
ba
Hence from Equation (5),
b
f (a )b f (b)a
f (b) f (a ) b 2 a 2
f
x
dx

a
+
(
)
(
)
a
ba
ba
2

(8a)

(8b)

f (a ) + f (b)
= (b a )

(9)

Method 2: Also Derived from Calculus


f1 ( x) can also be approximated by using Newtons divided difference polynomial as
f (b) f (a )
f1 ( x) = f (a) +
( x a)
ba
Hence
b

f ( x)dx f1 ( x)dx
a

f (b) f (a )

( x a ) dx
= f (a) +
ba

a
b

f (b) f (a ) x 2
ax
= f (a) x +
ba
2
a

a2
f (b) f (a ) b
+ a 2
= f (a )b f (a )a +
ab
ba
2
2

2
a2
f (b) f (a) b
= f (a)b f (a)a +
ab +
ba
2
2

f (b) f (a ) 1
2
= f (a )b f (a )a +
(b a )
ba
2

1
= f (a )b f (a )a + ( f (b) f (a ) )(b a )
2

(10)

07.02.4

Chapter 07.02

1
1
1
1
f (b)b f (b)a f (a )b + f (a )a
2
2
2
2
1
1
1
1
= f (a )b f (a )a + f (b)b f (b)a
2
2
2
2
f
(
a
)
+
f
(
b
)

(11)
= (b a )

This gives the same result as Equation (10) because they are just different forms of writing
the same polynomial.
= f (a )b f (a )a +

Method 3: Derived from Geometry


The trapezoidal rule can also be derived from geometry. Look at Figure 2. The area under
the curve f1 ( x) is the area of a trapezoid. The integral
b

f ( x)dx Area of

trapezoid

1
(Sum of length of parallel sides)(Perpendicular distance between parallel sides)
2
1
= ( f (b) + f (a ) )(b a )
2
f (a ) + f (b)
(12)
= (b a )

Figure 2 Geometric representation of trapezoidal rule.


Method 4: Derived from Method of Coefficients
The trapezoidal rule can also be derived by the method of coefficients. The formula
b
ba
ba
a f ( x)dx 2 f (a) + 2 f (b)
2

= ci f ( xi )
i =1

where
c1 =

ba
2

(13)

Trapezoidal Rule

07.02.5

ba
2
x1 = a
x2 = b

c2 =

Figure 3 Area by method of coefficients.


The interpretation is that f (x) is evaluated at points a and b , and each function evaluation
ba
is given a weight of
. Geometrically, Equation (12) is looked at as the area of a
2
trapezoid, while Equation (13) is viewed as the sum of the area of two rectangles, as shown
in Figure 3. How can one derive the trapezoidal rule by the method of coefficients?
Assume
b

f ( x)dx = c

f (a ) + c 2 f (b)

(14)

Let the right hand side be an exact expression for integrals of 1dx and
a

xdx , that is, the


a

formula will then also be exact for linear combinations of f ( x) = 1 and f ( x) = x , that is, for
f ( x) = a 0 (1) + a1 ( x) .
b

1dx = b a = c

+ c2

(15)

b2 a2
= c1 a + c 2 b
2
a
Solving the above two equations gives
ba
c1 =
2
ba
c2 =
2
Hence

xdx =

(16)

(17)

07.02.6

Chapter 07.02
b

f ( x)dx
a

ba
ba
f (a ) +
f (b)
2
2

(18)

Method 5: Another approach on the Method of Coefficients


The trapezoidal rule can also be derived by the method of coefficients by another approach
b
ba
ba
a f ( x)dx 2 f (a) + 2 f (b)
Assume
b

f ( x)dx = c

f (a ) + c 2 f (b)

(19)

Let the right hand side be exact for integrals of the form
b

(a
So

+ a1 x )dx

x2

(
)
a
+
a
x
dx
=
a
x
+
a
1
a 0 1
0
2 a

b2 a2
= a 0 (b a ) + a1
2
But we want
b

(a

+ a1 x )dx = c1 f (a ) + c 2 f (b)

(20)

(21)

to give the same result as Equation (20) for f ( x) = a 0 + a1 x .


b

(a

+ a1 x )dx = c1 (a 0 + a1 a ) + c 2 (a 0 + a1b )

= a 0 (c1 + c 2 ) + a1 (c1 a + c 2 b )
Hence from Equations (20) and (22),
b2 a2
= a 0 (c1 + c 2 ) + a1 (c1 a + c 2 b )
a 0 (b a ) + a1
2

(22)

Since a 0 and a1 are arbitrary for a general straight line


c1 + c 2 = b a
b2 a2
2
Again, solving the above two equations (23) gives
ba
c1 =
2
ba
c2 =
2
c1 a + c 2 b =

(23)

(24)

Trapezoidal Rule

07.02.7

Therefore
b

f ( x)dx c

f (a ) + c 2 f (b)

ba
ba
f (a) +
f (b)
2
2

(25)

Example 1
The vertical distance covered by a rocket from t = 8 to t = 30 seconds is given by
30

140000

9.8t dt
x = 2000 ln

140000 2100t

8
a) Use the single segment trapezoidal rule to find the distance covered for t = 8 to
t = 30 seconds.
b) Find the true error, Et for part (a).
c) Find the absolute relative true error for part (a).
Solution
a)

f (a ) + f (b)
I (b a )
, where
2

a=8
b = 30
140000

f (t ) = 2000 ln
9.8t
140000 2100t

140000
f (8) = 2000 ln
9.8(8)
140000 2100(8)
= 177.27 m/s

140000
f (30) = 2000 ln
9.8(30)
140000 2100(30)
= 901.67 m/s
177.27 + 901.67
I (30 8)

= 11868 m

b) The exact value of the above integral is


30

140000

9.8t dt
x = 2000 ln

140000 2100t

8
= 11061 m
so the true error is
Et = True Value Approximate Value
= 11061 11868
= 807 m

07.02.8

Chapter 07.02

c) The absolute relative true error, t , would then be


True Error
100
True Value
11061 11868
=
100
11061
= 7.2958%

t =

Multiple-Segment Trapezoidal Rule


In Example 1, the true error using a single segment trapezoidal rule was large. We can
divide the interval [8,30] into [8,19] and [19,30] intervals and apply the trapezoidal rule over
each segment.
140000

f (t ) = 2000 ln
9.8t
140000 2100t
30

19

30

19

f (t )dt = f (t )dt + f (t )dt


f (19) + f (30)
f (8) + f (19)
+ (30 19)
(19 8)

2
2

f (8) = 177.27 m/s

140000
9.8(19) = 484.75 m/s
f (19) = 2000 ln
140000
2100
(
19
)

f (30) = 901.67 m/s

Hence
30

177.27 + 484.75
484.75 + 901.67
+ (30 19)

2
2

8
= 11266 m
The true error, Et is

f (t )dt (19 8)

Et = 11061 11266
= 205 m
The true error now is reduced from 807 m to 205 m. Extending this procedure to dividing
[a, b] into n equal segments and applying the trapezoidal rule over each segment, the sum of
the results obtained for each segment is the approximate value of the integral.
Divide (b a ) into n equal segments as shown in Figure 4. Then the width of each segment
is
ba
(26)
h=
n
The integral I can be broken into h integrals as
b

I = f ( x)dx
a

Trapezoidal Rule

a+h

f ( x)dx +

07.02.9
a+2h

a + ( n 1) h

a+h

a +( n2) h

f ( x)dx + ... +

f ( x)dx +

f ( x)dx

(27)

a + ( n 1) h

Figure 4 Multiple ( n = 4 ) segment trapezoidal rule


Applying trapezoidal rule Equation (27) on each segment gives
b
f ( a ) + f ( a + h)
a f ( x)dx = [(a + h) a]

2
f ( a + h) + f ( a + 2h)
+ [(a + 2h) (a + h)]

f (a + (n 2)h) + f (a + (n 1)h)
+ + [(a + (n 1)h ) (a + (n 2)h )]

f (a + (n 1)h) + f (b)
+ [b (a + (n 1)h )]

f ( a ) + f ( a + h)
f ( a + h) + f ( a + 2h)
= h
+ h

+ ...................
2
2

f (a + (n 2)h) + f (a + (n 1)h)
f (a + (n 1)h) + f (b)
+ h
+ h

2
2

f (a ) + 2 f (a + h) + 2 f (a + 2h) + ... + 2 f (a + (n 1)h) + f (b)


= h

n 1

= f (a ) + 2 f (a + ih) + f (b)
2
i =1

ba
n 1

=
f (a ) + 2 f (a + ih) + f (b)
2n
i =1

(28)

07.02.10

Chapter 07.02

Example 2
The vertical distance covered by a rocket from t = 8 to t = 30 seconds is given by
30

140000

9.8t dt
x = 2000 ln

140000 2100t

8
a) Use the two-segment trapezoidal rule to find the distance covered from t = 8 to
t = 30 seconds.
b) Find the true error, Et for part (a).
c) Find the absolute relative true error for part (a).
Solution
a) The solution using 2-segment Trapezoidal rule is

ba
n 1

I
f
(
a
)
2
+
f (a + ih) + f (b)

2n
i =1

n=2
a=8
b = 30
ba
h=
n
30 8
=
2
= 11

30 8
21

I
f (8) + 2 f (8 + 11i ) + 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
=

b) The exact value of the above integral is


30

140000

9.8t dt
x = 2000 ln

140000 2100t

8
= 11061 m
so the true error is
Et = True Value Approximate Value
= 11061 11266
= 205 m
c) The absolute relative true error, t , would then be

Trapezoidal Rule

07.02.11

True Error
100
True Value
11061 11266
=
100
11061
= 1.8537%

t =

Table 1 Values obtained using multiple-segment trapezoidal rule for


30

140000

9.8t dt
x = 2000 ln

140000 2100t

n
1
2
3
4
5
6
7
8

Approximate
Value
11868
11266
11153
11113
11094
11084
11078
11074

Et

t %

a %

-807
-205
-91.4
-51.5
-33.0
-22.9
-16.8
-12.9

7.296
1.853
0.8265
0.4655
0.2981
0.2070
0.1521
0.1165

--5.343
1.019
0.3594
0.1669
0.09082
0.05482
0.03560

Example 3
Use the multiple-segment trapezoidal rule to find the area under the curve
300 x
f ( x) =
1+ ex
from x = 0 to x = 10 .
Solution
Using two segments, we get
10 0
h=
=5
2
300(0)
f (0) =
=0
1 + e0
300(5)
f (5) =
= 10.039
1 + e5
300(10)
f (10) =
= 0.136
1 + e10

ba
n 1

I
f
(
a
)
2
+
f (a + ih) + f (b)

2n
i =1

10 0
21

+
(
0
)
2
f
f (0 + 5) + f (10)

2(2)
i =1

07.02.12

Chapter 07.02

10
[ f (0) + 2 f (5) + f (10)]
4
10
= [0 + 2(10.039) + 0.136] = 50.537
4
So what is the true value of this integral?
10
300 x
0 1 + e x dx = 246.59
Making the absolute relative true error
246.59 50.535
t =
100
246.59
= 79.506%
Why is the true value so far away from the approximate values? Just take a look at Figure 5.
As you can see, the area under the trapezoids (yeah, they really look like triangles now)
covers a small portion of the area under the curve. As we add more segments, the
approximated value quickly approaches the true value.
=

Figure 5 2-segment trapezoidal rule approximation.


Table 2 Values obtained using multiple-segment trapezoidal rule for

10

Approximate
Value

Et

0.681

245.91 99.724%

50.535

196.05 79.505%

170.61

75.978 30.812%

227.04

19.546 7.927%

300 x

1+ e

dx .

Trapezoidal Rule

07.02.13

16 241.70

4.887

1.982%

32 245.37

1.222

0.495%

64 246.28

0.305

0.124%

Example 4
Use multiple-segment trapezoidal rule to find
2
1
I =
dx
x
0
Solution
We cannot use the trapezoidal rule for this integral, as the value of the integrand at x = 0 is
infinite. However, it is known that a discontinuity in a curve will not change the area under
it. We can assume any value for the function at x = 0 . The algorithm to define the function
so that we can use the multiple-segment trapezoidal rule is given below.
Function f (x)
If x = 0 Then f = 0
If x 0 Then f = x ^ (0.5)
End Function
Basically, we are just assigning the function a value of zero at x = 0 . Everywhere else, the
function is continuous. This means the true value of our integral will be just thattrue.
Lets see what happens using the multiple-segment trapezoidal rule.
Using two segments, we get
20
h=
=1
2
f (0) = 0
1
f (1) =
=1
1
1
f (2) =
= 0.70711
2

ba
n 1

I
f (a ) + 2 f (a + ih) + f (b)
2n
i =1

20
21

f
(
0
)
+
2
f (0 + 1) + f (2)

2(2)
i =1

2
[ f (0) + 2 f (1) + f (2)]
4
2
= [0 + 2(1) + 0.70711]
4
= 1.3536
=

07.02.14

Chapter 07.02

So what is the true value of this integral?


2
1
0 x dx = 2.8284
Thus making the absolute relative true error
2.8284 1.3536
t =
100
2.8284
= 52.145%
Table 3 Values obtained using multiple-segment trapezoidal rule for

Approximate
Value
2
1.354
4
1.792
8
2.097
16
2.312
32
2.463
64
2.570
128 2.646
256 2.699
512 2.737
1024 2.764
2048 2.783
4096 2.796

Et

1.474
1.036
0.731
0.516
0.365
0.258
0.182
0.129
0.091
0.064
0.045
0.032

52.14%
36.64%
25.85%
18.26%
12.91%
9.128%
6.454%
4.564%
3.227%
2.282%
1.613%
1.141%

1
x

dx .

Error in Multiple-segment Trapezoidal Rule


The true error for a single segment Trapezoidal rule is given by
(b a ) 3
Et =
f " ( ), a < < b
12
Where is some point in [a, b] .
What is the error then in the multiple-segment trapezoidal rule? It will be simply the sum of
the errors from each segment, where the error in each segment is that of the single segment
trapezoidal rule. The error in each segment is
[(a + h ) a ]3 f " ( ), a < < a + h
E1 =
1
1
12
h3
=
f " ( 1 )
12
[(a + 2h ) (a + h )]3 f " ( ), a + h < < a + 2h
E2 =
2
2
12
h3
=
f " ( 2 )
12

Trapezoidal Rule
.
.
.
Ei =

07.02.15

[(a + ih) (a + (i 1)h )]3


12

f " ( i ), a + (i 1)h < i < a + ih

h3
=
f " ( i )
12
.
.
.
[{a + (n 1)h} {a + (n 2)h}]3 f " ( ), a + (n 2)h < < a + (n 1)h
E n 1 =
n 1
n 1
12
h3
f " ( n 1 )
12
[b {a + (n 1)h}]3 f " ( ), a + (n 1)h < < b
En =
n
n
12
h3
=
f " ( n )
12
Hence the total error in the multiple-segment trapezoidal rule is
=

Et = Ei
i =1

h3 n
= f " ( i )
12 i =1
=

(b a ) 3
12n 3

f " ( )

(b a ) 3
=
12n 2

f " ( )
i =1

The

term

f " (
i =1

i =1
n

n
derivative f " ( x), a < x < b .
Hence
n

is

an

approximate

f " ( i )
(b a ) 3
i =1
Et =
12n 2
n
In Table 4, the approximate value of the integral
30

140000

8 2000 ln 140000 2100t 9.8t dt

average

value

of

the

second

07.02.16

Chapter 07.02

is given as a function of the number of segments. You can visualize that as the number of
segments are doubled, the true error gets approximately quartered.
Table 4 Values obtained using multiple-segment trapezoidal rule for
30

140000

9.8t dt .
x = 2000 ln

140000 2100t

8
Approximate
Value
2 11266
4 11113
8 11074
16 11065
n

Et

t %

a %

-205
-52
-13
-4

1.853
0.4701
0.1175
0.03616

5.343
0.3594
0.03560
0.00401

For example, for the 2-segment trapezoidal rule, the true error is -205, and a quarter of that
error is -51.25. That is close to the true error of -48 for the 4-segment trapezoidal rule.
Can you answer the question why is the true error not exactly -51.25? How does this
information help us in numerical integration? You will find out that this forms the basis of
Romberg integration based on the trapezoidal rule, where we use the argument that true error
gets approximately quartered when the number of segments is doubled. Romberg integration
based on the trapezoidal rule is computationally more efficient than using the trapezoidal rule
by itself in developing an automatic integration scheme.
INTEGRATION
Topic
Trapezoidal Rule
Summary These are textbook notes of trapezoidal rule of integration
Major
General Engineering
Authors
Autar Kaw, Michael Keteltas
Date
January 15, 2012
Web Site http://numericalmethods.eng.usf.edu

You might also like