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

Numerical Methods (CISE-301)

Unit-8
(Numerical Integration)
Dr. Muhammad Majid Gulzar (CIE-KFUPM)
Contents (Unit-8):
1) The Trapezoidal Rule (Sec 21.1)

2) Romberg Integration (Sec 22.2)

Dr. Muhammad Majid Gulzar (CIE-KFUPM)


Numerical Integration:
 Integral = Area under the Curve

𝑓𝑓(𝑥𝑥)
𝑏𝑏
𝐴𝐴𝐴𝐴𝐴𝐴𝐴𝐴 = � 𝑓𝑓(𝑥𝑥)𝑑𝑑𝑑𝑑
𝑎𝑎

Dr. Muhammad Majid Gulzar (CIE-KFUPM)


Numerical Integration:
 The idea in Numerical Integration is to replace a complicated function or tabulated data
with an approximating function that is easy to integrate.
𝑏𝑏 𝑏𝑏
𝐼𝐼 = � 𝑓𝑓(𝑥𝑥)𝑑𝑑𝑑𝑑 ≈ � 𝑎𝑎0 + 𝑎𝑎1 𝑥𝑥+. . . +𝑎𝑎𝑛𝑛 𝑥𝑥 𝑛𝑛 𝑑𝑑𝑑𝑑
𝑎𝑎 𝑎𝑎

𝑏𝑏
(𝑏𝑏 2 − 𝑎𝑎2 ) (𝑏𝑏 𝑛𝑛+1 − 𝑎𝑎𝑛𝑛+1 )
𝐼𝐼 = � 𝑓𝑓(𝑥𝑥)𝑑𝑑𝑑𝑑 ≈ 𝑎𝑎0 (𝑏𝑏 − 𝑎𝑎) + 𝑎𝑎1 +. . . +𝑎𝑎𝑛𝑛
𝑎𝑎 2 𝑛𝑛 + 1

 Not all functions are integrable, e.g.:


𝑎𝑎
−𝑥𝑥 2
𝐼𝐼 = � 𝑒𝑒 𝑑𝑑𝑑𝑑 =?
0

Dr. Muhammad Majid Gulzar (CIE-KFUPM)


Numerical Integration:
 Approximation of an integer

Using Single Straight Line Using Three Straight Line Using Single Parabola

Dr. Muhammad Majid Gulzar (CIE-KFUPM)


Numerical Integration:
 Difference between closed and open integration formulas

Closed Integration Formulas Open Integration Formulas

Dr. Muhammad Majid Gulzar (CIE-KFUPM)


The Trapezoidal Rule (Sec 21.1)
The Trapezoidal Rule:
 The idea in Numerical Integration is to replace a complicated function or tabulated data
with an approximating function that is easy to integrate.
𝑏𝑏 𝑏𝑏
𝐼𝐼 = � 𝑓𝑓(𝑥𝑥)𝑑𝑑𝑑𝑑 ≈ � 𝑎𝑎0 + 𝑎𝑎1 𝑥𝑥+. . . +𝑎𝑎𝑛𝑛 𝑥𝑥 𝑛𝑛 𝑑𝑑𝑑𝑑
𝑎𝑎 𝑎𝑎

 Trapezoid Method (First Order Polynomial are used)


𝑏𝑏 𝑏𝑏
𝐼𝐼 = � 𝑓𝑓(𝑥𝑥)𝑑𝑑𝑑𝑑 ≈ � 𝑎𝑎0 + 𝑎𝑎1 𝑥𝑥 𝑑𝑑𝑑𝑑
𝑎𝑎 𝑎𝑎

Dr. Muhammad Majid Gulzar (CIE-KFUPM)


The Trapezoidal Rule:
𝑏𝑏
𝐼𝐼 = � 𝑓𝑓(𝑥𝑥)𝑑𝑑𝑑𝑑
𝑎𝑎
𝑓𝑓(𝑏𝑏) − 𝑓𝑓(𝑎𝑎)
𝑓𝑓(𝑎𝑎) + (𝑥𝑥 − 𝑎𝑎)
𝑏𝑏 − 𝑎𝑎 𝑏𝑏
𝑓𝑓(𝑏𝑏) − 𝑓𝑓(𝑎𝑎)
𝐼𝐼 = � 𝑓𝑓(𝑎𝑎) + (𝑥𝑥 − 𝑎𝑎) 𝑑𝑑𝑑𝑑
𝑎𝑎 𝑏𝑏 − 𝑎𝑎

