0% found this document useful (0 votes)
4 views24 pages

W9 - Numerical Integration - Course Notes

The ENG1014 course notes cover numerical integration methods, including the trapezoidal rule and Simpson's rules, which are essential for approximating integrals when exact solutions are difficult or impossible to obtain. The notes explain the purpose of integration in various scientific and engineering contexts, as well as the implementation of these numerical methods for both uniform and non-uniform data segments. Key formulas and pseudocode for the composite trapezoidal method are also provided to facilitate practical application.

Uploaded by

p7sjtjkdvd
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)
4 views24 pages

W9 - Numerical Integration - Course Notes

The ENG1014 course notes cover numerical integration methods, including the trapezoidal rule and Simpson's rules, which are essential for approximating integrals when exact solutions are difficult or impossible to obtain. The notes explain the purpose of integration in various scientific and engineering contexts, as well as the implementation of these numerical methods for both uniform and non-uniform data segments. Key formulas and pseudocode for the composite trapezoidal method are also provided to facilitate practical application.

Uploaded by

p7sjtjkdvd
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
You are on page 1/ 24

ENG1014 Engineering Numerical Analysis Course Notes

ENG1014 Course notes


Week 9. Numerical Integration

WEEK 9. NUMERICAL INTEGRATION ................................................................................................... 1


9.1. INTRODUCTION TO NUMERICAL INTEGRATION ................................................................................................ 2
9.2. TRAPEZOIDAL RULE................................................................................................................................... 3
9.3. SIMPSON’S 1/3 RULE .............................................................................................................................. 11
9.4. SIMPSON’S 3/8 RULE.............................................................................................................................. 16
9.5. INPUT TESTING....................................................................................................................................... 21

Week 9 Overview
Most of you will know that integrating a function between two limits will give you the area
enclosed by the function, the limits, and your independent variable axis. Most of you will also
know how to integrate a range of functions. In many situations, however, you may have to deal
with functions that are extremely difficult or impossible to integrate exactly. In other situations,
as scientists and engineers there may not be a function that describes the area that you need to
determine. In situations like these, you will need numerical integration.

1
ENG1014 Engineering Numerical Analysis Course Notes

9.1. Introduction to Numerical Integration


9.1.1. Introduction to integration
Integrating a function 𝑓(𝑥) with respect to 𝑥 between two limits 𝑎 and 𝑏 gives the area bounded
by the function, the two limits, and the 𝑥-axis. This is illustrated by the shaded region in Figure
9.1, and in general is written as Equation 9.1.

Figure 9.1 – Integration of a function 𝑓(𝑥) between two limits, 𝑎 and 𝑏


𝑏
𝐼 = ∫ 𝑓(𝑥)𝑑𝑥 Equation 9.1
𝑎

Integration is the inverse of differentiation. This means that we can analytically calculate simple
integrations.

For example, we know how to compute the integral of 𝑓(𝑥) = 0.4𝑥 3 − 3𝑥 2 + 2𝑥 + 100:

∫ 𝑓(𝑥) 𝑑𝑥 = ∫ 0.4𝑥 3 − 3𝑥 2 + 2𝑥 + 100 𝑑𝑥


= 0.1𝑥 4 − 𝑥 3 + 𝑥 2 + 100𝑥 + 𝑐

We also know how to compute the definite integral of 𝑓(𝑥) = 0.4𝑥 3 − 3𝑥 2 + 2𝑥 + 100 between
𝑎 and 𝑏:
𝑏 𝑏
𝐼 = ∫ 𝑓(𝑥) 𝑑𝑥 = ∫ 0.4𝑥 3 − 3𝑥 2 + 2𝑥 + 100 𝑑𝑥
𝑎 𝑎
= [0.1𝑥 4 − 𝑥 3 + 𝑥 2 + 100𝑥 + 𝑐]𝑏𝑎
= (0.1𝑏4 − 𝑏3 + 𝑏2 + 100𝑏 + 𝑐 ) − (0.1𝑎4 − 𝑎3 + 𝑎2 + 100𝑎 + 𝑐 )

Note that we use 𝐼 to denote the value of the integral between two bounds.
However, there is not always an analytical solution to the integral we would like to determine.
The function might be complex to solve analytically or there might not be a function that
describes what we are dealing with at all; for example, a set of discrete measurements taken in
an experiment or in the field. This is where numerical integration is useful.

2
ENG1014 Engineering Numerical Analysis Course Notes

9.1.2. What is numerical integration?


Numerical integration provides an approximation of the true integral. It can often be carried out
in a manner that gives an answer that is very close to the true integral. It can be used in situations
where the integral function is not able to be calculated. Numerical integration uses no
additional information beyond the values of 𝑓(𝑥), and no knowledge of the integral function
𝐹(𝑥) = ∫ 𝑓(𝑥) 𝑑𝑥.

9.1.3. Purpose of integration


