0% found this document useful (0 votes)
35 views14 pages

Trapezoidal Rule in Numerical Integration

The document discusses numerical integration techniques, focusing on the trapezoidal rule and its derivation, error estimation, and applications. It explains how the trapezoidal rule approximates the area under a curve using linear segments and introduces the concept of multiple applications to improve accuracy. Additionally, it briefly covers Simpson's rule as a more accurate alternative using higher degree polynomials for integration.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views14 pages

Trapezoidal Rule in Numerical Integration

The document discusses numerical integration techniques, focusing on the trapezoidal rule and its derivation, error estimation, and applications. It explains how the trapezoidal rule approximates the area under a curve using linear segments and introduces the concept of multiple applications to improve accuracy. Additionally, it briefly covers Simpson's rule as a more accurate alternative using higher degree polynomials for integration.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

NUMERICAL INTEGRATION

3.1.- MATHEMATICAL FOUNDATIONS

3.2.- TRAPEZOID RULE

The trapezoidal rule is the first of the closed formulas.


of Newton-Cotes integration. It corresponds to the case where
the polynomial of it is of first degree

=∫ ( ) ≅ ∫ 1 ( )

Remember that a straight line can be represented as:


( )− ( )
1 ( )= ( ) + ( − )

The area under this straight line is an approximation of the integral of f(x) between the limits a and b:

( )− ( )
=∫[ ( )+ ( − )]

The result of the integration is
( )+ ( )
=( − )
2
What is known as the trapezoidal rule

Geometrically, the trapezoid rule is equivalent to approximating the area of the trapezoid below the
a straight line that connects f(a) and f(b). Remember that the formula to calculate the area of a trapezoid is
the height multiplied by the average of the bases. In our case, the concept is the same, but the
the trapezoid is on its side (figure 21.5b). Therefore, the approximate integral is represented
how

≅ ℎ ×

≅( − )×

where, for the trapezoid rule, the


average height is the average of the
values of the function at the points
extremes, [ ( ) + ( ) ]/2.

All closed formulas of Newton-


Quotes are expressed in the general form
from the equation. In fact, they only differ
regarding the formulation of height
average
DERIVATION OF THE TRAPEZOIDAL RULE

Before the integration, equation (21.2) can be expressed as


( )− ( ) ( ) − ( )
1( ) = + ( ) −
− −
Grouping the last two terms:
( )− ( ) ( ) − ( ) − ( ) + ( )
1( ) = +
− −

( )− ( ) ( ) − ( )
1( ) = +
− −
Which can be integrated between x=a and x=b to obtain:

( )− ( ) 2 ( ) − ( )
= + |
− 2 −
This result is evaluated to give:
2
( ) − ( )( − )2 (− ) ( )
= + ( − )
− 2 −
Now, like 2− 2= ( − )( + ),
+
=[ ( ) − ( )] + ( ) − ( )
2
Multiplying and grouping terms gives:
( )+ ( )
=( − )
2
What is the formula for the trapezoidal rule?

TRAPEZOIDAL RULE ERROR

When we use the integral under a segment of line


line to approximate the integral under a curve, obviously
there is an error that may be important. An estimate
the local truncation error for a single application of the
trapezoidal rule.

An alternative way to obtain the trapezoidal rule


it consists of integrating the interpolation polynomial towards
in front of Newton-Gregory. Remember that, for the version
of first degree with the term of the error, the integral will be:

´´( )
=∫ [ ( )+ ∆ ( ) + ( ) 2]
− 1ℎ
2
( − )
To simplify the analysis, consider that if = , then =ℎ

Because h = b-a (for a segment of the trapezoidal rule), the limits of integration a and
b correspond to 0 and 1, respectively. Therefore, the equation will be expressed as
1
´´( )
=ℎ∫[ ( )+ ∆ ( ) + ( ) 2]
− 1ℎ
0 2

If it is supposed that, for a small h, the term ´ it is