𝑏𝑏
𝑓𝑓(𝑥𝑥) 𝑓𝑓(𝑏𝑏) − 𝑓𝑓(𝑎𝑎) 𝑓𝑓(𝑏𝑏) − 𝑓𝑓(𝑎𝑎)
𝐼𝐼 = � 𝑓𝑓(𝑎𝑎) − 𝑎𝑎 + 𝑥𝑥 𝑑𝑑𝑑𝑑
𝑎𝑎 𝑏𝑏 − 𝑎𝑎 𝑏𝑏 − 𝑎𝑎

𝑏𝑏 𝑏𝑏
𝑓𝑓(𝑏𝑏) − 𝑓𝑓(𝑎𝑎) 𝑓𝑓(𝑏𝑏) − 𝑓𝑓(𝑎𝑎) 𝑥𝑥 2
𝐼𝐼 = 𝑓𝑓(𝑎𝑎) − 𝑎𝑎 𝑥𝑥 � + �
𝑏𝑏 − 𝑎𝑎 𝑏𝑏 − 𝑎𝑎 2
𝑎𝑎 𝑎𝑎

𝑓𝑓(𝑏𝑏) − 𝑓𝑓(𝑎𝑎) 𝑓𝑓(𝑏𝑏) − 𝑓𝑓(𝑎𝑎) 2


𝐼𝐼 = 𝑓𝑓(𝑎𝑎) − 𝑎𝑎 𝑏𝑏 − 𝑎𝑎 + (𝑏𝑏 − 𝑎𝑎2 )
𝑏𝑏 − 𝑎𝑎 2(𝑏𝑏 − 𝑎𝑎)
𝑎𝑎 𝑏𝑏
𝑓𝑓(𝑎𝑎) + 𝑓𝑓(𝑏𝑏)
𝐼𝐼 = 𝑏𝑏 − 𝑎𝑎
2
Dr. Muhammad Majid Gulzar (CIE-KFUPM)
The Trapezoidal Rule:
 Geometrically, the trapezoidal rule is equivalent to approximating the area of the
trapezoid under the straight line connecting 𝑓𝑓(𝑎𝑎) and 𝑓𝑓(𝑏𝑏).

𝐼𝐼 ≈ 𝑊𝑊𝑊𝑊𝑊𝑊𝑊𝑊𝑊 × 𝐴𝐴𝐴𝐴𝐴𝐴𝐴𝐴𝐴𝐴𝐴𝐴𝐴𝐴 𝐻𝐻𝐻𝐻𝐻𝐻𝐻𝐻𝐻𝐻𝐻

𝐼𝐼 ≈ (𝑏𝑏 − 𝑎𝑎) × 𝐴𝐴𝐴𝐴𝐴𝐴𝐴𝐴𝐴𝐴𝐴𝐴𝐴𝐴 𝐻𝐻𝐻𝐻𝐻𝐻𝐻𝐻𝐻𝐻𝐻

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

Dr. Muhammad Majid Gulzar (CIE-KFUPM)


The Trapezoidal Rule:

𝑓𝑓(𝑥𝑥)

𝑓𝑓(𝑏𝑏)

𝑓𝑓(𝑎𝑎)
𝑓𝑓(𝑎𝑎) + 𝑓𝑓(𝑏𝑏)
𝐴𝐴𝐴𝐴𝐴𝐴𝐴𝐴 = 𝑏𝑏 − 𝑎𝑎
2

𝑎𝑎 𝑏𝑏

Dr. Muhammad Majid Gulzar (CIE-KFUPM)


The Trapezoidal Rule:
 Error of the Trapezoidal Rule:
 In actual situations, we have no foreknowledge of the true value

 Therefore, an approximate error is estimated

 When we employ the integral under a straight-line segment to approximate the integral under
a curve, we obviously can incur an error that may be substantial

 An estimate for the local truncation error of a single application of the trapezoidal rule based
on Taylor Series is

Dr. Muhammad Majid Gulzar (CIE-KFUPM)


The Trapezoidal Rule:
 Error of the Trapezoidal Rule:
 To obtain the estimate, the functions’ second derivative over the interval can be computed by
differentiating the original function twice, where 𝜉𝜉 lies somewhere in the interval 𝑎𝑎 to 𝑏𝑏.

Dr. Muhammad Majid Gulzar (CIE-KFUPM)