Integration has numerous uses not just in engineering, but also in all areas of science and
economics. Any situation in which you need to calculate a cumulative total, an area, or a sum
of values over an interval could be solved with integration.
Here are some examples where integration is useful in ENG1014:
𝑏
• 𝒗(𝑡) = ∫ 𝒂(𝑡)𝑑𝑡 and ∆𝒗 = ∫𝑎 𝒂(𝑡)𝑑𝑡 (velocity and acceleration)
𝑏
• 𝒙(𝑡) = ∫ 𝒗(𝑡)𝑑𝑡 and ∆𝒙 = ∫𝑎 𝒗(𝑡)𝑑𝑡 (displacement and velocity)
𝑏
• 𝑊 = |∫𝑎 𝑭(𝒙)𝑑𝒙| (work (or energy), force & displacement)
• 𝑉 = ∫ 𝐴(𝑥, 𝑦)𝑑𝑧 (volume and cross-sectional area)
• 𝐴 = ∫ 𝑙(𝑥)𝑑𝑦 (area and length)
• 𝐸 = ∫ 𝑃(𝑡)𝑑𝑡 (energy, power and time)
• Any other cumulative sum (i.e., the sum of all individual observations over all intervals
that observations are made)

9.1.4. Numerical integration methods


The numerical integration methods covered in ENG1014 are:
• The trapezoidal rule and the composite trapezoidal integration method
• Simpson’s 1/3 rule and the composite Simpson’s 1/3 integration method
• Simpson’s 3/8 rule
These methods can be applied to either:
• a function, 𝑓(𝑥)
• sets of discrete data, {(𝑥𝑖 , 𝑦𝑖 )}

3
ENG1014 Engineering Numerical Analysis Course Notes

9.2. Trapezoidal Rule


9.2.1. Single application of trapezoidal rule
The trapezoidal rule is illustrated with a single trapezium spanning the bounds of the integral
with limits at (𝑎, 𝑓(𝑎)) and (𝑏, 𝑓(𝑏)) , as illustrated in Figure 9.2. The area is a crude
approximation to the area under the function between 𝑎 and 𝑏.

Figure 9.2 – Single trapezoidal segment spanning the integral bounds.


In this case, we have a single trapezoidal segment with width ℎ where ℎ = 𝑏 − 𝑎. The area of the
trapezium, and thus this estimation of our integral, 𝐼, is therefore:

(𝑓(𝑎) + 𝑓(𝑏))
𝐼 = (𝑏 − 𝑎) Equation 9.2
2

Practically, we would almost never use only a single segment for numerical integration; a more
accurate method is to use multiple trapezoids, as discussed in the next section.

9.2.2. Composite trapezoidal rules


Typically, we would never use only a single segment for numerical integration. A better estimate
is given by subdividing the integrand into multiple segments and summing the trapezoidal area
of each segment. Figure 9.3 illustrates this idea, showing the approximate integral as more
segments (or applications of the single trapezoidal rule) are added.

4
ENG1014 Engineering Numerical Analysis Course Notes

Figure 9.3 – Composite trapezoidal integration with increasing number of segments. Successive
estimates of the final integral are shown above each image. One can clearly see that these
converge towards the final value (408) as the number of segments becomes larger.

5
ENG1014 Engineering Numerical Analysis Course Notes

Uniform segments
The composite trapezoidal integration rule for uniform segments of width ℎ simply extends the
approach above by subdividing the integrand into multiple segments of equal width, ℎ.
The simplest case is two trapezoidal segments, as illustrated in Figure 9.4 below. These two
𝑎+𝑏 𝑎+𝑏
trapezoidal segments will share a vertex at ( ,𝑓( )).
2 2

Figure 9.4 – The composite of two trapezia Figure 9.5 – The composite of four trapezia
𝑏−𝑎
Since there are two segments, the width of each segment is ℎ = .
2

The area of the first segment is:



𝐼1 = [𝑓(𝑎) + 𝑓(𝑎 + ℎ)]
2
The area of the second segment is:

𝐼2 = [𝑓(𝑎 + ℎ) + 𝑓(𝑏)]
2
The estimate for the integral is then the sum of these segments:

𝐼 = 𝐼1 + 𝐼2 = [𝑓(𝑎) + 2𝑓(𝑎 + ℎ) + 𝑓(𝑏)]
2
Let’s add another two segments, as illustrated in Figure 9.5 above.
The area of the first segment is:

𝐼1 = [𝑓(𝑎) + 𝑓(𝑎 + ℎ)]
2
The area of the second segment is:

𝐼2 = [𝑓(𝑎 + ℎ) + 𝑓(𝑎 + 2ℎ)]
2

6
ENG1014 Engineering Numerical Analysis Course Notes

The area of the third segment is:



𝐼3 = [𝑓(𝑎 + 2ℎ) + 𝑓(𝑎 + 3ℎ)]
2
The area of the fourth segment is:

𝐼4 = [𝑓(𝑎 + 3ℎ) + 𝑓(𝑏)]
2
The estimate for the integral is then the sum of these four segments:

𝐼 = 𝐼1 + 𝐼2 + 𝐼3 + 𝐼4 = [𝑓(𝑎) + 2𝑓(𝑎 + ℎ) + 2𝑓(𝑎 + 2ℎ) + 2𝑓(𝑎 + 3ℎ) + 𝑓(𝑏)]
2
This lays the foundation for expanding the composite trapezoidal into a generic method. If you
look closely at the above estimations for the integral, you’ll notice a pattern emerging; the
integral is the sum of the end terms 𝑓(𝑎) and 𝑓(𝑏), and 2 times all the other terms in between.

Figure 9.6 – The composite trapezoidal method for uniform segments of width ℎ
If we look at the generic case illustrated in Figure 9.6 above, we can obtain the general form of
the estimate of the integral for 𝑛 points. Note that we have replaced 𝑎 and 𝑏 with 𝑥1 and 𝑥𝑛 ,
respectively, and maintained a uniform width ℎ for all trapezoidal segments:

𝐼= [𝑓(𝑥1 ) + 2𝑓(𝑥2 ) + 2𝑓(𝑥3 ) + ⋯ + 2𝑓(𝑥𝑛−1 ) + 𝑓(𝑥𝑛 )]
2
Thus, the composite trapezoidal rule for uniform segments of width ℎ and 𝑛 points is:

𝑛−1

𝐼 = [𝑓(𝑥1 ) + 2 (∑ 𝑓(𝑥𝑖 )) + 𝑓(𝑥𝑛 )] Equation 9.3
2
𝑖=2

7
ENG1014 Engineering Numerical Analysis Course Notes

Pseudocode for composite trapezoidal method


function 𝑓(𝑥) version
Description:
Calculates an estimation of the integral of 𝑓(𝑥) using the composite trapezoidal rule for
uniform segments.

Arguments: Returns:
• 𝑓: lambda function to be solved • 𝐼: estimated integral
• 𝑎: lower bound of the integral
• 𝑏: upper bound of the integral
• 𝑛: number of points

Algorithm:
1. Create a 1D array for 𝑥𝑖 points so that 𝑓(𝑥𝑖 ) can be calculated.
2. Create a 1D array for 𝑓(𝑥𝑖 ) points, let this be known as 𝑦.
3. Determine the width of each segment, ℎ.
4. Calculate the middle summation, ∑𝑛−1
𝑖=2 𝑦𝑖 .

5. Calculate the integral estimate, 𝐼, according to Equation 9.3.

Complete Steps 1-3 from the W9 – Numerical Integration ENG1014 Module Instructions

Non-uniform segments
The composite trapezoidal integration rule for uniform segments of width ℎ is applied to a
known function, as we can sample that function in any way that we like. However, sometimes,
like in an experiment, we may not be able to have equally spaced data. As such, we will have
non-uniform segments of different widths.
Essentially, the composite trapezoidal rule for non-uniform segments is the summation of every
trapezoidal segment between each pair of adjacent points (𝑥𝑖−1 and 𝑥𝑖 ). Thus, from Equation
9.2, which estimated the integral using a single trapezoidal segment, we can obtain the
composite trapezoidal rule for non-uniform segments and 𝑛 points by replacing 𝑎 and 𝑏 with
𝑥𝑖−1 and 𝑥𝑖 , respectively:
𝑛
𝑥𝑖 − 𝑥𝑖−1
𝐼 = ∑( ) (𝑓(𝑥𝑖−1 ) + 𝑓(𝑥𝑖 )) Equation 9.4
2
𝑖=2

8
ENG1014 Engineering Numerical Analysis Course Notes

Pseudocode for composite trapezoidal method


set of discrete data {(𝑥𝑖 , 𝑦𝑖 )} version
Description:
Calculates an estimation of the integral of {(𝑥𝑖 , 𝑦𝑖 )} using the composite trapezoidal rule for
non-uniform segments.

Arguments: Returns:
• 𝑥: 1D array of discrete 𝑥𝑖 observations • 𝐼: estimated integral
• 𝑦: 1D array of discrete 𝑦𝑖 observations

Algorithm:
1. Calculate the width of each segment, 𝑥𝑖 − 𝑥𝑖−1 , let this be known as ℎ𝑖 .
2. Calculate 𝑓(𝑥𝑖−1 ) + 𝑓(𝑥𝑖 ), let this be known as 𝑏𝑎𝑠𝑒𝑠𝑖 .
3. Calculate the integral estimate, 𝐼, according to Equation 9.4.

Complete Steps 4-5 from the W9 – Numerical Integration ENG1014 Module Instructions

Refer to Examples 1-2 from the W9 – Numerical Integration – Course Notes Examples

9.2.3. Truncation errors of trapezoidal rule