( approximately
) constant,
then the result of the integration is:
2 2 2
=ℎ[ ( ) + ∆ ( ) +( − ) ´´( ) ℎ2 ]
2 6 4

And evaluated as

Δ ( ) 1
=ℎ [ ( ) + ]− ´´( ) 3ℎ
2 12

How∆ ( )= ( −) ( ,)the result can be written as


( )+ ( ) 1
=ℎ= − ´´( ) 3ℎ
2 12
Thus, the first term is the trapezoidal rule and the second is an approximation for the error.
1 3
= − ´´ ( () − )
12

EXAMPLE OF THE TRAPEZOID RULE

Statement of the problem. With the equation integrate numerically

( ) = 0.2 + 25x- 200 2+ 675x3- 900 4+ 400 5

from a = 0 to b = 0.8. Remember that the exact value of the integral can be determined at
analytical form and is 1.640533.

Solution.
When evaluating the function
(0) = 0.2 + 25x- 200(0)2+ 675(0)3- 900(0)4+ 400(0)5

(0.8) = 0.2 + 25x- 200(0)2+ 675(0.8)3- 900(0.8)4+ 400(0.8)5


(0) = 0.2
(0.8) = 0.232
substituting in the equation
( )+ ( )
=( − )
2
0,2 + 0,232
= (0.8 − 0 ) = 0,1728
2
Which represents an error of = 1.640533– 0.1728 = 1.467733
which corresponds to a relative percentage error of 89.5%
1467733
=| | ∗ 10089.5%
1,640533
The reason for this large error is evident in
the graph of figure 21.6. Note that the area
below the straight line does not take into account one
significant portion of the integral that is about
above the line. In real situations, maybe
we do not previously know the true value.
Therefore, an estimate is required of
approximate error. To obtain this
the estimation calculates the second derivative of the
function in the interval, deriving twice the
original function:

f''(x) = -400+ 4050 – 10800 2+ 8000 3

The average value of the second derivative is calculated using the equation:

∫ 00.8(– 400+ 4050 – 10800 2+ 8000 3)


´´( ) = = -60
0.8 -0
that is substituted in equation (21.6) and the result is
1
= − -60)(0.8)3= 2.56
12
which is of the same order of magnitude and sign as the true error. However, in fact,
There is a discrepancy, as in an interval of this size, the average of the second
derivative is not necessarily an exact approximation of ´´ ( )we indicate that the error
Thus,
it is approximately represented by the notation , and not exactly using .

The multiple application trapezoidal rule One way to improve the accuracy of the rule of
trapezoid consists of dividing the integration interval from a to b into several segments, and applying the
method to each of them (figure 21.7). The areas

THE MULTIPLE APPLICATION TRAPEZOIDAL RULE

One way to improve the accuracy of the trapezoidal rule is to divide the interval of
integration of a or b in several segments, and apply the
method to each of them. The areas of the segments
they are added later to obtain the integral over the entire
interval. The resulting equations are called formulas
of integration, of multiple or composite application.

show the general format and the nomenclature that


we will use to obtain application integrals
multiple. There are n + 1 equally spaced points
( 0, 1, 2, … . , ) . Consequently, there are n
segments of the same width:

ℎ=

If a and b are designated as 0 , respectively, the complete integral will be represented as


1 2
=∫ ( ) + ∫ ( ) + ….+∫ ( )
0 1 +1

By substituting the trapezoidal rule in each integral, one obtains

( )0 + ( 1) ( )1+ ( 2) ( −1)+ ( )
=ℎ +ℎ +⋯+ℎ
2 2 2
Oh, we group terms,
−1

=[ ( 0+) 2 ∑ +( ) ]( )
2
=1

Oh, using the following equation to express the equation in general form of the equation
−1
( )0 + 2 ∑ =1 ( ) + ( )
=( − )
2n

WIDTH AVERAGE HEIGHT

Since the sum of the coefficients of f(x) in the numerator divided by 2n equals 1, the
Average height represents a weighted average of the values of the function. According to
with the equation, the interior points are given double the weight of the two extreme points
( 0) ( )There is an error with the multiple application trapezoidal rule when summing the
individual errors of each segment, like this