The Trapezoidal Rule (Example):
Using trapezoidal rule to numerically integrate the given system from 𝑎𝑎 = 0 to 𝑏𝑏 = 0.8.
Note: The exact value of the integral can be determined analytically to be 1.640533.

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

Dr. Muhammad Majid Gulzar (CIE-KFUPM)


The Trapezoidal Rule (Example):
 The reason for this large error is evident from
the graphical depiction that the area under the
straight line neglects a significant portion of the
integral lying above the line.
 Therefore, an approximate error estimate is
required.

Dr. Muhammad Majid Gulzar (CIE-KFUPM)


The Trapezoidal Rule (Example):
Using trapezoidal rule to numerically integrate the given system from 𝑎𝑎 = 0 to 𝑏𝑏 = 0.8.
Note: The exact value of the integral can be determined analytically to be 1.640533.

Average value of 2nd Derivative

Thus, we denote that the error is approximate by using the notation 𝐸𝐸𝑎𝑎 , rather than exact by using 𝐸𝐸𝑡𝑡 .
Dr. Muhammad Majid Gulzar (CIE-KFUPM)
The Trapezoidal Rule:
 The Multiple-Application Trapezoidal Rule:
 One way to improve the accuracy of the trapezoidal rule is to divide the integration interval
from 𝑎𝑎 to 𝑏𝑏 into a number of segments and apply the method to each segment

2 Segments 3 Segments 4 Segments 5 Segments

Dr. Muhammad Majid Gulzar (CIE-KFUPM)


The Trapezoidal Rule:
 The Multiple-Application Trapezoidal Rule:
 If the interval [𝑎𝑎, 𝑏𝑏] is partitioned into 𝑛𝑛 segments 𝑎𝑎 = 𝑥𝑥0 ≤ 𝑥𝑥1 ≤ 𝑥𝑥2 ≤. . . ≤ 𝑥𝑥𝑛𝑛 = 𝑏𝑏.

𝑓𝑓(𝑥𝑥)
𝑏𝑏
� 𝑓𝑓(𝑥𝑥)𝑑𝑑𝑑𝑑 = sum of the areas of the trapezoids
𝑎𝑎

𝑓𝑓(𝑥𝑥2 ) + 𝑓𝑓(𝑥𝑥1 )
𝐴𝐴𝐴𝐴𝐴𝐴𝐴𝐴 = 𝑥𝑥2 − 𝑥𝑥1
2
𝑥𝑥
𝑥𝑥0 𝑥𝑥1 𝑥𝑥2 𝑥𝑥3
𝑎𝑎 𝑏𝑏
Dr. Muhammad Majid Gulzar (CIE-KFUPM)
The Trapezoidal Rule:

Dr. Muhammad Majid Gulzar (CIE-KFUPM)


The Trapezoidal Rule (Example):
Using two-segment trapezoidal rule to estimate the integral of the given system from 𝑎𝑎 = 0 to 𝑏𝑏 =
0.8. Do also estimate the error.
Note: The exact value of the integral can be determined analytically to be 1.640533.

Dr. Muhammad Majid Gulzar (CIE-KFUPM)


The Trapezoidal Rule (Example):
Using two-segment trapezoidal rule to estimate the integral of the given system from 𝑎𝑎 = 0 to 𝑏𝑏 =
0.8. Do also estimate the error.
Note: The exact value of the integral can be determined analytically to be 1.640533.

Dr. Muhammad Majid Gulzar (CIE-KFUPM)


The Trapezoidal Rule (Example):
Using two-segment trapezoidal rule to estimate the integral of the given system from 𝑎𝑎 = 0 to 𝑏𝑏 =
0.8. Do also estimate the error.
Note: The exact value of the integral can be determined analytically to be 1.640533.

Note: Error order is 𝑂𝑂(ℎ2 ) means doubling


the number of segments quarters the error.

Dr. Muhammad Majid Gulzar (CIE-KFUPM)


Romberg Integration (Sec 22.2)
Romberg Integration:
 Romberg integration is one technique that is designed to attain efficient numerical
integrals of functions.

 It is quite similar to the trapezoidal rule in the sense that it is based on successive
application of the trapezoidal rule.

 Trapezoid formula with an interval ℎ gives error of the order 𝑂𝑂(ℎ2 ), Thus we can
combine two Trapezoid estimates with intervals ℎ and ℎ/2 to get a better estimate.

 Generally called Richardson’s extrapolation, these methods use two estimates of an


integral to compute a third, more accurate approximation.