We could see from Figure 9.3 that as the number of segments increases (and the width of the
segments decreases), the difference between the individual trapezia and the actual function
gets smaller. This difference is called the location truncation error, 𝐸𝑇,𝑙𝑜𝑐𝑎𝑙 .

Key Concept – Convergence


As the number of individual segments gets larger, and each individual segment becomes
smaller, the overall estimate of the integral converges towards the true answer. If the
segments become infinitely small, the limit of the total estimate will be the true value for the
integral (as per calculus, where the integral is defined as a “limit as h approaches zero”), and
the local truncation error will approach zero.

The local truncation error is also dependent on the nature of the function, as illustrated in Figure
9.7. A trapezium will give the exact integral when 𝑓(𝑥) is a linear function. Truncation errors start
to appear when the second derivative of the function is non-zero and become worse as the
second and higher order derivatives of the function increase in magnitude.

9
ENG1014 Engineering Numerical Analysis Course Notes

Figure 9.7 – Truncation error is dependent on the nature of the function.

It is possible to show that the truncation error, 𝐸𝑇,𝑙𝑜𝑐𝑎𝑙 , in the trapezoidal rule is:
1
𝐸𝑇,𝑙𝑜𝑐𝑎𝑙 = − 12 𝑓′′(𝜉). ℎ3

where

• 𝜉 is some (unknown) value within the range 𝑎 < 𝜉 < 𝑏, and


• ℎ = 𝑏 − 𝑎 (i.e. the width of the trapezoids used to approximate the shape)

It is sufficient to say that the local truncation error “scales with ℎ3 ”. Mathematically, this is
expressed as 𝐸𝑇,𝑙𝑜𝑐𝑎𝑙 = 𝑂(ℎ3 ), where 𝑂 is “order”. Thus, the statement 𝐸𝑇,𝑙𝑜𝑐𝑎𝑙 = 𝑂(ℎ3 ) should
be interpreted as, “the local truncation error changes as a function of order ℎ 3”.
Note that if a function has a second derivative that is 0, trapezoidal integration methods will
have zero error, i.e., linear functions will be integrated exactly.
The “global” truncation error, 𝐸𝑇,𝑔𝑙𝑜𝑏𝑎𝑙 , over the entire integrand is the sum over all of the
truncation errors. Note that these can be both positive and negative, and so the errors are often
cancellative instead of cumulative. The number of segments also increases based on the value
of ℎ. You do not need to know the derivation for ENG1014, but it is possible to show that:
𝐸𝑇,𝑔𝑙𝑜𝑏𝑎𝑙 = 𝑂(ℎ 2 )

In a similar fashion to the “big-O notation” for computational complexity, discussed in week
7, this analysis will not tell you the absolute value of the error in an integration.
However, because the equation for the local error only contains a ℎ3 term, without any lower
order terms, we can find the factor by which the local error will change if the step size is
changed. The global error can also be approximately found. For example:
• If the step size is halved (i.e. twice as many trapezoids are used), then 𝐸𝑇,𝑙𝑜𝑐𝑎𝑙 will be
1/8 of its original value and 𝐸𝑇,𝑔𝑙𝑜𝑏𝑎𝑙 will be around 1/4 of its original value
• If the step size is tripled, 𝐸𝑇,𝑙𝑜𝑐𝑎𝑙 will be 27 times larger than its original value and
𝐸𝑇,𝑔𝑙𝑜𝑏𝑎𝑙 will be around 9-fold larger.

10
ENG1014 Engineering Numerical Analysis Course Notes

Complete Practice Questions 1-2 from the W9 – Numerical Integration – Course Notes
Practice Questions

You should now be able to answer Part A from W9 – Weekly Quiz

9.3. Simpson’s 1/3 Rule


9.3.1. Single application of Simpson’s 1/3 rule
Simpson’s 1/3 rule is derived from fitting a parabola to three points on a function, 𝑓(𝑥). As with
the trapezoid rule, this is almost never used practically, but is presented in order to build
towards discussion of the composite Simpson’s 1/3 method.
Consider Figure 9.8 below; we can see that three equally space points (𝑥1, 𝑓(𝑥1 )), (𝑥2, 𝑓(𝑥2 )),
and (𝑥3, 𝑓(𝑥3 )), separated by the interval ℎ = 𝑥2 − 𝑥1 = 𝑥3 − 𝑥2, are fitted with a parabola.

Figure 9.8 – Fitting a parabola to a set of three evenly spaced points.


The area under the parabola between 𝑥1 and 𝑥3 is the estimate for the integral of 𝑓(𝑥) from 𝑥1 to
𝑥3. It can be shown that Simpson’s 1/3 rule for uniform segments of width ℎ is:


𝐼= (𝑓(𝑥1 ) + 4𝑓(𝑥2) + 𝑓(𝑥3 )) Equation 9.5
3

9.3.2. Composite Simpson’s 1/3 rule