( − )3
=− ∑ ´´( )
12n3
=1

Where ´´( ) it is the second derivative at a point located in segment i. This


the result is simplified by estimating the mean or average value of the second derivative over the entire
interval like:

∑ =1 ´´( )
´´ ≅

Therefore, ´´
∑ ( ≅) ´´ and the equation is written as

( − )3
= − ´´
12n2
Thus, if the number of segments is doubled, the truncation error is divided by four.

EXAMPLE OF MULTIPLE APPLICATION TRAPEZOIDAL RULE

Use the trapezoidal rule with two segments to estimate the integral of

( ) = 0.2 + 25x- 200 2+ 675x3- 900 4+ 400 5


from a = 0 to b = 0.8. Use the equation to estimate the error. Remember that the value
the correct value for the integral is 1.640533.

Solution:

n = 2ℎ( = 0,4 : )

( 0=
) 0,2 ; 0,4 ( = 2,456
) ( )
0,8 = 0,232

(
02 + 2 2,456 +) 0,232
= 0,8 = 1,0688
4

= 1,640533− 1,0688 = 0,57173

= 34.9%

0.83
= − ( -60=)0,64
12(2)2

The results of the previous example, along with applications of the trapezoidal rule with three to
ten segments, are summarized in table 21.1. Note how the error decreases as
it increases the number of segments. However, also note that the reason for the decrease
it is gradual, because the error is inversely related to the square of n. Therefore
Thus, by doubling the number of segments, the error is divided by four. In the following
we will develop higher degree formulas that are more accurate and that converge
faster towards the true integral as the segments increase. However, before
to investigate such formulas, we will analyze computational algorithms to implement the
trapezoidal rule.

For individual applications of functions with good behavior, the trapezoidal rule
of multiple segments is almost exact for the type of precision required in various
applications of engineering.

If high accuracy is required, the multiple segment trapezoidal rule demands a large
computational work. Although this work seems insignificant for a single application,
it can be very important when: a) numerous integrals are evaluated, or b) where the function
it is time-consuming in its evaluation. For such cases, perhaps methods may be required
more efficient (they will be analyzed in the remaining part of this chapter and in the next one).

Finally, rounding errors represent a limitation in our ability to


determine integrals. This is due both to the precision of the machine and to the various
calculations involved in simple techniques such as the multiple segment trapezoidal rule.
Now we will analyze a way to improve efficiency. That is, through polynomials of degree
upper bound to approximate the integral.

3.3.- SIMPSON'S RULE

Another way to obtain an estimate


more accurate than an integral consists of
use higher degree polynomials for
connect the dots. For example, if there is another
point halfway between ( ) ( ), the
three points can be joined by a parabola. If there are two equally spaced points in between
( ) ( )the four points can be connected by a third degree polynomial. The
formulas that result from taking the integrals under those polynomials are known as rules of
Simpson.

SIMPSON'S RULE 1 / 3

The Simpson 1/3 rule results when a second-degree interpolation polynomial is


replace in the equation
( )0+ 4f 1(+ ) ( 2)
=( − )
6
WIDTH AVERAGE HEIGHT

where a = x0, b = x2 and x1 = the point halfway between a and b, which is given by (b + a)/2. Observe
that, according to the equation, the midpoint is weighted by two thirds; and the two
extreme points, by a sixth. It can be shown that the application to a single segment of the
Simpson's 1/3 rule has a truncation error of
1 5 ( 4)
=− ℎ ( )
90
Or how h = (b-a) /2,

( − )5 (4 )(
=− )
2880
where ξ is somewhere in the interval from a to b. Thus, the 1/3 Simpson's rule is more accurate
that the trapezoidal rule. Consequently, the Simpson 1/3 rule achieves an accuracy of
third order even when based on only three points. In other words, it gives exact results
for cubic polynomials even when obtained from a parabola

Simple application of Simpson's 1/3 rule

