You are on page 1of 54

Numerical Analysis 0905201

Numerical Integration

Eng. Mohammad Al Nairat & Eng. Mohammad Al Musleh

1
Numerical Analysis 0905201
Chapter 21

Newton Cotes Formulas


2
Introduction

Using numerical integration techniques is quite useful in the following cases:

1- Complex integrand function.

2- Integration of tabulated data.

3- Integration of data with unequaled spaces.


Introduction
- Graphically, the integration for a function is the area beneath the curve.

- Newton Cotes formulas transform the integrand into an approximate


polynomial.

- Newton Cotes formulas deals only with definite integrals.


1- Trapezoidal Rule
- The function will be dealt with as a trapezoid.

𝑆𝑡𝑒𝑝 𝑠𝑖𝑧𝑒 ℎ = 𝑏 − 𝑎
1- Trapezoidal Rule
- True error 𝐸𝑡 = 𝑇𝑟𝑢𝑒 𝑣𝑎𝑙𝑢𝑒 𝐼𝑡 − 𝐴𝑝𝑝𝑟𝑜𝑥𝑖𝑚𝑎𝑡𝑒 𝑣𝑎𝑙𝑢𝑒 𝐼

𝐼𝑡 −𝐼
- Relative true error 𝜀𝑡 = . 100 %
𝐼𝑡

- The local truncation error:


Example
0.5 𝑥
- Using the trapezoidal rule, estimate the value of ‫׬‬0 𝑒 𝑑𝑥 , given that

𝐼𝑡 = 0.6487 and 𝑓′′ = 1.2974


Solution
0.5 𝑥
𝐼= ‫׬‬0 𝑒 𝑑𝑥

𝑓 𝑎 +𝑓 𝑏
𝐼 ≅ 𝑏−𝑎
2

𝑓 0 + 𝑓 0.5
𝐼 ≅ 0.5 − 0
2
1 + 1.6487
𝐼 ≅ 0.5 − 0
2
𝐼 ≅ 0.6621
Solution
𝐼 ≅ 0.6621 , 𝐼𝑡 = 0.6487

True error 𝐸𝑡 = 𝐼𝑡 − 𝐼 = 0.6487 − 0.6621 = −0.0134

𝐼𝑡 −𝐼 0.6487 −0.6621
Relative true error 𝜀𝑡 = . 100 % = . 100 %
𝐼𝑡 0.6487

𝜀𝑡 = 2.06 %

1
The local truncation error 𝐸𝑎 = − 𝑏 − 𝑎 3 𝑓′′
12

1 3
𝐸𝑎 = − 0.5 − 0 1.2974 = −0.0135
12
2- Simpson’s 1/3 Rule
This rule is derived from a 2nd order Lagrange interpolating polynomial.
Basically, this rule uses a parabola of 3 points to approximate the integrand.

𝐼 = න 𝑓 𝑥 𝑑𝑥
𝑎


𝐼≅ 𝑓0 + 4𝑓1 + 𝑓2
3
𝑏−𝑎
Where the step size ℎ =
2
2- Simpson’s 1/3 Rule
- True error 𝐸𝑡 = 𝑇𝑟𝑢𝑒 𝑣𝑎𝑙𝑢𝑒 𝐼𝑡 − 𝐴𝑝𝑝𝑟𝑜𝑥𝑖𝑚𝑎𝑡𝑒 𝑣𝑎𝑙𝑢𝑒 𝐼

𝐼𝑡 −𝐼
- Relative true error 𝜀𝑡 = . 100 %
𝐼𝑡

- The local truncation error:


Example
0.5 𝑥
- Using the Simpson’s rule, estimate the value of ‫׬‬0 𝑒 𝑑𝑥 , given that 𝐼𝑡
= 0.6487
Solution
0.5 𝑥
𝐼= ‫׬‬0 𝑒 𝑑𝑥

𝑏 − 𝑎 0.5 − 0
ℎ= = = 0.25
2 2

𝑥0 = 0 ⇒ 𝑓0 = 𝑓 0 = 1
𝑥1 = 0.25 ⇒ 𝑓1 = 𝑓 0.25 = 1.2840
𝑥2 = 0.5 ⇒ 𝑓2 = 𝑓 0.5 = 1.6487
Solution
ℎ = 0.25
𝑓0 = 1
𝑓1 = 1.2840
𝑓2 = 1.6487