Uniform segments
Figure 9.8 above shows that fitting a parabola to the three equally spaced points spanning the
integrand from 𝑥1 to 𝑥3 gives a very poor estimate of the integral, and that the truncation error
will be very large in this case.
We noticed earlier, with the composite trapezoidal integration rule, that increasing the number
of trapezia decreased the truncation error. If we apply this same treatment to parabolas, as we
have in Figure 9.9, we can see how rapidly the truncation error diminishes.

11
ENG1014 Engineering Numerical Analysis Course Notes

Figure 9.9 – Composite Simpson’s 1/3 rule with increasing number of segments

12
ENG1014 Engineering Numerical Analysis Course Notes

Consider the case of two parabolas, as shown in Figure 9.10, where we have five equally spaced
points where we sample the function 𝑓(𝑥). These points are (𝑥1 , 𝑓(𝑥1)), (𝑥2, 𝑓(𝑥2 )), (𝑥3 , 𝑓(𝑥3 ))
for the first parabola, and (𝑥3 , 𝑓(𝑥3)), (𝑥4 , 𝑓(𝑥4)), and (𝑥5 , 𝑓(𝑥5)) for the second parabola. Note
that (𝑥3 , 𝑓(𝑥3)) is considered twice in determining both parabolas.

Figure 9.10 – Fitting 2 parabolas to 5 equally spaced points


The area under the first parabola is:

(𝑓(𝑥1 ) + 4𝑓(𝑥2 ) + 𝑓(𝑥3 ))
𝐼1 =
3
The area under the second parabola is:

𝐼2 = (𝑓(𝑥3 ) + 4𝑓(𝑥4 ) + 𝑓(𝑥5 ))
3
Our estimate for the integral in the case of two parabolas is therefore:

𝐼 = 𝐼1 + 𝐼2 = [𝑓(𝑥1 ) + 4𝑓(𝑥2 ) + 2𝑓(𝑥3) + 4𝑓(𝑥4) + 𝑓(𝑥5 )]
3

Figure 9.11 – Fitting 3 parabolas to 7 equally spaced points.

13
ENG1014 Engineering Numerical Analysis Course Notes

Consider the case of three parabolas, as shown in Figure 9.11, where we have seven equally
spaced points where we sample the function 𝑓(𝑥). These points are (𝑥1 , 𝑓(𝑥1)), (𝑥2, 𝑓(𝑥2 )),
(𝑥3 , 𝑓(𝑥3 )) for the first parabola, (𝑥3 , 𝑓(𝑥3)) , (𝑥4 , 𝑓(𝑥4)) , and (𝑥5 , 𝑓(𝑥5 )) for the second
parabola, and (𝑥5 , 𝑓(𝑥5 )) , (𝑥6 , 𝑓(𝑥6 )) , and (𝑥7 , 𝑓(𝑥7 )) for the third parabola. Note that
(𝑥3, 𝑓(𝑥3 )) is considered twice in determining the first two parabolas, and (𝑥5 , 𝑓(𝑥5 )) is
considered twice in determining the second and third parabolas.
Our estimate of the integral for the case of three parabolas is therefore:

[𝑓(𝑥1 ) + 4𝑓(𝑥2 ) + 2𝑓(𝑥3) + 4𝑓(𝑥4) + 2𝑓(𝑥5) + 4𝑓(𝑥6 ) + 𝑓(𝑥7)]
𝐼 = 𝐼1 + 𝐼2 + 𝐼3 =
3
We can see from this that there is a general pattern emerging as illustrated in Figure 9.12.

Figure 9.12 – Pattern manifested in composite Simpson’s 1/3 method.


Thus, the composite Simpson’s 1/3 rule for uniform segments of width ℎ and 𝑛 points is:

𝑛−1 𝑛−2

𝐼 = 𝑓(𝑥1 ) + 4 ( ∑ 𝑓(𝑥𝑖 )) + 2 ∑ 𝑓(𝑥𝑗 ) + 𝑓(𝑥𝑛 ) Equation 9.6
3
𝑖=2 𝑗=3
[ 𝑖 𝑖𝑠 𝑒𝑣𝑒𝑛 ]
(𝑗 𝑖𝑠 𝑜𝑑𝑑 )
There are some conditions that apply:

• To fit a parabola, three points are needed. That means that the smallest number of
points for this method to work is three, or a minimum of two segments of equal width.
• Using the composite approach, where at least two parabolas are fitted, the point
between any two neighbouring parabolas is shared between them. Thus, the number of
points with increasing number of parabolas is 3, 5,7... The composite approach will
only work with an odd number of points (and thus an even number of segments).

14
ENG1014 Engineering Numerical Analysis Course Notes

Pseudocode for composite Simpson’s 1/3 method


function 𝑓(𝑥) version
Description:
Calculates an estimation of the integral of 𝑓(𝑥) using the composite Simpson’s 1/3 rule.