Statement of the problem. With the equation

( ) = 0.2 + 25x- 200 2+ 675x3- 900 4+ 400 5

From a=0 to b=0.8 the exact integral is 1.640533

Solution

( )= . ( . )= . ( . )= .
(
0.2 + 4 2.456 )+ 0.232
= 0.8 = 1.367467
6
What represents an exact error of

= 1.640533− 1.367467 = 0.2730667 = 16.6%


which is approximately 5 times more accurate than a single application of the trapezoidal rule
(0.8) 5
The estimated error is =− ( -2400= )0.2730667
2880
The 1/3 Simpson's Rule of application
multiple

Just like in the trapezoidal rule, the rule of


Simpson improves by dividing the interval of
integration in several segments of a
same size

ℎ=

total integration can be represented as

=∫ ( ) + ∫ ( ) +⋯+∫ ( ) +

By substituting Simpson's 1/3 rule in each integral, one obtains


( )+ ( )+ ( ) ( )+ ( )+ ( ) ( −) + ( − )+ ( )
≅ + +⋯+

By combining terms and using the equation

( ∑ −1
)0+ 4 =1,3,5 ( + )2 ∑
=2,4,6
-2
( )+ ( )
=( − )
3

WIDTH AVERAGE WEIGHT

An estimated error in the multiple application Simpson's rule is obtained in the same way.
that in the trapezoidal rule: by summing the individual errors of the segments and taking out the
average of the derivative to reach

( − ) 5 ̅̅̅̅̅
= − (4)
180 4
where (4) It is the average of the fourth derivative in the interval.

EXAMPLE the Simpson's rule 1/3 of multiple application

( ) = 0.2 + 25x- 200 2+ 675x3- 900 4+ 400 5

From a=0 to b=0.8 the exact integral is 1.640533

Solution n=4 (h=0.2):

( )= . ; ( .) = . ;( ). = . (; ) . = . ; ( . )= .
(
0.2 + 4 1.288 + 3.464 +) 2 2.456+
( )
0.232
= 0.8 = 1,623467
12
What represents an exact error of

= 1.640533− 1.623467 = 0.017067 = 1.04%


(0.8) 5
The estimated error is =− ( -2400= )0.017067
180(4)
The previous example demonstrates that the version of Simpson's Rule 1/3 for multiple applications
gives very precise results. For this
reason is considered better than the rule
of the trapezoid in most of the
applications. However, as it
as indicated before, it is limited to cases
where the values are equidistant.
In addition, it is limited to situations in
those that have an odd number of
segments and an odd number of
points. Consequently, as it
will analyze in the next section, a
formula for odd segments and
even points, known as Simpson's 3/8 rule, is used together with the 1/3 rule to allow
the evaluation of even and odd segment numbers.

Simpson's 3/8 Rule


Similarly to the derivation of the trapezoidal rule and Simpson's 1/3 rule, it is possible to adjust a
third degree Lagrange polynomial at four points and integrate it:

=∫ ( ) =∫ ( )

To obtain ≅ [( ) + ( )+ ( +) ( ])

where h = (b–a)/3. This equation is called the Simpson's 3/8 rule because h is multiplied
for 3/8. This is the third closed integration formula of Newton-Cotes. The 3/8 rule is
express also in the form of the equation
( )0+ 3 ( 1+) 3 ( 2+ ) 3( )
=( − )
8
WIDTH AVERAGE WEIGHT

Thus the two interior points have weights of three eighths, while the extreme points
they have a weight of one eighth. The Simpson 3/8 rule has an error of
3 5 4(
= −ℎ )
80
Oh, how h = (b-a) / 3,

( − )5 4(
= − )
6480 4
Typically, the Simpson's rule is preferred.
1/3, since it reaches a third accuracy
order with three points instead of four
points required in version 3/8. No
however, the 3/8 rule is useful when the
the number of segments is odd.
EXAMPLE Simpson's Rule 3/8

Statement of the problem. a) Using Simpson's 3/8 rule, integrate