𝐼≅ 𝑓0 + 4𝑓1 + 𝑓2
3

0.25
𝐼≅ 1 + 4(1.2840) + 1.6487
3
𝐼 ≅ 0.6487
Solution
𝐼 ≅ 0.6487 , 𝐼𝑡 = 0.6487

True error 𝐸𝑡 = 𝐼𝑡 − 𝐼 = 0.6487 − 0.6487 = 0

𝐼𝑡 −𝐼 0.6487 −0.6487
Relative true error 𝜀𝑡 = . 100 % = . 100 %
𝐼𝑡 0.6487

𝜀𝑡 = 0 %

Which means that the Simpson’s rule is more accurate than the trapezoidal rule.
3- Simpson’s 3/8 Rule
This rule is derived from a 3rd order Lagrange interpolating polynomial.
Basically, this rule uses a cubic of 4 points to approximate the integrand.

𝐼 = න 𝑓 𝑥 𝑑𝑥
𝑎

3ℎ
𝐼≅ 𝑓0 + 3𝑓1 + 3𝑓2 + 𝑓3
8
𝑏−𝑎
Where the step size ℎ =
3
Example
Consider the following table of data points:
X 0 2 4 6 8 10 12
Y 0 1.9 2 2 2.4 2.6 2.8

12 3
Find the value of ‫׬‬0 𝑓(𝑥) 𝑑𝑥 2.5

2
Using the trapezoidal, Simpson’s 1.5

1
1/3 and 3/8 rules.
0.5

0
0 2 4 6 8 10 12 14
X 0 2 4 6 8 10 12
Solution Y 0 1.9 2 2 2.4 2.6 2.8
𝑓 𝑎 +𝑓 𝑏 𝑓 0 +𝑓 12
1- Trapezoidal Rule : 𝐼 ≅ 𝑏 − 𝑎 = 12 − 0 = 16.8
2 2