Arguments: Returns:
• 𝑓: lambda function to be solved • 𝐼: estimated integral
• 𝑎: lower bound of the integral
• 𝑏: upper bound of the integral
• 𝑛: number of points

Algorithm:
1. Create a 1D array for 𝑥𝑖 points so that 𝑓(𝑥𝑖 ) can be calculated
2. Create a 1D array for 𝑓(𝑥𝑖 ) points, let this be known as 𝑦
3. Determine the width of each segment, ℎ
4. Calculate the even summation, ∑𝑛−1 𝑛−2
𝑖=2 𝑦𝑖 and odd summation, ∑ 𝑗=3 𝑦𝑗
𝑖,even 𝑗,odd

5. Calculate the integral estimate, 𝐼, according to Equation 9.6.

Pseudocode for composite Simpson’s 1/3 method


set of discrete data {(𝑥𝑖 , 𝑦𝑖 )} version
Description:
Calculates an estimation of the integral of {(𝑥𝑖 , 𝑦𝑖 )} using the composite Simpson’s 1/3 rule.

Arguments: Returns:
• 𝑥: 1D array of discrete 𝑥𝑖 observations • 𝐼: estimated integral
• 𝑦: 1D array of discrete 𝑦𝑖 observations

Algorithm:
1. Determine the width of each segment, ℎ
2. Calculate the even summation, ∑𝑛−1 𝑛−2
𝑖=2 𝑦𝑖 and odd summation, ∑ 𝑗=3 𝑦𝑗
𝑖,even 𝑗,odd

3. Calculate the integral estimate, 𝐼, according to Equation 9.6.

Complete Steps 6-9 from the W9 – Numerical Integration ENG1014 Module Instructions

15
ENG1014 Engineering Numerical Analysis Course Notes

Non-uniform segments
It becomes computationally cumbersome to implement the fitting of parabolas to unevenly
spaced points. It is theoretically possible, but the mathematics becomes much more
complicated and the expressions for the area between each parabola and the independent
variable axis do not simplify to something as concise as Equation 9.6 above. Thus, we do not
generally consider a composite Simpson’s 1/3 rule for unevenly spaced points (unlike the
composite trapezoidal method).

Refer to Examples 3-4 from the W9 – Numerical Integration – Course Notes Examples

9.3.3. Truncation errors of Simpson’s 1/3 rule


As we saw in Figure 9.9, as the number of segments increases (and the width of the segments
decreases), the difference between the composite parabolas and the actual function gets
smaller quite rapidly.
It is possible to show that the truncation error for the Simpson’s 1/3 rule is:
1
𝐸𝑇,𝑙𝑜𝑐𝑎𝑙 = − 90 𝑓 (4) (𝜉). ℎ5

where 𝜉 is somewhere in the integrand and 𝑓 (4) is the 4th derivative of the function. In other
words:

𝐸𝑇,𝑙𝑜𝑐𝑎𝑙 = 𝑂(ℎ5 )
It can also be shown that:
𝐸𝑇,𝑔𝑙𝑜𝑏𝑎𝑙 = 𝑂(ℎ4 ).

Note that if a function has a fourth derivative that is 0, Simpson’s 1/3 methods will have no error.
In other words, cubic functions (and polynomials of lower order) will be integrated exactly.

Complete Practice Questions 3-4 from the W9 – Numerical Integration – Course Notes
Practice Questions

You should now be able to answer Part B from W9 – Weekly Quiz

16
ENG1014 Engineering Numerical Analysis Course Notes

9.4. Simpson’s 3/8 Rule


9.4.1. Single application of Simpson’s 3/8 rule
Simpson’s 3/8 rule is derived from fitting a cubic function to four points on a function, 𝑓(𝑥).

Figure 9.13 – Fitting a cubic function to a set of four evenly spaced points.
Consider Figure 9.13; we can see that three equally spaced points (𝑥1, 𝑓(𝑥1 )), (𝑥2, 𝑓(𝑥2 )),
(𝑥3 , 𝑓(𝑥3 )) , and (𝑥4 , 𝑓(𝑥4 )) , separated by the interval ℎ = 𝑥2 − 𝑥1 = 𝑥3 − 𝑥2 = 𝑥4 − 𝑥3 , are
fitted with a cubic function. The area under the cubic between 𝑥1 and 𝑥4 is the estimate, 𝐼, of the
integral of 𝑓(𝑥) from 𝑥1 to 𝑥4.
It can be shown that Simpson’s 3/8 rule for uniform segments of width ℎ is:

3ℎ
𝐼= (𝑓(𝑥1 ) + 3𝑓(𝑥2 ) + 3𝑓(𝑥3 ) + 𝑓(𝑥4 )) Equation 9.7
8

Refer to Examples 5-6 from the W9 – Numerical Integration – Course Notes Examples

17
ENG1014 Engineering Numerical Analysis Course Notes

9.4.2. Composite Simpson’s 3/8 rule