( ) = 0.2 + 25x- 200 2+ 675x3- 900 4+ 400 5

From a=0 to b=0.8

Use it together with Simpson's 1/3 rule in order to integrate the same function in five.
segments.

Solution.

a) A single application of Simpson's 3/8 rule requires four equidistant points:

( 0=
) 0.2 ; (0.2667) = 1.432724
( 0.5333=) 3.487177 ; ( 0.8 ) = 0.232
0.2 + 3 (1.432724 +3.487177 + )00.232
= 0.8 = 1,519170
8
= 1.640533− 1.519170 = 0.1213630 7.4%
(0.8) 5
The estimated error is =− ( -2400= )0.01213630
6480

b) the necessary data for an application with five segments (h=0.16) are

(0=) 0.2 ; 0.16 (= 1.296919


) ; ( 0.32 ) =1.743393 ;
( 0.48 ) = 3.186015 ; ( 0.64 ) = 3.181929 0.80=( 0.232
)
The integral for the first two segments is obtained using Simpson's 1/3 rule:
(
0.2 + 4 1.296919 +) 1.743393
= 0.32 = 0.3803237
6
For the last three segments, the 3/8 rule is used to obtain
(
1.743393+ 3 3.186015 )
+ 3.181929 + 0.232
= 0.48 = 1,264754
8
The total integral is calculated by adding the two results:

= 0.3803237 +1.264753= 1,645077


= 1.640533− 1.645077 = −0.00454383
= −0.28%

3.4.- INTEGRATION WITH UNEQUAL INTERVALS

Numerical integration formulas have been based on equally spaced data. In the
in practice, there are many situations where this assumption is not satisfied and there are
segments of unequal sizes. Numerical integration formulas have been based on
equally spaced data. In practice, there are many situations where this
the assumption is not satisfied and segments of unequal sizes are present. One method consists of
apply the trapezoidal rule to each segment and sum the results:
Hasta aquí, todas las fórmulas de integración numérica se han basado en datos igualmente
spaced. In practice, there are many situations where this assumption is not satisfied.
and segments of unequal sizes are obtained. For example, the data obtained
experimentally are often of this type. In such cases, one method consists of applying the
trapezoidal rule for each segment and sum the results:
( )0+ ( 1) ( )1+ ( 2) ( −1)+ ( )
= ℎ1 + ℎ2 +⋯+ℎ
2 2 2
Where h1, h2, h3, hn = the width of segments 1, 2, 3, n respectively. Note that this was the
same procedure that was used in the multiple application trapezoidal rule. The only
The difference between these equations is that the h in the first one are constants. In some
Adjacent segments are of the same width and, consequently, could be evaluated.
through Simpson's rules. This usually leads to more accurate results.

When the length of the subintervals is not equal, a combination of the rule is used.
Trapezoidal and Simpson's rules, aiming to follow the following hierarchical order: When the
the length of the subintervals is not equal, a combination of the Trapezoidal rule and the
Simpson's rules, trying to follow the following hierarchical order:

1.- Simpson 3/8: This applies if we have 4 equally spaced points.


2.- Simpson 1/3: This applies if it fails (1) and we have 3 equally spaced points.
3.- Trapezoidal Rule: It only applies if (1) and (2) are not satisfied.

Trapezoidal rule with unequal segments

Statement of the problem. With the equation, integrate numerically.

( ) = 0.2 + 25x- 200 2+ 675x3- 900 4+ 400 5

With the equation, determine the integral for these data.

Solution. If the equation is applied

( )0+ ( 1) ( )1+ ( 2) ( −1)+ ( )


= ℎ1 + ℎ2 +⋯+ℎ
2 2 2
1.309729 +0.2 1.305241+ 1.309729 0.232 + 2.363
= 0.12 + 0.10 + ⋯ + 0.10
2 2 2
= 0.090584 + 0.130749 + ... +0.12975 = 1.594801
What does an absolute percentage relative error represent? 2.8%
The data from example 21.7 is illustrated in figure 21.14. Note that some segments
adjacent ones are of the same width and, consequently, could be evaluated using the rules
from Simpson. This usually leads to more accurate results, as illustrated by the following
example.