Dr. Muhammad Majid Gulzar (CIE-KFUPM)


Romberg Integration:
 Combined two trapezoidal rule estimates of 𝑂𝑂(ℎ2 ) to yield a new estimate of 𝑂𝑂(ℎ4 ).

 Combined two trapezoidal rule estimates of 𝑂𝑂(ℎ4 ) to yield a new estimate of 𝑂𝑂(ℎ6 ).

 Combined two trapezoidal rule estimates of 𝑂𝑂(ℎ6 ) to yield a new estimate of 𝑂𝑂(ℎ8 ).

 Here 𝐼𝐼𝑚𝑚 and 𝐼𝐼𝑙𝑙 are the more and less accurate estimates

Dr. Muhammad Majid Gulzar (CIE-KFUPM)


Romberg Integration (Example):
Using Romberg Integration to estimate the integral of the given system from 𝑎𝑎 = 0 to 𝑏𝑏 = 0.8 and
compute an integral with 𝑂𝑂(ℎ4 ).
Note: The exact value of the integral can be determined analytically to be 1.640533.

Previously

Dr. Muhammad Majid Gulzar (CIE-KFUPM)


Romberg Integration (Example):

Estimate for segment 1&2

Estimate for segment 2&4

Dr. Muhammad Majid Gulzar (CIE-KFUPM)


Romberg Integration (Example):
Using Romberg Integration to estimate the integral of the given system from 𝑎𝑎 = 0 to 𝑏𝑏 = 0.8 and
compute an integral with 𝑂𝑂(ℎ6 ).
Note: The exact value of the integral can be determined analytically to be 1.640533.

Previously

Correct Answer

Dr. Muhammad Majid Gulzar (CIE-KFUPM)


Romberg Integration (Class Activity):
Using Romberg Integration to estimate the integral of the given system from 𝑎𝑎 = 0 to 𝑏𝑏 = 0.8 and
compute an integral with 𝑂𝑂(ℎ8 ).
Note: The exact value of the integral can be determined analytically to be 1.640533.

Dr. Muhammad Majid Gulzar (CIE-KFUPM)


Romberg Integration (Class Activity):
𝑛𝑛 ℎ 𝑂𝑂(ℎ2 ) 𝑂𝑂(ℎ4 ) 𝑂𝑂(ℎ6 ) 𝑂𝑂(ℎ8 )
1 0.8 𝑅𝑅(0,0)
First column is obtained using
Trapezoid Method 2 0.4 𝑅𝑅(1,0) 𝑅𝑅(1,1)

4 0.2 𝑅𝑅(2,0) 𝑅𝑅(2,1) 𝑅𝑅(2,2)

8 0.1 𝑅𝑅(3,0) 𝑅𝑅(3,1) 𝑅𝑅(3,2) 𝑅𝑅(3,3)


The other elements are obtained
using the Romberg Method
𝑛𝑛 ℎ 𝑂𝑂(ℎ2 ) 𝑂𝑂(ℎ4 ) 𝑂𝑂(ℎ6 ) 𝑂𝑂(ℎ8 )
1 0.8 0.1728
2 0.4 1.0688 1.367467
4 0.2 1.4848 1.623467 1.640533
8 0.1 1.6008 1.639467 1.640533 1.640533
Dr. Muhammad Majid Gulzar (CIE-KFUPM)
Romberg Integration (Class Activity):

Dr. Muhammad Majid Gulzar (CIE-KFUPM)


Romberg Integration (Class Activity):
Using Romberg Integration to estimate the integral of the given system from 𝑎𝑎 = 0 to 𝑏𝑏 = 1.

Dr. Muhammad Majid Gulzar (CIE-KFUPM)


Romberg Integration (Class Activity):
Using Romberg Integration to estimate the integral of the given system from 𝑎𝑎 = 0 to 𝑏𝑏 = 1.

𝑂𝑂(ℎ2 ) 𝑂𝑂(ℎ4 ) 𝑂𝑂(ℎ6 ) 𝑂𝑂(ℎ2 ) 𝑂𝑂(ℎ4 ) 𝑂𝑂(ℎ6 )


𝑅𝑅(0,0) 0.5
𝑅𝑅(1,0) 𝑅𝑅(1,1) 3/8 1/3
𝑅𝑅(2,0) 𝑅𝑅(2,1) 𝑅𝑅(2,2) 11/32 1/3 1/3

Dr. Muhammad Majid Gulzar (CIE-KFUPM)

You might also like