Uniform segments
Figure 9.14 below shows the process of concatenating Simpson’s 3/8 rule to produce the
composite Simpson’s 3/8 rule.

Figure 9.14 – Composite Simpson’s 3/8 rule with five applications of the Simpson’s 3/8 rule
We can see from Figure 9.15 that a pattern emerges, as was the case for the composite
Simpson’s 1/3 method. Thus, we can apply the same process as we did earlier; we can sum the
overlapping coefficients for each application of Simpson’s 3/8 rule for each of the concatenated
cubic functions to obtain an estimate for the integral.

Figure 9.15 – Pattern emerging from composite Simpson’s 3/8 method.

18
ENG1014 Engineering Numerical Analysis Course Notes

The composite Simpson’s 3/8 rule for equal segments of width ℎ is:
𝑛−2 𝑛−1 𝑛−3
3ℎ
𝐼= [𝑓(𝑥1 ) + 3 ( ∑ 𝑓(𝑥𝑖 )) + 3 ( ∑ 𝑓(𝑥𝑖 )) + 2 ( ∑ 𝑓(𝑥𝑖 )) + 𝑓(𝑥𝑛 )]
8
𝑖=2,5,8,… 𝑖=3,6,9,… 𝑖=4,7,10,…

Equation 9.8
There are some conditions that apply:
• To fit a cubic, four points are required. Thus, the smallest number of points required for
this method is four, which corresponds to three segments of equal width.
• Using the composite approach, where at least two cubic functions are fitted, the point
between any two neighbouring cubic functions is shared between them. Thus, the
number of points with increasing number of cubic functions is 4, 7, 10, etc. The
composite approach will only work when the number of points minus 1 is a multiple of
3, i.e., the number of segments is a multiple of 3.

Non-uniform segments
It is computationally fiendish to implement the fitting of cubic functions to non-uniform
segments. It can be done, but the mathematics becomes much more complicated and the
expressions for the area between each cubic function and the independent variable axis do not
simplify to something as concise as Equation 9.8. Thus, in ENG1014, we do not consider a
composite Simpson’s 3/8 rule for non-uniform segments.

9.4.3. Truncation errors of Simpson’s 3/8 rule


It can be shown that for the Simpson’s 3/8 rule:
3
𝐸𝑇,𝑙𝑜𝑐𝑎𝑙 ≅ − 80 𝑓 (4) (𝜉). ℎ5 where 𝑥1 < 𝜉 < 𝑥4

i.e.,
𝐸𝑇,𝑙𝑜𝑐𝑎𝑙 = 𝑂(ℎ5 ).
It can also be shown that:
𝐸𝑇,𝑔𝑙𝑜𝑏𝑎𝑙 = 𝑂(ℎ4 ).
The local truncation error changes as a function of order ℎ5 , and the global truncation error
changes as a function of order ℎ4, just like for the Simpson’s 1/3 rule. In other words, nothing is
gained from Simpson’s 3/8 rule over the 1/3 rule with regard to truncation error. It is worth noting
that both methods will also integrate cubic functions exactly.

19
ENG1014 Engineering Numerical Analysis Course Notes

9.4.4. Usefulness of the Simpson’s 3/8 rule


As we’ve just seen, Simpson’s 3/8 offers little advantage over Simpson’s 1/3 rule regarding error
reduction and is restricted to multiples of three segments. However, it is for this second reason
that it can prove useful. Simpson’s 1/3 rule was restricted to an even number of segments. Thus,
if we have an odd number of segments, composite Simpson’s 1/3 rule can be used with a single
application of Simpson’s 3/8 rule at the end. This is illustrated in Figure 9.16 below.

Figure 9.16 – Composite Simpson’s 1/3 rule combined with Simpson’s 3/8 rule to integrate
over 9 segments (10 points)

As a result of all the above, we will usually only apply a single application of Simpson’s 3/8 rule.
It will be used where we have a discrete datasets {(𝑥𝑖 , 𝑦𝑖 )} with four datapoints – either:
• There is only four datapoints in the entire set, or
• There is an even number of points in the dataset and we wish to combine Simpson’s 3/8
with Simpson’s 1/3 due to the reduced size of the expected error.

20
ENG1014 Engineering Numerical Analysis Course Notes

Pseudocode for Simpson’s 3/8 method


function 𝑓(𝑥) version
Description:
Calculates an estimation of the integral of 𝑓(𝑥) using a single application of Simpson’s 3/8
rule.

Arguments: Returns:
• 𝑓: lambda function to be solved • 𝐼: estimated integral
• 𝑎: lower bound of the integral
• 𝑏: upper bound of the integral

Algorithm:
1. Create a 1D array for 𝑥𝑖 points so that 𝑓(𝑥𝑖 ) can be calculated
2. Create a 1D array for 𝑓(𝑥𝑖 ) points, let this be known as 𝑦
3. Determine the width of each segment, ℎ
4. Calculate the integral estimate, 𝐼, according to Equation 9.7.