Use of Simpson's rules in the evaluation of irregular data

Problem statement. Recalculate the integral for the data in table 21.3, but
Now use Simpson's rules in those segments where appropriate.

Solution. The first segment is evaluated using the trapezoidal rule:


1.309729 + 0.2
= 0.12 = 0.09058376
2
Since the following two segments that go from x= 0.12 to 0.32 are of equal length, their integral
it is calculated with Simpson's 1/3 rule:
1.743393+ 4(1.305241) + 1.309729
= 0.2 = 0.2758029
6
The following three segments are also equal and can therefore be evaluated with the
Rule 3/8 to obtain I = 0.2726863. Similarly, the 1/3 rule applies to both.
segments from x = 0.44 to 0.64 to give I = 0.6684701. Finally, the last two
segments, which are of different lengths, are evaluated using the trapezoidal rule to give values
from 0.1663479 and 0.1297500, respectively. The area of those individual segments is summed up.
to have a total integral result of 1.603641. This represents an error of et =
2.2%, which is better than the result obtained using the trapezoidal rule in the example.
21.7.

3.5.- OPEN INTEGRATION FORMULAS


the formulas of open integration have limits that extend beyond the interval of the
data. The table summarizes the open integration formulas of Newton-Cotes. The formulas are
they have expressed in the form of the equation (multiple integration) in such a way that the factors of
weighting should be evident. As in the case of closed versions, successive pairs of the
formulas have the same order of error. The formulas for even segments and odd points
are generally the preference methods, as they require fewer points to achieve the
same accuracy as the formulas for odd segments and even points. The open formulas
they are not frequently used for the defined integration.

MULTIPLE INTEGRALS

Multiple integrals are often used in engineering. For example, an equation


A general formula to calculate the average of a bidimensional function can be written as follows:

∫ (∫ ( ,) )
̅ =
( − )( − )
The numerator is called double integral.

The techniques are used to evaluate integrals


multiple. A simple example would be to obtain the
double integral of a function over an area
rectangular

∫(∫ (, ) ) = ∫( ∫ ,( ) )

First, the integral is evaluated in one of the dimensions and the result of this first
integration is incorporated in the second dimension. The equation states that it does not matter the
order of integration. A double numerical integral will be based on the same idea. First, it
they apply methods, such as Simpson's rule or the trapezoidal rule for multiple segments, to the
first dimension keeping the values of the second dimension constant. Then, it
apply the method to integrate the second dimension. The procedure is illustrated in the example
next
Use of the double integral to determine an average temperature.

Problem Statement. Suppose that the temperature on a rectangular plate is


describe using the following function:

( , ) = 2xy + 2x – 2-2y2+ 72
If the plate is 8 m long (dimension x) and 6 m wide (dimension y), calculate the
average temperature.

Solution.

First, the trapezoidal rule will be used with two segments in each dimension. The temperatures
in the necessary x and y values.

Note that a simple average of these values is 47.33. The function is also evaluated
analytically, whose result would be 58.66667.

To numerically perform the same evaluation, the trapezoidal rule is first used to
length of dimension x with each of the values of y.

These values are integrated throughout the dimension to result in a final total of 2,688.

Dividing this by the area yields the average temperature:2688 (6∗8)


= 56.

We can also use Simpson's 1/3 rule in the same way with a single segment.
This integral results in 2,816 and an average of 58.66667, which is exact.

Why does this happen? Remember that Simpson's 1/3 rule gave perfect results with
cubic polynomials. Since the term of the highest degree in the function is of second degree, in the

In this case, the exact same result is obtained. For algebraic functions of degree
superior, as well as with transcendent functions, it will be necessary to employ multiple segments
to obtain exact estimates of the integral.

3.6.- APPLICATIONS. - SOLUTIONS USING SOFTWARE (MATLAB)

You might also like