2- Simpson’s 1/3 rule: 𝐼 ≅ 𝑓0 + 4𝑓1 + 𝑓2
3
𝑏 − 𝑎 12 − 0
ℎ= = =6 𝑥0 = 0 , 𝑥1 = 6 , 𝑥2 = 12
2 2
6
𝐼≅ 𝑓 0 + 4𝑓 6 + 𝑓 12 = 21.6
3
3ℎ
3- Simpson’s 3/8 rule: 𝐼 ≅ 𝑓0 + 3𝑓1 + 3𝑓2 + 𝑓3
8
𝑏−𝑎 12−0
ℎ= = =4 𝑥0 = 0 , 𝑥1 = 4 , 𝑥2 = 8 , 𝑥3 = 12
3 3
3∗4
𝐼≅ 𝑓(0) + 3𝑓(4) + 3𝑓(8) + 𝑓(12 = 24
8
Romberg Integration
- It uses the trapezoidal rule, but much more efficient results are obtained
through iterative refinement techniques.

For the special case of interval being halved (h2=h1/2), we get:


Integration With Unequal Segments
Integration With Unequal Segments
Integration With Unequal Segments

- There may be cases where the spacing between data points may not be even
(e.g., experimental data points).

- The best technique to use in this case is to use Simpson’s 1/3 rule wherever
two consecutive equal-sized segments are encountered, and use 3/8 rule
wherever three consecutive equal-sized segments are encountered. And when
adjacent segments are unequal-sized , just use trapezoidal rule. Finally, the
total value of the approximate integration is the sum of all these integrations.
Integration With Unequal Segments
Example
Consider the following table of data points:
X 0 0.12 0.22 0.32 0.33 0.34 0.35 0.40
Y 0 1.9 2 2 2.4 2.6 2.8 3.0

Using numerical integration techniques, approximate the value of the


integration from 𝑥 = 0 to 𝑥 = 0.40
Solution
X 0 0.12 0.22 0.32 0.33 0.34 0.35 0.40
Y 0 1.9 2 2 2.4 2.6 2.8 3.0

𝐼 ≅ 𝐼1 + 𝐼2 + 𝐼3 + 𝐼4

0.12 0.32 0.35 0.40


𝐼≅ න 𝑓 𝑥 𝑑𝑥 + න 𝑓 𝑥 𝑑𝑥 + න 𝑓 𝑥 𝑑𝑥 + න 𝑓 𝑥 𝑑𝑥
0 0.12 0.32 0.35

𝑓 𝑎 +𝑓 𝑏 𝑓 0 + 𝑓 0.12
𝐼1 ≅ 𝑏 − 𝑎 = 0.12 − 0 = 0.114
2 2
ℎ 0.1
𝐼2 ≅ 𝑓0 + 4𝑓1 + 𝑓2 = 𝑓 0.12 + 4𝑓 0.22 + 𝑓 0.32 = 0.396
3 3
Solution
X 0 0.12 0.22 0.32 0.33 0.34 0.35 0.40
Y 0 1.9 2 2 2.4 2.6 2.8 3.0

𝐼 ≅ 𝐼1 + 𝐼2 + 𝐼3 + 𝐼4

0.12 0.32 0.35 0.40


𝐼≅ න 𝑓 𝑥 𝑑𝑥 + න 𝑓 𝑥 𝑑𝑥 + න 𝑓 𝑥 𝑑𝑥 + න 𝑓 𝑥 𝑑𝑥
0 0.12 0.32 0.35
3ℎ
𝐼3 ≅ 𝑓0 + 3𝑓1 + 3𝑓2 + 𝑓3
8
3 0.01
= 𝑓 0.32 + 3𝑓 0.33 + 3𝑓 0.34 + 𝑓 0.35 = 0.074
8

𝑓 𝑎 +𝑓 𝑏 𝑓 0.35 + 𝑓 0.40
𝐼4 ≅ 𝑏 − 𝑎 = 0.40 − 0.35 = 0.145
2 2
Solution
X 0 0.12 0.22 0.32 0.33 0.34 0.35 0.40
Y 0 1.9 2 2 2.4 2.6 2.8 3.0

𝐼 ≅ 𝐼1 + 𝐼2 + 𝐼3 + 𝐼4
𝐼 ≅ 0.114 + 0.396 + 0.074 + 0.145
𝐼 ≅ 0.729
Composite Trapezoidal Rule
To make the trapezoidal rule more effective and accurate, we divide the area
under the curve into multiple “segments” instead of only one.

𝒙𝟎 𝒙𝟏 𝒙𝟐 𝒙𝟑 𝒙𝟒
Composite Trapezoidal Rule

𝑥4
𝐼 = න 𝑓 𝑥 𝑑𝑥
𝑥0

𝑥1 𝑥2
𝐼 ≅ න 𝑓 𝑥 𝑑𝑥 + න 𝑓 𝑥 𝑑𝑥
𝑥0 𝑥1

𝒙𝟎 𝒙𝟏 𝒙𝟐 𝒙𝟑 𝒙𝟒
𝑥3 𝑥4
+ න 𝑓 𝑥 𝑑𝑥 + න 𝑓 𝑥 𝑑𝑥
𝑥2 𝑥3

𝑓 𝑎 +𝑓 𝑏
Trapezoidal Rule: 𝐼 ≅ 𝑏 − 𝑎
2
𝑓 𝑎 +𝑓 𝑏
Composite Trapezoidal Rule Trapezoidal Rule: 𝐼 ≅ 𝑏 − 𝑎
2

𝑥1 𝑥2 𝑥3 𝑥4
𝐼 ≅ න 𝑓 𝑥 𝑑𝑥 + න 𝑓 𝑥 𝑑𝑥 + න 𝑓 𝑥 𝑑𝑥 + න 𝑓 𝑥 𝑑𝑥
𝑥0 𝑥1 𝑥2 𝑥3

𝑓 𝑥0 + 𝑓 𝑥1 𝑓 𝑥1 + 𝑓 𝑥2
≅ 𝑥1 − 𝑥0 + 𝑥2 − 𝑥1
2 2

𝑓 𝑥2 + 𝑓 𝑥3 𝑓 𝑥3 + 𝑓(𝑥4 )
+ 𝑥3 − 𝑥2 + 𝑥4 − 𝑥3
2 2
𝑓 𝑎 +𝑓 𝑏
Composite Trapezoidal Rule Trapezoidal Rule: 𝐼 ≅ 𝑏 − 𝑎
2

𝑓 𝑥0 + 𝑓 𝑥1 𝑓 𝑥1 + 𝑓 𝑥2 𝑓 𝑥2 + 𝑓 𝑥3
≅ ℎ + ℎ + ℎ
2 2 2

𝑓 𝑥3 + 𝑓(𝑥4 )
+ ℎ
2


≅ 𝑓 𝑥0 + 𝑓 𝑥1 + 𝑓 𝑥1 + 𝑓 𝑥2 + 𝑓 𝑥2 + 𝑓 𝑥3
2
+ 𝑓 𝑥3 + 𝑓(𝑥4 )
Composite Trapezoidal Rule

𝑏 𝑛−1

න 𝑓 𝑥 𝑑𝑥 ≅ 𝑓 𝑎 +2 ෍ 𝑓(𝑥𝑖 ) + 𝑓(𝑏)
𝑎 2
𝑖=1

𝑏−𝑎
Where the step size ℎ =
𝑛

𝑛: 𝑡ℎ𝑒 𝑛𝑢𝑚𝑏𝑒𝑟 𝑜𝑓 𝑠𝑒𝑔𝑚𝑒𝑛𝑡𝑠

Note: for n segments, n+1 points are required.


Example
Use the composite trapezoidal rule to approximate the following
integration using 4 segments.

2
1
න dx
1 𝑥

Given that 𝐼𝑡 = 0.6931, calculate the true error and the relative true
error.
1
Solution
𝑥
n= 4 segments.

𝑏−𝑎 2−1
ℎ= = = 0.25
𝑛 4
𝑥0 = 1 𝑓 𝑥0 = 𝑓 1 = 1
𝑥1 = 1.25 𝑓 𝑥1 = 𝑓 1.25 = 0.8
𝑥2 = 1.5 𝑓 𝑥2 = 𝑓 1.5 = 0.6
𝑥3 = 1.75 𝑓 𝑥3 = 𝑓 1.75 = 0.5714
𝑥4 = 2 𝑓 𝑥4 = 𝑓 2 = 0.5
Solution

𝑏 𝑛−1

න 𝑓 𝑥 𝑑𝑥 ≅ 𝑓 𝑎 +2 ෍ 𝑓(𝑥𝑖 ) + 𝑓(𝑏)
𝑎 2
𝑖=1


≅ 𝑓 𝑥0 + 2 𝑓 𝑥1 + 𝑓 𝑥2 + 𝑓 𝑥3 + 𝑓 𝑥4
2

≅ 𝑓 1 + 2 𝑓 1.25 + 𝑓 1.5 + 𝑓 1.75 +𝑓 2
2
0.25
≅ 1 + 2 0.8 + 0.6 + 0.5714 + 0.5 = 0.6803
2
Solution
𝐼 ≅ 0.6803 , 𝐼𝑡 = 0.6931

True error 𝐸𝑡 = 𝐼𝑡 − 𝐼 = 0.6931 − 0.6803 = 0.0128

𝐼𝑡 −𝐼 0.6931 −0.6803
Relative true error 𝜀𝑡 = . 100 % = . 100 %
𝐼𝑡 0.6931

𝜀𝑡 = 1.84 %
Example
Approximate the area beneath 𝑦 = 𝑥 2 + 1 on the interval [0,2] using
the trapezoidal rule with n = 5 segments

Given that 𝐼𝑡 = 4.666 , calculate the true error and the relative true
error.
𝑦 = 𝑥2 + 1
Solution
n = 5 segments.

𝑏−𝑎 2−0
ℎ= = = 0.4
𝑛 5
𝑥0 = 0 𝑓 𝑥0 = 𝑓 0 = 1
𝑥1 = 0.4 𝑓 𝑥1 = 𝑓 0.4 = 1.16
𝑥2 = 0.8 𝑓 𝑥2 = 𝑓 0.8 = 1.64
𝑥3 = 1.2 𝑓 𝑥3 = 𝑓 1.2 = 2.44
𝑥4 = 1.6 𝑓 𝑥4 = 𝑓 1.6 = 3.56
𝑥5 = 2 𝑓 𝑥4 = 𝑓 2 = 5
Solution

𝑏 𝑛−1

න 𝑓 𝑥 𝑑𝑥 ≅ 𝑓 𝑎 +2 ෍ 𝑓(𝑥𝑖 ) + 𝑓(𝑏)
𝑎 2
𝑖=1


≅ 𝑓 𝑥0 + 2 𝑓 𝑥1 + 𝑓 𝑥2 + 𝑓 𝑥3 + +𝑓 𝑥4 + 𝑓 𝑥5
2

≅ 𝑓 0 + 2 𝑓 0.4 + 𝑓 0.8 + 𝑓 1.2 + 𝑓 1.6 +𝑓 2
2
0.4
≅ 1 + 2 1.16 + 1.64 + 2.44 + 3.56 + 5 = 4.72
2
Solution
𝐼 ≅ 4.72 , 𝐼𝑡 = 4.6666

True error 𝐸𝑡 = 𝐼𝑡 − 𝐼 = 4.666 − 4.72 = −0.054

𝐼𝑡 −𝐼 4.666 −4.72
Relative true error 𝜀𝑡 = . 100 % = . 100 %
𝐼𝑡 4.6666

𝜀𝑡 = 1.15 %
Composite Simpson’s Rule
To make Simpson’s 1/3 rule more effective and accurate, we divide the area
under the curve into multiple “segments” instead of only one.

𝒙𝟎 𝒙𝟏 𝒙𝟐 𝒙𝟑 𝒙𝟒
Composite Simpson’s Rule

𝑥4
𝐼 = න 𝑓 𝑥 𝑑𝑥
𝑥0

𝑥2 𝑥4
𝐼 ≅ න 𝑓 𝑥 𝑑𝑥 + න 𝑓 𝑥 𝑑𝑥
𝑥0 𝑥2

𝒙𝟎 𝒙𝟏 𝒙𝟐 𝒙𝟑 𝒙𝟒

ℎ 𝑏−𝑎
Simpson’s 1/3 Rule 𝐼 ≅ 𝑓0 + 4𝑓1 + 𝑓2 , ℎ=
3 2

Simpson’s 1/3 Rule 𝐼 ≅ 𝑓0 + 4𝑓1 + 𝑓2
Composite Simpson’s Rule 3
𝑏−𝑎
ℎ=
2
𝑥2 𝑥4
𝐼 ≅ න 𝑓 𝑥 𝑑𝑥 + න 𝑓 𝑥 𝑑𝑥
𝑥0 𝑥2

𝑥2 − 𝑥0 𝑓 𝑥0 + 4𝑓 𝑥1 + 𝑓(𝑥2 )
≅ .
2 3

𝑥4 − 𝑥2 𝑓 𝑥2 + 4𝑓 𝑥3 + 𝑓(𝑥4 )
+ .
2 3
𝑓 𝑎 +𝑓 𝑏
Composite Simpson’s Rule Trapezoidal Rule: 𝐼 ≅ 𝑏 − 𝑎
2

𝑓 𝑥0 + 4𝑓 𝑥1 + 𝑓(𝑥2 ) 𝑓 𝑥2 + 4𝑓 𝑥3 + 𝑓(𝑥4 )
𝐼 ≅ ℎ. + ℎ.
3 3


≅ 𝑓 𝑥0 + 4 𝑓 𝑥1 + 𝑓 𝑥3 + 2 𝑓 𝑥2 + 𝑓 𝑥4
3
Composite Simpson’s Rule

𝑏 𝑛−1 𝑛−2

න 𝑓 𝑥 𝑑𝑥 ≅ 𝑓 𝑎 +4 ෍ 𝑓(𝑥𝑖 ) + 2 ෍ 𝑓(𝑥𝑖 ) + 𝑓(𝑏)
𝑎 3
𝑖=1 𝑖=2
𝑖=𝑜𝑑𝑑 𝑖=𝑒𝑣𝑒𝑛

𝑏−𝑎
Where the step size ℎ =
𝑛

𝑛: 𝑡ℎ𝑒 𝑛𝑢𝑚𝑏𝑒𝑟 𝑜𝑓 𝑠𝑒𝑔𝑚𝑒𝑛𝑡𝑠


Example

Approximate the area beneath 𝑦 = 𝑥 2 + 1 on the interval [0,3] using


the Simpson’s rule with n= 6 segments

Given that 𝐼𝑡 = 12 , calculate the true error and the relative true error.
𝑦 = 𝑥2 + 1
Solution
n= 6 segments.

𝑏−𝑎 3−0
ℎ= = = 0.5
𝑛 6
𝑥0 = 0 𝑓 𝑥0 = 𝑓 0 = 1
𝑥1 = 0.5 𝑓 𝑥1 = 𝑓 0.5 = 1.25
𝑥2 = 1 𝑓 𝑥2 = 𝑓 1 = 2
𝑥3 = 1.5 𝑓 𝑥3 = 𝑓 1.5 = 3.25
𝑥4 = 2 𝑓 𝑥4 = 𝑓 2 = 5
𝑥5 = 2.5 𝑓 𝑥5 = 𝑓 2.5 = 7.25
𝑥6 = 3 𝑓 𝑥6 = 𝑓 3 = 10
Solution

𝑛−1 𝑛−2

𝐼≅ 𝑓 𝑎 +4 ෍ 𝑓(𝑥𝑖 ) + 2 ෍ 𝑓(𝑥𝑖 ) + 𝑓(𝑏)
3
𝑖=1 𝑖=2
𝑖=𝑜𝑑𝑑 𝑖=𝑒𝑣𝑒𝑛


≅ 𝑓 𝑥0 + 4 𝑓 𝑥1 + 𝑓 𝑥3 + 𝑓 𝑥5 + 2 𝑓 𝑥2 + 𝑓 𝑥4 + 𝑓 𝑥6
3
0.5
≅ 𝑓 0 + 4 𝑓 0.5 + 𝑓 1.5 + 𝑓 2.5 +2 𝑓 1 +𝑓 2 +𝑓 3
3
𝐼 ≅ 12
Solution
𝐼 ≅ 12 , 𝐼𝑡 = 12

True error 𝐸𝑡 = 𝐼𝑡 − 𝐼 = 12 − 12 = 0

𝐼𝑡 −𝐼 12 −12
Relative true error 𝜀𝑡 = . 100 % = . 100 %
𝐼𝑡 12

𝜀𝑡 = 0 %
Example 8 (solve by yourself)

Solve the previous example using composite trapezoidal rule using n=6
segments for the same interval [0,3].

Answer: 𝐼 ≅ 12.125
Example
Consider the following table of data points:
X 0 2 4 6 8
Y 0 1.9 2 2 2.4

8
Find the value of ‫׬‬0 𝑓(𝑥) 𝑑𝑥 Using the composite trapezoidal and
composite Simpson’s rules, using n=6 segments
Solution X 0 2 4 6 8
Y 0 1.9 2 2 2.4
𝑏−𝑎 8−0
step size ℎ = = =2
𝑛 4

𝑏 𝑛−1

න 𝑓 𝑥 𝑑𝑥 ≅ 𝑓 𝑎 +2 ෍ 𝑓(𝑥𝑖 ) + 𝑓(𝑏)
𝑎 2
𝑖=1


≅ 𝑓 𝑥0 + 2 𝑓 𝑥1 + 𝑓 𝑥2 + 𝑓 𝑥3 + 𝑓 𝑥4
2

≅ 𝑓 0 +2 𝑓 2 +𝑓 4 +𝑓 6 +𝑓 8
2
2
≅ 0 + 2 1.9 + 2 + 2 + 2.4 = 14.2
2
Solution X 0 2 4 6 8
Y 0 1.9 2 2 2.4
𝑏−𝑎 8−0
step size ℎ = = =2
𝑛 4

𝑛−1 𝑛−2

≅ 𝑓 𝑎 +4 ෍ 𝑓(𝑥𝑖 ) + 2 ෍ 𝑓(𝑥𝑖 ) + 𝑓(𝑏)
3
𝑖=1 𝑖=2
𝑖=𝑜𝑑𝑑 𝑖=𝑒𝑣𝑒𝑛


≅ 𝑓 𝑥0 + 4 𝑓 𝑥1 + 𝑓 𝑥3 + 2 𝑓 𝑥2 + 𝑓 𝑥4
3
2
≅ 𝑓 0 +4 𝑓 2 +𝑓 6 +2 𝑓 4 +𝑓 8
3
𝐼 ≅ 14.66

You might also like