Pseudocode for Simpson’s 3/8 method


set of discrete data {(𝑥𝑖 , 𝑦𝑖 )} version
Description:
Calculates an estimation of the integral of {(𝑥𝑖 , 𝑦𝑖 )} using a single application of Simpson’s
3/8 rule.

Arguments: Returns:
• 𝑥: 1D array of discrete 𝑥𝑖 observations • 𝐼: estimated integral
• 𝑦: 1D array of discrete 𝑦𝑖 observations

Algorithm:
1. Determine the width of each segment, ℎ
2. Calculate the integral estimate, 𝐼, according to Equation 9.7.

Complete Steps 10-13 from the W9 – Numerical Integration ENG1014 Module Instructions

Refer to Example 7 from the W9 – Numerical Integration – Course Notes Examples

21
ENG1014 Engineering Numerical Analysis Course Notes

Complete Practice Questions 5-8 from the W9 – Numerical Integration – Course Notes
Practice Questions

You should now be able to answer Part C from W9 – Weekly Quiz

9.5. Input Testing


Now that we know the three numerical integration methods covered in ENG1014, we can add
input validation tests to each method.
The input validation tests can be split into the two applications (a function, 𝑓(𝑥), and sets of
discrete data, {(𝑥𝑖 , 𝑦𝑖 )}) of these methods.

9.5.1. Application 1: a function


All numerical integration methods when used to estimate the integral of a function have the
same three arguments: 𝑓, the lambda function to be solved, 𝑥𝑙 , the lower bound of the integral,
and 𝑥𝑢 , the upper bound of the integral. As 𝑥𝑙 is the lower bound of the integral and 𝑥𝑢 the upper
bound, all three methods require that 𝑥𝑙 < 𝑥𝑢 .
Additionally, both the composite trapezoidal and composite Simpson’s 1/3 methods have a
fourth argument, 𝑛, the number of points. The composite trapezoidal method requires a
minimum of 2 points. As discussed in 0.
Composite Simpson’s 1/3 rule, composite Simpson’s 1/3 requires a minimum of 3 points and
an odd number of points. As Simpson’s 3/8 method is just the single application of the rule, the
number of points does not need to be checked as the number of points is implemented within
the method.

Input testing for numerical integration - function 𝒇(𝒙) version


Before step 1 of each method, check the following conditions. If they are true, continue. If they
are false, raise an error.
All methods:
• 𝑎<𝑏
Composite trapezoidal method:
• Number of points is greater than or equal to 2
Composite Simpson’s 1/3 method:
• Number of points is greater than or equal to 3
• Number of points is odd

Complete Step 14 from the W9 – Numerical Integration ENG1014 Module Instructions

22
ENG1014 Engineering Numerical Analysis Course Notes

9.5.2. Application 2: set of discrete data


All numerical integration methods when used to estimate the integral of a function have the
same two arguments: 𝑥𝑖 , the 1D array of discrete 𝑥𝑖 observations, and 𝑦𝑖 , the 1D array of
discrete 𝑦𝑖 observations. Obvious input requirements are that both 𝑥𝑖 and 𝑦𝑖 are 1D and that 𝑥𝑖
and 𝑦𝑖 have the same number of points.
Similarly to their function versions, both the composite trapezoidal and composite Simpson’s
1/3 methods have requirements related to their number of points. The only difference is that the
number of points is not provided as a separate argument and must be determine from 𝑥𝑖 and 𝑦𝑖 .
However, as the set of discrete data version of Simpson’s 3/8 method does not implement the
number of points, the number of points must be checked to ensure that it is 4.
The composite Simpson’s 1/3 and Simpson’s 3/8 methods have one more requirement. In both
0.
Composite Simpson’s 1/3 rule and 0.

Refer to Examples 5-6 from the W9 – Numerical Integration – Course Notes Examples

23
ENG1014 Engineering Numerical Analysis Course Notes

Composite Simpson’s 3/8 rule, we discussed that these methods can only be used with uniform
segments. Thus, another input validation test needs to be added that checks that 𝑥𝑖 is evenly
spaced.

Input testing for numerical integration - set of discrete data {(𝒙𝒊, 𝒚𝒊 )} version
Before step 1 of each method, check the following conditions. If they are true, continue. If they
are false, raise an error.
All methods:
• 𝑥𝑖 is 1D
• 𝑦𝑖 is 1D
• 𝑥𝑖 and 𝑦𝑖 have the same number of points
Composite trapezoidal method:
• Number of points is greater than or equal to 2
Composite Simpson’s 1/3 method:
• Number of points is greater than or equal to 3
• Number of points is odd
• Segments are uniform
Simpson’s 3/8 method:
• Number of points is 4
• Segments are uniform

Complete Steps 15-16 from the W9 – Numerical Integration ENG1014 Module Instructions

24

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy