0% found this document useful (0 votes)
19 views55 pages

Lecture Notes - Differentiation and Integration

Uploaded by

mo.dmour22
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)
19 views55 pages

Lecture Notes - Differentiation and Integration

Uploaded by

mo.dmour22
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/ 55

College of Engineering, Department of Mechanical Engineering

Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

Numerical Differentiation and Integration


Derivative Definition:
Given:
𝒚 = 𝒇(𝒙)

∆𝒚 ∆𝒇 𝒇(𝒙𝒊 + ∆𝒙) − 𝒇(𝒙𝒊 )


→ = =
∆𝒙 ∆𝒙 ∆𝒙

𝒅𝒚 𝒅𝒇 ∆𝒚 𝒇(𝒙𝒊 + ∆𝒙) − 𝒇(𝒙𝒊 )


= = 𝐥𝐢𝐦 = 𝐥𝐢𝐦
𝒅𝒙 𝒅𝒙 ∆𝒙→𝟎 ∆𝒙 ∆𝒙→𝟎 ∆𝒙

The graphical definition of a derivative: as ∆𝒙 approaches zero in going from (a) to (c), the
difference approximation becomes a derivative.

Approximations to Derivatives Using Taylor Series

Taylor series of 𝒇(𝒙) near a point 𝒙𝒊 :

(𝒙 − 𝒙𝒊 )𝟐 ′′ (𝒙 − 𝒙𝒊 )𝟑 ′′′
𝒇(𝒙) = 𝒇(𝒙𝒊 ) + (𝒙 − 𝒙𝒊 )𝒇′ (𝒙𝒊 ) + 𝒇 (𝒙 )
𝒊 + 𝒇 (𝒙𝒊 ) + ⋯
𝟐! 𝟑!
(𝒙 − 𝒙𝒊 )𝒏 (𝒏)
+ 𝒇 (𝒙𝒊 ) (𝟏)
𝒏!

Page 1 of 55
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

Forward Difference Approximation to 1st derivative:

Apply (1) at 𝒙𝒊+𝟏 𝒘𝒊𝒕𝒉

∆𝒙 = 𝒙𝒊+𝟏 − 𝒙𝒊

𝒇(𝒙𝒊 ) = 𝒇𝒊 , 𝒇(𝒙𝒊+𝟏 ) = 𝒇𝒊+𝟏

(∆𝒙)𝟐 ′′ (∆𝒙)𝟑 ′′′ (∆𝒙)𝒏 (𝒏)


𝒇(𝒙𝒊+𝟏 ) = 𝒇(𝒙𝒊 ) + ∆𝒙𝒇′ (𝒙𝒊 ) + 𝒇 (𝒙𝒊 ) + 𝒇 (𝒙𝒊 ) + ⋯ + 𝒇 (𝒙𝒊 )
𝟐! 𝟑! 𝒏!

𝒘𝒊𝒕𝒉 𝒇(𝒙𝒊 ) = 𝒇𝒊 , 𝒇(𝒙𝒊+𝟏 ) = 𝒇𝒊+𝟏 :

(∆𝒙)𝟐 ′′ (∆𝒙)𝟑 ′′′ (∆𝒙)𝒏 (𝒏)


𝒇𝒊+𝟏 = 𝒇𝒊 + ∆𝒙𝒇′𝒊 + 𝒇𝒊 + 𝒇𝒊 + ⋯ + 𝒇𝒊 (𝟐)
𝟐! 𝟑! 𝒏!
𝒅𝒇
Solve (2) for 𝒇′𝒊 ≡ ( ) :
𝒅𝒙 𝒊

𝒅𝒇 𝒇𝒊+𝟏 − 𝒇𝒊 ∆𝒙 ′′ (∆𝒙)𝟐 ′′′ (∆𝒙)𝒏−𝟏 (𝒏)


𝒇′𝒊 ≡ ( ) = − 𝒇 − 𝒇 − ⋯ − 𝒇𝒊 (𝟑)
𝒅𝒙 𝒊 ∆𝒙 𝟐! 𝒊 𝟑! 𝒊
𝒏!

Truncate (3) after the first term: 

𝒅𝒇 𝒇𝒊+𝟏 − 𝒇𝒊
𝒇′𝒊 ≡ ( ) ≅ + 𝑶(∆𝒙) (𝟒)
𝒅𝒙 𝒊 ∆𝒙
OR:
𝒅𝒇 𝒇(𝒙𝒊+𝟏 ) − 𝒇(𝒙𝒊 )
𝒇′ (𝒙𝒊 ) ≡ ( ) ≅ + 𝑶(∆𝒙) (𝟒)
𝒅𝒙 𝒊 𝒙𝒊+𝟏 − 𝒙𝒊
Above formula is an approximation to the first derivative at 𝒙𝒊 , using 𝒙𝒊+𝟏 , 
Forward Difference
𝑶(∆𝒙) is the order of magnitude of the error encountered in approximating the
derivative.
 First order accurate Forward Difference of the first derivative:

Page 2 of 55
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

𝒅𝒇 𝒇(𝒙𝒊+𝟏 ) − 𝒇(𝒙𝒊 ) 𝒇(𝒙𝒊 + ∆𝒙) − 𝒇(𝒙𝒊 )


( ) = = + 𝑶(∆𝒙)
𝒅𝒙 𝒊 𝒙𝒊+𝟏 − 𝒙𝒊 ∆𝒙

Backward Difference Approximation to 1st derivative:

Apply Taylor series at 𝒙𝒊−𝟏


𝒙 − 𝒙𝒊 = 𝒙𝒊−𝟏 − 𝒙𝒊 = −∆𝒙

(∆𝒙)𝟐 ′′ (∆𝒙)𝟑 ′′′


𝒇𝒊−𝟏 = 𝒇𝒊 − ∆𝒙𝒇′𝒊 + 𝒇𝒊 − 𝒇𝒊 + ⋯ (𝟓)
𝟐! 𝟑!
𝒅𝒇
Solve for 𝒇′𝒊 ≡ ( ) :
𝒅𝒙 𝒊
𝒅𝒇 𝒇𝒊 − 𝒇𝒊−𝟏 ∆𝒙 ′′ ∆𝒙 ′′′
𝒇′𝒊 ≡ ( ) = + 𝒇 − 𝒇 −⋯
𝒅𝒙 𝒊 ∆𝒙 𝟐! 𝒊 𝟑! 𝒊

Truncate above equation after the first term: 


1st order accurate Backward difference of the first derivative:
𝒅𝒇 𝒇𝒊 − 𝒇𝒊−𝟏
𝒇′𝒊 ≡ ( ) = + 𝑶(∆𝒙)
𝒅𝒙 𝒊 ∆𝒙

Page 3 of 55
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

Central Difference Approximation to 1st derivative:

Using Equations (2) & (5):

(∆𝒙)𝟐 ′′ (∆𝒙)𝟑 ′′′ (∆𝒙)𝒏 (𝒏)


𝒇𝒊+𝟏 = 𝒇𝒊 + ∆𝒙𝒇′𝒊 + 𝒇𝒊 + 𝒇𝒊 + ⋯ + 𝒇𝒊 (𝟐)
𝟐! 𝟑! 𝒏!

(∆𝒙)𝟐 ′′ (∆𝒙)𝟑 ′′′


𝒇𝒊−𝟏 = 𝒇𝒊 − ∆𝒙𝒇′𝒊 + 𝒇𝒊 − 𝒇𝒊 + ⋯ (𝟓)
𝟐! 𝟑!

Subtract (5) from (2):

𝟐(∆𝒙)𝟑 ′′′
𝒇𝒊+𝟏 − 𝒇𝒊−𝟏 = 𝟐∆𝒙𝒇′𝒊 + 𝒇𝒊 + ⋯
𝟑!
𝒅𝒇
Solve for 𝒇′𝒊 ≡ ( ) :
𝒅𝒙 𝒊

2nd order accurate Central difference of the first derivative:

𝒅𝒇 𝒇𝒊+𝟏 − 𝒇𝒊−𝟏
𝒇′𝒊 ≡ ( ) = + 𝑶(∆𝒙)𝟐
𝒅𝒙 𝒊 𝟐∆𝒙

Page 4 of 55
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

Summary - Approximation to first derivative

𝒅𝒇 𝒇𝒊+𝟏 − 𝒇𝒊
𝒇′𝒊 ≡ ( ) ≅ + 𝑶(∆𝒙) 𝐅𝐨𝐫𝐰𝐚𝐫𝐝 𝐃𝐢𝐟𝐟𝐞𝐫𝐞𝐧𝐜𝐞
𝒅𝒙 𝒊 ∆𝒙

𝒅𝒇 𝒇𝒊 − 𝒇𝒊−𝟏
𝒇′𝒊 ≡ ( ) = + 𝑶(∆𝒙) 𝐁𝐚𝐜𝐤𝐰𝐚𝐫𝐝 𝐃𝐢𝐟𝐟𝐞𝐫𝐞𝐧𝐜𝐞
𝒅𝒙 𝒊 ∆𝒙
𝒅𝒇 𝒇𝒊+𝟏 − 𝒇𝒊−𝟏
𝒇′𝒊 ≡ ( ) = + 𝑶(∆𝒙)𝟐 𝐂𝐞𝐧𝐭𝐫𝐚𝐥 𝐃𝐢𝐟𝐟𝐞𝐫𝐞𝐧𝐜𝐞
𝒅𝒙 𝒊 𝟐∆𝒙

Page 5 of 55
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

Example:
Calculate the forward, backward and central difference approximations to the
first derivative at 𝒙 = 𝟓 with ∆𝒙 = 𝟎. 𝟏 for
𝒇(𝒙) = 𝟏𝟎𝒙𝟑 + 𝟓𝒙𝟐 + 𝟐, and compare with the exact solution.
Solution
Exact Solution:
𝒇′ (𝒙) = 𝟑𝟎𝒙𝟐 + 𝟏𝟎𝒙, → 𝒇′ (𝟓) = 𝟑𝟎(𝟓)𝟐 + 𝟏𝟎(𝟓) = 𝟖𝟎𝟎

(1) Forward Difference:

𝒇(𝟓. 𝟏) − 𝒇(𝟓) 𝟏𝟒𝟓𝟖. 𝟓𝟔 − 𝟏𝟑𝟕𝟕


𝒇′ (𝟓) ≅ = = 𝟖𝟏𝟓. 𝟔
𝟎. 𝟏 𝟎. 𝟏

Error = 1.950 %

(2) Backward Difference:

𝒇(𝟓) − 𝒇(𝟒. 𝟗) 𝟏𝟑𝟕𝟕 − 𝟏𝟐𝟗𝟖. 𝟓𝟒


𝒇′ (𝟓) ≅ = = 𝟕𝟖𝟒. 𝟔
𝟎. 𝟏 𝟎. 𝟏

Error = 1.925 %

(3) Central Difference:

𝒇(𝟓. 𝟏) − 𝒇(𝟒. 𝟗) 𝟏𝟒𝟓𝟖. 𝟓𝟔 − 𝟏𝟐𝟗𝟖. 𝟓𝟒


𝒇′ (𝟓) ≅ = = 𝟖𝟎𝟎. 𝟏
𝟐(𝟎. 𝟏) 𝟎. 𝟐

Error = 0.0125 %

Exercise:
Repeat the above example with ∆𝒙 = 𝟎. 𝟐, 𝟎. 𝟎𝟓, 𝟎. 𝟎𝟏

Page 6 of 55
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

High Order Approximations to the 1st Derivative


2nd order accurate forward difference approximation to the 1st derivative
To obtain a 2nd order accurate
forward difference
𝒅𝒇
approximation for :
𝒅𝒙

Apply Taylor series expansion


at 𝒙𝒊+𝟏 , 𝒙𝒊+𝟐 :
(∆𝒙)𝟐 ′′ (∆𝒙)𝟑 ′′′
𝒇𝒊+𝟏 = 𝒇𝒊 + ∆𝒙𝒇′𝒊 + 𝒇𝒊 + 𝒇𝒊 + ⋯ (𝟏)
𝟐! 𝟑!

(𝟐∆𝒙)𝟐 ′′ (𝟐∆𝒙)𝟑 ′′′


𝒇𝒊+𝟐 = 𝒇𝒊 + 𝟐∆𝒙𝒇′𝒊 + 𝒇𝒊 + 𝒇𝒊 + ⋯ (𝟐)
𝟐! 𝟑!

To find an 𝑶(∆𝒙)𝟐 𝒂𝒑𝒑𝒓𝒐𝒙𝒊𝒎𝒂𝒕𝒊𝒐𝒏 𝒕𝒐 𝒇′𝒊 ∶


We need to eliminate the terms involving 𝒇′′
𝒊

 Multiply (1) by 4 and subtract (2) from (1)


(𝟐∆𝒙)𝟐 ′′ 𝟒(∆𝒙)𝟑 ′′′
𝟒𝒇𝒊+𝟏 = 𝟒𝒇𝒊 + 𝟒∆𝒙𝒇′𝒊 + 𝒇𝒊 + 𝒇𝒊 + ⋯ (𝟏)′
𝟐! 𝟑!
(𝟐∆𝒙)𝟐 ′′ (𝟐∆𝒙)𝟑 ′′′
∓𝒇𝒊+𝟐 = ∓𝒇𝒊 ∓ 𝟐∆𝒙𝒇′𝒊 ∓ 𝒇𝒊 ∓ 𝒇𝒊 + ⋯ (𝟐)′
𝟐! 𝟑!

𝟒(∆𝒙)𝟑 ′′′
𝟒𝒇𝒊+𝟏 − 𝒇𝒊+𝟐 = 𝟑𝒇𝒊 + 𝟐∆𝒙𝒇′𝒊 − 𝒇𝒊
𝟑!
Solve for 𝒇′𝒊

−𝟑𝒇𝒊 + 𝟒𝒇𝒊+𝟏 − 𝒇𝒊+𝟐 𝟐(∆𝒙)𝟐 ′′′


𝒇′𝒊 = + 𝒇𝒊
𝟐∆𝒙 𝟑!

−𝟑𝒇𝒊 + 𝟒𝒇𝒊+𝟏 − 𝒇𝒊+𝟐


𝒇′𝒊 = + 𝑶(∆𝒙)𝟐
𝟐∆𝒙

Page 7 of 55
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

2nd order accurate backward difference approximation to the 1st derivative


To obtain a 2nd order accurate
forward difference
𝒅𝒇
approximation for :
𝒅𝒙

Apply Taylor series expansion


at 𝒙𝒊−𝟏 , 𝒙𝒊−𝟐 :
(∆𝒙)𝟐 ′′ (∆𝒙)𝟑 ′′′
𝒇𝒊−𝟏 = 𝒇𝒊 − ∆𝒙𝒇′𝒊 + 𝒇𝒊 − 𝒇𝒊 + ⋯ (𝟏)
𝟐! 𝟑!

(𝟐∆𝒙)𝟐 ′′ (𝟐∆𝒙)𝟑 ′′′


𝒇𝒊−𝟐 = 𝒇𝒊 − 𝟐∆𝒙𝒇′𝒊 + 𝒇𝒊 − 𝒇𝒊 + ⋯ (𝟐)
𝟐! 𝟑!

To find an 𝑶(∆𝒙)𝟐 𝒂𝒑𝒑𝒓𝒐𝒙𝒊𝒎𝒂𝒕𝒊𝒐𝒏 𝒕𝒐 𝒇′𝒊 ∶


We need to eliminate the terms involving 𝒇′′
𝒊

 Multiply (1) by 4 and subtract (2) from (1)

(𝟐∆𝒙)𝟐 ′′ 𝟒(∆𝒙)𝟑 ′′′


𝟒𝒇𝒊−𝟏 = 𝟒𝒇𝒊 − 𝟒∆𝒙𝒇′𝒊 + 𝒇𝒊 − 𝒇𝒊 + ⋯ (𝟏)′
𝟐! 𝟑!
(𝟐∆𝒙)𝟐 ′′ (𝟐∆𝒙)𝟑 ′′′
∓𝒇𝒊−𝟐 = ∓𝒇𝒊 ± 𝟐∆𝒙𝒇′𝒊 ∓ 𝒇𝒊 ± 𝒇𝒊 + ⋯ (𝟐)′
𝟐! 𝟑!
--------------------------------------------------------------------------------------------------------
𝟒(∆𝒙)𝟑 ′′′
𝟒𝒇𝒊−𝟏 − 𝒇𝒊−𝟐 = 𝟑𝒇𝒊 − 𝟐∆𝒙𝒇′𝒊 + 𝒇𝒊
𝟑!
Solve for 𝒇′𝒊

𝟑𝒇𝒊 − 𝟒𝒇𝒊−𝟏 + 𝒇𝒊−𝟐 𝟒(∆𝒙)𝟐 ′′′


𝒇′𝒊 = + 𝒇𝒊
𝟐∆𝒙 𝟑!

𝟑𝒇𝒊 − 𝟒𝒇𝒊−𝟏 + 𝒇𝒊−𝟐


𝒇′𝒊 = + 𝑶(∆𝒙)𝟐
𝟐∆𝒙

Page 8 of 55
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

Example:
Use 2nd order accurate forward and backward difference approximations to
numerically evaluate 𝒇′ (𝟎), 𝒘𝒊𝒕𝒉 ∆𝒙 = 𝟎. 𝟏 𝒊𝒇 𝒇(𝒙) = 𝒆𝒙
Solution:
Exact solution:
𝒇′ (𝒙) = 𝒆𝒙 , → 𝒇′ (𝟎) = 𝒆𝟎 = 𝟏
Forward difference approximation:

−𝟑𝒇(𝟎) + 𝟒𝒇(𝟎. 𝟏) − 𝒇(𝟎. 𝟐)


𝒇′ (𝟎) = = 𝟎. 𝟗𝟗𝟔𝟒𝟎𝟓
𝟐(𝟎. 𝟏)
𝑬𝒓𝒓𝒐𝒓 ≈ 𝟎. 𝟑𝟔%

Backward difference approximation:

𝟑𝒇(𝟎) − 𝟒𝒇(−𝟎. 𝟏) + 𝒇(−𝟎. 𝟐)


𝒇′ (𝟎) = = 𝟎. 𝟗𝟗𝟔𝟗𝟎𝟓
𝟐(𝟎. 𝟏)
𝑬𝒓𝒓𝒐𝒓 ≈ 𝟎. 𝟑𝟏%

Page 9 of 55
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

Finite Difference Approximations to the 2nd derivative


1. 2nd order accurate central difference

Taylor series at 𝒙𝒊+𝟏 𝒂𝒏𝒅 𝒙𝒊−𝟏

(∆𝒙)𝟐 ′′ (∆𝒙)𝟑 ′′′ (∆𝒙)𝟒 (𝟒)


𝒇𝒊+𝟏 = 𝒇𝒊 + ∆𝒙𝒇′𝒊 + 𝒇𝒊 + 𝒇𝒊 + 𝒇𝒊 + ⋯ (𝟏)
𝟐! 𝟑! 𝟒!

(∆𝒙)𝟐 ′′ (∆𝒙)𝟑 ′′′ (∆𝒙)𝟒 (𝟒)


𝒇𝒊−𝟏 = 𝒇𝒊 − ∆𝒙𝒇′𝒊 + 𝒇𝒊 − 𝒇𝒊 + 𝒇𝒊 + ⋯ (𝟐)
𝟐! 𝟑! 𝟒!
--------------------------------------------------------------------------------------------------------
Add (1) & (2)”:
𝟐(∆𝒙)𝟒 (𝟒)
𝒇𝒊+𝟏 + 𝒇𝒊−𝟏 = 𝟐𝒇𝒊 + (∆𝒙)𝟐 𝒇′′
𝒊 + 𝒇𝒊 + ⋯
𝟒!
Solve for 𝒇′′
𝒊 :

𝒇𝒊+𝟏 − 𝟐𝒇𝒊 + 𝒇𝒊−𝟏 𝟐(∆𝒙)𝟐 (𝟒)


𝒇′′
𝒊 = + 𝒇𝒊 + ⋯
(∆𝒙)𝟐 𝟒!
OR:

𝒇𝒊+𝟏 − 𝟐𝒇𝒊 + 𝒇𝒊−𝟏


𝒇′′
𝒊 = + 𝑶(∆𝒙)𝟐
(∆𝒙)𝟐

Page 10 of 55
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

Finite Difference Approximations to the 2nd derivative

2. 1st order accurate forward difference

Taylor series at 𝒙𝒊+𝟏 𝒂𝒏𝒅 𝒙𝒊+𝟐 :

(∆𝒙)𝟐 ′′ (∆𝒙)𝟑 ′′′ (∆𝒙)𝟒 (𝟒)


𝒇𝒊+𝟏 = 𝒇𝒊 + ∆𝒙𝒇′𝒊 + 𝒇𝒊 + 𝒇𝒊 + 𝒇𝒊 + ⋯ (𝟏)
𝟐! 𝟑! 𝟒!

(𝟐∆𝒙)𝟐 ′′ (𝟐∆𝒙)𝟑 ′′′ (𝟐∆𝒙)𝟒 (𝟒)


𝒇𝒊+𝟐 = 𝒇𝒊 + 𝟐∆𝒙𝒇′𝒊 + 𝒇𝒊 + 𝒇𝒊 + 𝒇𝒊 + ⋯ (𝟐)
𝟐! 𝟑! 𝟒!

To eliminate 𝒇′𝒊 :

Multiply (1) by 2 and subtract from (2):

𝟐(∆𝒙)𝟐 ′′ 𝟐(∆𝒙)𝟑 ′′′ 𝟐(∆𝒙)𝟒 (𝟒)


𝟐𝒇𝒊+𝟏 = 𝟐𝒇𝒊 + 𝟐∆𝒙𝒇′𝒊 + 𝒇𝒊 + 𝒇𝒊 + 𝒇𝒊 + ⋯ (𝟏)
𝟐! 𝟑! 𝟒!

(𝟐∆𝒙)𝟐 ′′ (𝟐∆𝒙)𝟑 ′′′ (𝟐∆𝒙)𝟒 (𝟒)


−𝒇𝒊+𝟐 = −𝒇𝒊 − 𝟐∆𝒙𝒇′𝒊 − 𝒇𝒊 − 𝒇𝒊 − 𝒇𝒊 + ⋯ (𝟐)
𝟐! 𝟑! 𝟒!
--------------------------------------------------------------------------------------------------------
𝟐𝒇𝒊+𝟏 − 𝒇𝒊+𝟐 = 𝒇𝒊 − (∆𝒙)𝟐 𝒇′′ 𝟑 ′′′
𝒊 − (∆𝒙) 𝒇𝒊 − ⋯

Solve for 𝒇′′


𝒊 :

𝒇𝒊 − 𝟐𝒇𝒊+𝟏 + 𝒇𝒊+𝟐
𝒇′′
𝒊 = + 𝑶(∆𝒙)
(∆𝒙)𝟐

Page 11 of 55
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

Finite Difference Approximations to the 2nd derivative


3. 2nd order accurate backward difference

Write Taylor series at 𝒙𝒊−𝟏 , 𝒙𝒊−𝟐 , 𝒙𝒊−𝟑 :

(∆𝒙)𝟐 ′′ (∆𝒙)𝟑 ′′′ (∆𝒙)𝟒 (𝟒)


𝒇𝒊−𝟏 = 𝒇𝒊 − ∆𝒙𝒇′𝒊 + 𝒇𝒊 − 𝒇𝒊 + 𝒇𝒊 − ⋯ (𝟏)
𝟐! 𝟑! 𝟒!

(𝟐∆𝒙)𝟐 ′′ (𝟐∆𝒙)𝟑 ′′′ (𝟐∆𝒙)𝟒 (𝟒)


𝒇𝒊−𝟐 = 𝒇𝒊 − 𝟐∆𝒙𝒇′𝒊 + 𝒇𝒊 − 𝒇𝒊 + 𝒇𝒊 − ⋯ (𝟐)
𝟐! 𝟑! 𝟒!

(𝟑∆𝒙)𝟐 ′′ (𝟑∆𝒙)𝟑 ′′′ (𝟑∆𝒙)𝟒 (𝟒)


𝒇𝒊−𝟑 = 𝒇𝒊 − 𝟑∆𝒙𝒇′𝒊 + 𝒇𝒊 − 𝒇𝒊 + 𝒇𝒊 − ⋯ (𝟑)
𝟐! 𝟑! 𝟒!

To eliminate 𝒇′′′
𝒊 from the above equations:

Multiply Eq (1) by 5, Eq (2) by -4, and add the three equations:

𝟐𝒇𝒊 − 𝟓𝒇𝒊−𝟏 + 𝟒𝒇𝒊−𝟐 − 𝒇𝒊−𝟑


𝒇′′
𝒊 = + 𝑶(∆𝒙)𝟐
(∆𝒙)𝟐

4. 2nd order accurate forward difference

Exercise: Use Taylor series expansion to show that 2nd order accurate forward
difference approximation for 𝒇′′
𝒊 is:

𝟐𝒇𝒊 − 𝟓𝒇𝒊+𝟏 + 𝟒𝒇𝒊+𝟐 − 𝒇𝒊+𝟑


𝒇′′
𝒊 = 𝟐
+ 𝑶(∆𝒙)𝟐
(∆𝒙)

Page 12 of 55
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

Summary: Forward Difference Formulas for 1st , 2nd, 3rd , 4th derivatives
𝑵𝒐𝒕𝒆: 𝒉 = ∆𝒙

Page 13 of 55
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

Summary: Backward Difference Formulas for 1st , 2nd, 3rd , 4th derivatives
𝑵𝒐𝒕𝒆: 𝒉 = ∆𝒙

Page 14 of 55
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

Summary: Central Difference Formulas for 1st , 2nd, 3rd , 4th derivatives
𝑵𝒐𝒕𝒆: 𝒉 = ∆𝒙

Page 15 of 55
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

Numerical Solution of Ordinary Differential Equations by


Finite Difference Method

Derivatives in Ordinary Differential Equations (ODEs) are replaced by their


finite difference approximations  System of algebraic equations  Solve by:
Gauss elimination, Gauss Jordan, Gauss –Seidel iteration,……
Example:
Solve the following ODE numerically using central difference approximations to
both the first and second derivatives.
𝒇′′ − 𝟓𝒇′ − 𝟔𝒇 = 𝟎
𝒇(𝟎) = 𝟎, 𝒇(𝟏) = 𝟏
Find solution at 𝒙 = 𝟎. 𝟐, 𝟎. 𝟒, 𝟎. 𝟔, 𝟎. 𝟖 and compare with the exact solution.
Solution:
Divide the given interval (domain) into 5 subintervals (cells)
5 subintervals (cells)  6 grid points.
In general: for N grid points, with domain of length L:
𝑳
∆𝒙 =
𝑵−𝟏

In the above example: 𝑳 = 𝟏, 𝑵 = 𝟔


𝟏
∆𝒙 = = 𝟎. 𝟐 = 𝒉
𝟓

Approximating the given ODE at


a typical grid point i:

𝒇𝒊+𝟏 − 𝟐𝒇𝒊 + 𝒇𝒊−𝟏 𝒇𝒊+𝟏 − 𝒇𝒊−𝟏


− 𝟓 − 𝟔𝒇𝒊 = 𝟎
𝒉𝟐 𝟐𝒉

Multiply above equation by 𝒉𝟐 :

Page 16 of 55
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

𝟓
𝒇𝒊+𝟏 − 𝟐𝒇𝒊 + 𝒇𝒊−𝟏 − 𝒉(𝒇𝒊+𝟏 − 𝒇𝒊−𝟏 ) − 𝟔𝒉𝟐 𝒇𝒊 = 𝟎
𝟐
Re-arrange:
(𝟏 + 𝟐. 𝟓𝒉)𝒇𝒊−𝟏 − (𝟐 + 𝟔𝒉𝟐 )𝒇𝒊 + (𝟏 − 𝟐. 𝟓𝒉)𝒇𝒊+𝟏 = 𝟎

𝑾𝒊𝒕𝒉 ∆𝒙 = 𝒉 = 𝟎. 𝟐, above equation becomes:

𝟏. 𝟓𝒇𝒊−𝟏 − 𝟐. 𝟐𝟒𝒇𝒊 + 𝟎. 𝟓𝒇𝒊+𝟏 = 𝟎


Note:
𝑭𝒐𝒓 𝒊 = 𝟏 (𝒙 = 𝟎): 𝒇(𝟎) = 𝟎
𝑭𝒐𝒓 𝒊 = 𝟔 (𝒙 = 𝟏): 𝒇(𝟏) = 𝟏. 𝟎
 No need to apply the finite difference equation at 𝒊 = 𝟏, 𝒊 = 𝟔
 Apply equation at 𝒊 = 𝟐, 𝟑, 𝟒, 𝟓
𝒊 = 𝟐: 𝟏. 𝟓𝒇𝟏 − 𝟐. 𝟐𝟒𝒇𝟐 + 𝟎. 𝟓𝒇𝟑 = 𝟎
Since 𝒇𝟏 = 𝟎:
𝒊 = 𝟐: − 𝟐. 𝟐𝟒𝒇𝟐 + 𝟎. 𝟓𝒇𝟑 = 𝟎 (𝟏)
𝒊 = 𝟑: 𝟏. 𝟓𝒇𝟐 − 𝟐. 𝟐𝟒𝒇𝟑 + 𝟎. 𝟓𝒇𝟒 = 𝟎 (𝟐)
𝒊 = 𝟒: 𝟏. 𝟓𝒇𝟑 − 𝟐. 𝟐𝟒𝒇𝟒 + 𝟎. 𝟓𝒇𝟓 = 𝟎 (𝟑)
𝒊 = 𝟓: 𝟏. 𝟓𝒇𝟒 − 𝟐. 𝟐𝟒𝒇𝟓 + 𝟎. 𝟓𝒇𝟔 = 𝟎
Since 𝒇𝟔 = 𝟏:
𝒊 = 𝟓: 𝟏. 𝟓𝒇𝟒 − 𝟐. 𝟐𝟒𝒇𝟓 = −𝟎. 𝟓 (𝟒)
Equations (1) to (4) in matrix form:
−𝟐. 𝟐𝟒 𝟎. 𝟓 𝟎 𝟎 𝒇𝟐 𝟎
𝟏. 𝟓 −𝟐. 𝟐𝟒 𝟎. 𝟓 𝟎 𝒇 𝟎
[ ] [ 𝟑] = [ ]
𝟎 𝟏. 𝟓 −𝟐. 𝟐𝟒 𝟎. 𝟓 𝒇𝟒 𝟎
𝟎 𝟎 𝟏. 𝟓 −𝟐. 𝟐𝟒 𝒇𝟓 −𝟎. 𝟓
Solve using Gauss elimination,……
Exact Solution:
𝒇 = 𝒆𝜶𝒙 , → 𝒇′ = 𝜶𝒆𝜶𝒙 , 𝒇′′ = 𝜶𝟐 𝒆𝜶𝒙
→ 𝜶𝟐 − 𝟓𝜶 − 𝟔 = 𝟎, → 𝜶 = −𝟏, 𝟔
→ 𝒇(𝒙) = 𝑪𝟏 𝒆−𝒙 + 𝑪𝟐 𝒆𝟔𝒙
𝑼𝒔𝒆 𝒕𝒉𝒆 𝒃𝒐𝒖𝒏𝒅𝒂𝒓𝒚 𝒄𝒐𝒏𝒅𝒊𝒕𝒊𝒐𝒏𝒔 𝒕𝒐 𝒇𝒊𝒏𝒅 𝑪𝟏 , 𝑪𝟐

Page 17 of 55
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

Boundary Conditions
Boundary conditions can take different forms:
1. The dependent variable is given explicitly at the boundaries

Example:
𝒚′′ + 𝒂𝒚′ + 𝒃𝒚 = 𝟎, 𝒙 ∈ [𝟎, 𝟏]
𝒚(𝟎) = 𝜶, 𝒚(𝟏) = 𝜷

𝒚𝟏 = 𝜶, 𝒚𝟏𝟏 = 𝜷
 Write the ODE in finite difference form and apply it at the interior points:
In the example above: at points 𝒊 = 𝟐, 𝟑, … . , 𝟏𝟎,  9 equations.
-------------------------------------------------------------------------------------------------
2. The boundary condition can be given in terms of a derivative:

Example:
𝒚′′ + 𝒂𝒚′ + 𝒃𝒚 = 𝟎, 𝒙 ∈ [𝟎, 𝑳] (𝟏)
𝒚′ (𝟎) = 𝜶, 𝒚′ (𝑳) = 𝜷 (𝟐)

ODE in finite difference form:


𝟏 𝟏
[𝟏 − 𝒂∆𝒙] 𝒚𝒊−𝟏 − [𝟐 − 𝒃∆𝒙𝟐 ]𝒚𝒊 + [𝟏 + 𝒂∆𝒙] 𝒚𝒊+𝟏 = 𝟎
𝟐 𝟐
OR:
𝑪𝟏 𝒚𝒊−𝟏 − 𝑪𝟐 𝒚𝒊 + 𝑪𝟑 𝒚𝒊+𝟏 = 𝟎 (𝟑)
𝒘𝒉𝒆𝒓𝒆,
𝟏 𝟏
𝑪𝟏 = [𝟏 − 𝒂∆𝒙] , 𝑪𝟐 = [𝟐 − 𝒃∆𝒙𝟐 ], 𝑪𝟑 = [𝟏 + 𝒂∆𝒙]
𝟐 𝟐
Divide the domain into (N-1) cells (N grid points)
𝑳
∆𝒙 =
𝑵−𝟏

Page 18 of 55
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

Since the dependent variable y is not given at the boundary, we have to apply the
finite difference equation (3) at the boundary:
At 𝒊 = 𝟏 (𝒙 = 𝟎): 𝑬𝒒𝒖𝒂𝒕𝒊𝒐𝒏 (𝟑) 𝒓𝒆𝒂𝒅𝒔:
𝑪𝟏 𝒚𝟎 − 𝑪𝟐 𝒚𝟏 + 𝑪𝟑 𝒚𝟐 = 𝟎 (𝟒)
Note: 𝒚𝟎 is a point out of the domain:
To eliminate this point, we use the B. C:
𝒚′ (𝟎) = 𝜶 (𝟓)
In finite difference form, Eq. (3) at 𝒙 = 𝟎 (𝒊 = 𝟏) becomes:
𝒚𝟐 − 𝒚 𝒐
= 𝜶, → 𝒚𝒐 = 𝒚𝟐 − 𝟐𝜶∆𝒙 (𝟔)
𝟐∆𝒙
 Use (6) in (4) to eliminate 𝒚𝒐 :

𝑬𝒒𝒏. (𝟒) → 𝑪𝟏 (𝒚𝟐 − 𝟐𝜶∆𝒙) − 𝑪𝟐 𝒚𝟏 + 𝑪𝟑 𝒚𝟐 = 𝟎


OR:
−𝑪𝟐 𝒚𝟏 + (𝑪𝟏 + 𝑪𝟑 )𝒚𝟐 = 𝟐𝜶𝑪𝟏 ∆𝒙 (𝟕)
For the interior points 𝒊 = 𝟐, 𝟑, … , 𝑵 − 𝟏:
𝑪𝟏 𝒚𝒊−𝟏 − 𝑪𝟐 𝒚𝒊 + 𝑪𝟑 𝒚𝒊+𝟏 = 𝟎; 𝑵𝒐 𝒑𝒐𝒊𝒏𝒕𝒔 𝒐𝒖𝒕𝒔𝒊𝒅𝒆 𝒕𝒉𝒆 𝒅𝒐𝒎𝒂𝒊𝒏
For 𝒊 = 𝑵: 𝑬𝒒𝒏 (𝟑) →
𝑪𝟏 𝒚𝑵−𝟏 − 𝑪𝟐 𝒚𝑵 + 𝑪𝟑 𝒚𝑵+𝟏 = 𝟎 (𝟖)
𝒚𝑵+𝟏 𝒊𝒔 𝒐𝒖𝒕𝒔𝒊𝒅𝒆 𝒕𝒉𝒆 𝒅𝒐𝒎𝒂𝒊𝒏; 𝑬𝒍𝒊𝒎𝒊𝒏𝒂𝒕𝒆 𝒕𝒉𝒊𝒔 𝒑𝒐𝒊𝒏𝒕 𝒇𝒓𝒐𝒎 (𝟖):
Use the boundary condition at 𝒙 = 𝑳, (𝒊 = 𝑵).
Descritize the boundary condition at 𝒙 = 𝑳, (𝒊 = 𝑵)𝒖𝒔𝒊𝒏𝒈 𝒄𝒆𝒏𝒕𝒓𝒂𝒍 𝒅𝒊𝒇𝒇𝒆𝒓𝒆𝒏𝒄𝒆:
𝒚𝑵+𝟏 − 𝒚𝑵−𝟏
𝒚′ (𝑳) = 𝜷, → =𝜷
𝟐∆𝒙
→ 𝒚𝑵+𝟏 = 𝒚𝑵−𝟏 + 𝟐𝜷∆𝒙 (𝟗)
Substitute (9) in (8):
𝑪𝟏 𝒚𝑵−𝟏 − 𝑪𝟐 𝒚𝑵 + 𝑪𝟑 (𝒚𝑵−𝟏 + 𝟐𝜷∆𝒙) = 𝟎
OR:
Page 19 of 55
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

(𝑪𝟏 + 𝑪𝟑 ) 𝒚𝑵−𝟏 − 𝑪𝟐 𝒚𝑵 = −𝟐𝜷∆𝒙𝑪𝟑 (𝟏𝟎)

 Summary of the Equations to be solved

−𝑪𝟐 𝒚𝟏 + (𝑪𝟏 + 𝑪𝟑 )𝒚𝟐 = 𝟐𝜶𝑪𝟏 ∆𝒙, 𝑭𝒐𝒓 𝒊 = 𝟏


𝑪𝟏 𝒚𝒊−𝟏 − 𝑪𝟐 𝒚𝒊 + 𝑪𝟑 𝒚𝒊+𝟏 = 𝟎, 𝑭𝒐𝒓 𝒊 = 𝟐, 𝑵 − 𝟏
(𝑪𝟏 + 𝑪𝟑 ) 𝒚𝑵−𝟏 − 𝑪𝟐 𝒚𝑵 = −𝟐𝜷∆𝒙𝑪𝟑 , 𝑭𝒐𝒓 𝒊 = 𝑵

3. The boundary condition can be given in terms of the dependent variable and
its derivative:
General Form:
𝒚′ + 𝜶𝒚 = 𝜷 𝒂𝒕 𝒕𝒉𝒆 𝒃𝒐𝒖𝒏𝒅𝒂𝒓𝒚 (𝟏)

Example:

At the left boundary; 𝒊 = 𝟏


Discritize (1) at 𝒊 = 𝟏:
𝒚𝟐 − 𝒚 𝒐
+ 𝜶𝒚𝟏 = 𝜷
𝟐∆𝒙
→ 𝒚𝒐 = 𝒚𝟐 + 𝟐∆𝒙𝜶𝒚𝟏 − 𝟐∆𝒙𝜷
At the right boundary; 𝒊 = 𝑵
Discritize (1) at 𝒊 = 𝑵:
𝒚𝑵+𝟏 − 𝒚𝑵−𝟏
+ 𝜶𝒚𝑵 = 𝜷
𝟐∆𝒙
→ 𝒚𝑵+𝟏 = 𝒚𝑵−𝟏 − 𝟐∆𝒙𝜶𝒚𝑵 + 𝟐∆𝒙𝜷

Page 20 of 55
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

Partial Derivatives
Finite difference approximations for partial derivatives can be found using
Taylor series expansions.
Given 𝒇 = 𝒇(𝒙, 𝒚)
Partial derivatives of f w.r.t. x:
𝝏𝒇 𝝏𝟐 𝒇
, ,………
𝝏𝒙 𝝏𝒙𝟐
Partial derivatives of f w.r.t. y:
𝝏𝒇 𝝏𝟐 𝒇
, ,………
𝝏𝒚 𝝏𝒚𝟐
1st order accurate forward difference – 1st derivative:
𝝏𝒇 𝒇(𝒙𝒊+𝟏 , 𝒚𝒋 ) − 𝒇(𝒙𝒊 , 𝒚𝒋 ) 𝒇𝒊+𝟏,𝒋 − 𝒇𝒊,𝒋
( ) = =
𝝏𝒙 𝒊,𝒋 ∆𝒙 ∆𝒙
𝝏𝒇 𝒇(𝒙𝒊 , 𝒚𝒋+𝟏 ) − 𝒇(𝒙𝒊 , 𝒚𝒋 ) 𝒇𝒊,𝒋+𝟏 − 𝒇𝒊,𝒋
( ) = =
𝝏𝒚 𝒊,𝒋 ∆𝒚 ∆𝒚

1st order accurate backward difference – 1st derivative:


𝝏𝒇 𝒇(𝒙𝒊 , 𝒚𝒋 ) − 𝒇(𝒙𝒊−𝟏 , 𝒚𝒋 ) 𝒇𝒊,𝒋 − 𝒇𝒊−𝟏,𝒋
( ) = =
𝝏𝒙 𝒊,𝒋 ∆𝒙 ∆𝒙
𝝏𝒇 𝒇(𝒙𝒊 , 𝒚𝒋 ) − 𝒇(𝒙𝒊 , 𝒚𝒋−𝟏 ) 𝒇𝒊,𝒋 − 𝒇𝒊,𝒋−𝟏
( ) = =
𝝏𝒚 𝒊,𝒋 ∆𝒚 ∆𝒚

2nd order accurate central difference – 1st derivative::


𝝏𝒇 𝒇(𝒙𝒊+𝟏 , 𝒚𝒋 ) − 𝒇(𝒙𝒊−𝟏 , 𝒚𝒋 ) 𝒇𝒊+𝟏,𝒋 − 𝒇𝒊−𝟏,𝒋
( ) = =
𝝏𝒙 𝒊,𝒋 𝟐∆𝒙 𝟐∆𝒙
𝝏𝒇 𝒇(𝒙𝒊 , 𝒚𝒋+𝟏 ) − 𝒇(𝒙𝒊 , 𝒚𝒋 ) 𝒇𝒊,𝒋+𝟏 − 𝒇𝒊,𝒋−𝟏
( ) = =
𝝏𝒚 𝒊,𝒋 𝟐∆𝒚 𝟐∆𝒚

2nd order accurate central difference – 2nd derivatives:


𝝏𝟐 𝒇 𝒇𝒊−𝟏,𝒋 − 𝟐𝒇𝒊,𝒋 + 𝒇𝒊+𝟏,𝒋 𝝏𝟐 𝒇 𝒇𝒊,𝒋−𝟏 − 𝟐𝒇𝒊,𝒋 + 𝒇𝒊,𝒋+𝟏
= , =
𝝏𝒙𝟐 ∆𝒙𝟐 𝝏𝒚𝟐 ∆𝒚𝟐

Page 21 of 55
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

HW Problem Set 6 (Numerical Differentiation)


Problem 1:

Problem 2:

Problem 3:
Solve the following ODE numerically using central difference approximations for both
the 1st and 2nd derivatives. Use a grid size of ∆𝑥 = 0.25. Compare your results with the
analytical solution.
𝑦 ′′ + 3𝑦 ′ + 2𝑦 = 6
𝑦(0) = 0, 𝑦 ′ (1) = 1

Page 22 of 55
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

Numerical Integration
Goal: To evaluate numerically an integral:
𝒃

𝑰 = ∫ 𝒇(𝒙)𝒅𝒙
𝒂
𝒏

𝑨𝒓𝒆𝒂 = ∑ 𝒇(𝒙𝒊 )∆𝒙𝒊


𝒊=𝟏

𝒏 𝒃

𝒏 → ∞: ∑ 𝒇(𝒙𝒊 )∆𝒙𝒊 = ∫ 𝒇(𝒙)𝒅𝒙


𝒊=𝟏 𝒂

With finite n:
𝒃 𝒏

∫ 𝒇(𝒙)𝒅𝒙 ≅ ∑ 𝒇(𝒙𝒊 )∆𝒙𝒊


𝒂 𝒊=𝟏

To resort to numerical integration when 𝒇(𝒙) cannot be integrated analytically.


Newton – Cotes Integration Formulas (NCIF)
𝒃
To compute 𝑰 = ∫𝒂 𝒇(𝒙)𝒅𝒙 numerically:
𝒇(𝒙) is replaced by an approximating function that can be easily integrated.
𝑰𝒇 𝒇(𝒙) ≅ 𝒇𝒏 (𝒙), where 𝒇𝒏 (𝒙) is a polynomial of degree n 
𝒃 𝒃

𝑰 = ∫ 𝒇(𝒙)𝒅𝒙 ≅ ∫ 𝒇𝒏 (𝒙)𝒅𝒙
𝒂 𝒂

Where,
𝒇𝒏 (𝒙) = 𝒂𝒐 + 𝒂𝟏 𝒙 + 𝒂𝟐 𝒙𝟐 + ⋯ + 𝒂𝒏 𝒙𝒏

Page 23 of 55
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

Diversion:
To have an estimate of the error encountered by replacing 𝒇(𝒙) with a
polynomial 𝒇𝒏 (𝒙):
Remainders in Polynomial Representation of Functions:
Recall: Taylor series of 𝒇(𝒙) at 𝒙𝒊+𝟏 near 𝒙𝒊 :
(𝒙𝒊+𝟏 − 𝒙𝒊 )𝟐 ′′ (𝒙𝒊+𝟏 − 𝒙𝒊 )𝟑 ′′′
𝒇𝒊+𝟏 = 𝒇𝒊 + (𝒙𝒊+𝟏 − 𝒙𝒊 )𝒇′ (𝒙𝒊 ) + 𝒇 (𝒙𝒊 ) + 𝒇 (𝒙𝒊 ) + ⋯
𝟐! 𝟑!
(𝒙𝒊+𝟏 − 𝒙𝒊 )𝒏 (𝒏) (𝒙𝒊+𝟏 − 𝒙𝒊 )𝒏 (𝒏)
+ 𝒇 (𝒙𝒊 ) + 𝒇 (𝒙𝒊 ) + ⋯ (𝟏)
𝒏! 𝒏!
Taylor Theorem:
If the function 𝒇(𝒙) and its first (n+1) derivatives are continuous on an interval
[𝒂, 𝒃], with 𝒙𝒐 ∈ [𝒂, 𝒃], there exists a number 𝝃 between 𝒙 and 𝒙𝒐 such that:
(𝒙 − 𝒙𝒐 )𝟐 ′′ (𝒙 − 𝒙𝒐 )𝒏 (𝒏)
𝒇(𝒙) = 𝒇(𝒙𝒐 ) + (𝒙 − 𝒙𝒐 )𝒇′ (𝒙𝒐 ) + 𝒇 (𝒙 )
𝒐 + ⋯+ 𝒇 (𝒙𝒐 )
𝟐! 𝒏!
+ 𝑹𝒏 (𝟐)
Where,
(𝒙 − 𝒙𝒐 )𝟐 ′′ (𝒙 − 𝒙𝒐 )𝒏 (𝒏)
𝒇(𝒙) = 𝒇(𝒙𝒐 ) + (𝒙 − 𝒙𝒐 )𝒇′ (𝒙𝒐 ) + 𝒇 (𝒙𝒐 ) + ⋯ + 𝒇 (𝒙𝒐 )
𝟐! 𝒏!
is the Taylor polynomial, and
(𝒙 − 𝒙𝒐 )𝒏+𝟏 (𝒏+𝟏)
𝑹𝒏 = 𝒇 (𝝃 ) 𝒙𝒐 < 𝝃 < 𝒙 (𝟑)
(𝒏 + 𝟏)!

If the spacing between 𝒙 & 𝒙𝒐 𝒊𝒔 𝒉; 𝒉 = 𝒙 − 𝒙𝒐 :


𝒉𝟐 ′′ 𝒉𝒏 (𝒏)
𝒇(𝒙) = 𝒇(𝒙𝒐 ) + 𝒉𝒇′ (𝒙𝒐 ) + 𝒇 (𝒙𝒐 ) + ⋯ + 𝒇 (𝒙𝒐 ) + 𝑹𝒏 (𝟒)
𝟐! 𝒏!
𝒉𝒏+𝟏
𝑹𝒏 = 𝒇(𝒏+𝟏) (𝝃 ) 𝒙𝒐 < 𝝃 < 𝒙 (𝟓)
(𝒏 + 𝟏)!

𝑻𝒂𝒚𝒍𝒐𝒓 𝑺𝒆𝒓𝒊𝒆𝒔 = 𝑻𝒂𝒚𝒍𝒐𝒓 𝑷𝒐𝒍𝒚𝒏𝒐𝒎𝒊𝒂𝒍 + 𝑹𝒆𝒎𝒂𝒊𝒏𝒅𝒆𝒓


Page 24 of 55
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

Taylor series in terms of Newton’s interpolating polynomials


Recall: The nth order Newton’s interpolating polynomial:
𝒇𝒏 (𝒙) = 𝒂𝒐 + 𝒂𝟏 (𝒙 − 𝒙𝒐 ) + 𝒂𝟐 (𝒙 − 𝒙𝒐 )(𝒙 − 𝒙𝟏 ) + 𝒂𝟑 (𝒙 − 𝒙𝒐 )(𝒙 − 𝒙𝟏 )(𝒙 − 𝒙𝟐 )
+ ⋯ + 𝒂𝒏 (𝒙 − 𝒙𝒐 )(𝒙 − 𝒙𝟏 ) … (𝒙 − 𝒙𝒏−𝟏 )
+ 𝒂𝒏+𝟏 (𝒙 − 𝒙𝒐 )(𝒙 − 𝒙𝟏 ) … (𝒙 − 𝒙𝒏 ) + ⋯
Where,
𝒂𝒐 = 𝒇(𝒙𝒐 )
𝒂𝟏 = 𝒇[𝒙𝟏 , 𝒙𝒐 ]
𝒂𝟐 = 𝒇[𝒙𝟐 , 𝒙𝟏 , 𝒙𝒐 ]
………
………
𝒂𝒏 = 𝒇[𝒙𝒏 , 𝒙𝒏−𝟏 , … . , 𝒙𝒐 ]
For the nth order Newton’s interpolating polynomial:
𝑹𝒆𝒎𝒂𝒊𝒏𝒅𝒆𝒓 𝑹𝒏 = 𝒂𝒏+𝟏 (𝒙 − 𝒙𝒐 )(𝒙 − 𝒙𝟏 ) … (𝒙 − 𝒙𝒏 ) + ⋯

Polynomials with Equally Spaced Data


With equally spaced data:
𝒙𝒊+𝟏 − 𝒙𝒊 = 𝒉, 𝒊 = 𝟎, 𝟏, 𝟐, … ..
→ 𝒙𝒊+𝟏 = 𝒙𝒊 + 𝒉
𝒙𝟏 = 𝒙𝒐 + 𝒉
𝒙𝟐 = 𝒙𝟏 + 𝒉 = 𝒙𝒐 + 𝒉 + 𝒉 = 𝒙𝒐 + 𝟐𝒉
𝒙𝟑 = 𝒙𝒐 + 𝟑𝒉
……
……
𝒙𝒏 = 𝒙𝒏−𝟏 + 𝒉 = 𝒙𝒐 + 𝒏𝒉
𝒙𝒏+𝟏 = 𝒙𝒏 + 𝒉 = 𝒙𝒐 + (𝒏 + 𝟏)𝒉

𝒂𝒐 = 𝒇(𝒙𝒐 )
𝒇(𝒙𝟏 ) − 𝒇(𝒙𝒐 ) ∆𝒇(𝒙𝒐 )
𝒂𝟏 = 𝒇[𝒙𝟏 , 𝒙𝒐 ] = =
𝒙𝟏 − 𝒙𝒐 𝒉
Page 25 of 55
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

𝒇(𝒙𝟐 ) − 𝒇(𝒙𝟏 ) 𝒇(𝒙𝟏 ) − 𝒇(𝒙𝒐 )


− 𝒇(𝒙𝟐 ) − 𝟐𝒇(𝒙𝟏 ) + 𝒇(𝒙𝒐 )
𝒙𝟐 − 𝒙𝟏 𝒙𝟏 − 𝒙𝒐
𝒂𝟐 = 𝒇[𝒙𝟐 , 𝒙𝟏 , 𝒙𝒐 ] = =
𝒙𝟐 − 𝒙𝒐 𝟐𝒉𝟐
∆𝟐 𝒇(𝒙𝒐 ) ∆𝟐 𝒇(𝒙𝒐 )
= =
𝟐𝒉𝟐 𝟐! 𝒉𝟐

𝒇[𝒙𝟑 , 𝒙𝟐 , 𝒙𝟏 ] − 𝒇[𝒙𝟐 , 𝒙𝟏 , 𝒙𝒐 ]
𝒂𝟑 = 𝒇[𝒙𝟑 , 𝒙𝟐 , 𝒙𝟏 , 𝒙𝒐 ] =
𝒙𝟑 − 𝒙𝒐
𝒇(𝒙𝟑 ) − 𝟑𝒇(𝒙𝟐 ) + 𝟑𝒇(𝒙𝟏 ) − 𝒇(𝒙𝒐 ) ∆𝟑 𝒇(𝒙𝒐 ) ∆𝟑 𝒇(𝒙𝒐 )
= = =
𝟔𝒉𝟑 𝟔𝒉𝟑 𝟑! 𝒉𝟑

∆𝟒 𝒇(𝒙𝒐 )
𝒂𝟒 =
𝟒! 𝒉𝟒
……………
……………
∆𝒏 𝒇(𝒙𝒐 )
𝒂𝒏 =
𝒏! 𝒉𝒏
 For equally spaced data points, Newton’s interpolating polynomial can be
written as:

∆𝒇(𝒙𝒐 ) ∆𝟐 𝒇(𝒙𝒐 )
𝒇𝒏 (𝒙) = 𝒇(𝒙𝒐 ) + (𝒙 − 𝒙𝒐 ) + (𝒙 − 𝒙𝒐 )(𝒙 − 𝒙𝒐 − 𝒉)
𝒉 𝟐! 𝒉𝟐
∆𝟑 𝒇(𝒙𝒐 )
+ (𝒙 − 𝒙𝒐 )(𝒙 − 𝒙𝒐 − 𝒉)(𝒙 − 𝒙𝒐 − 𝟐𝒉) + ⋯
𝟑! 𝒉𝟑
∆𝒏 𝒇(𝒙𝒐 )
+ (𝒙 − 𝒙𝒐 )(𝒙 − 𝒙𝒐 − 𝒉)(𝒙 − 𝒙𝒐 − 𝟐𝒉) … (𝒙 − 𝒙𝒐 − [𝒏 − 𝟏]𝒉)
𝒏! 𝒉𝒏
+ 𝑹𝒏
Above expansion is called: Newton’s Formula, OR, Newton-Gregory Forward
formula. To simplify the formula above:
Introduce a new variable as follows:
𝒙 − 𝒙𝒐
𝜶=
𝒉

𝒙 − 𝒙𝒐 = 𝜶𝒉
𝒙 − 𝒙𝒐 − 𝒉 = 𝜶𝒉 − 𝒉 = (𝜶 − 𝟏)𝒉
Page 26 of 55
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

𝒙 − 𝒙𝒐 − 𝟐𝒉 = 𝜶𝒉 − 𝟐𝒉 = (𝜶 − 𝟐)𝒉
𝒙 − 𝒙𝒐 − 𝟑𝒉 = 𝜶𝒉 − 𝟑𝒉 = (𝜶 − 𝟑)𝒉
………
………
𝒙 − 𝒙𝒐 − (𝒏 − 𝟏)𝒉 = 𝜶𝒉 − (𝒏 − 𝟏)𝒉 = (𝜶 − 𝒏 + 𝟏)𝒉


𝜶(𝜶 − 𝟏) 𝟐 𝜶(𝜶 − 𝟏)(𝜶 − 𝟐) 𝟑
𝒇𝒏 (𝒙) = 𝒇(𝒙𝒐 ) + 𝜶∆𝒇(𝒙𝒐 ) + ∆ 𝒇(𝒙𝒐 ) + ∆ 𝒇(𝒙𝒐 ) + ⋯
𝟐! 𝟑!
𝜶(𝜶 − 𝟏)(𝜶 − 𝟐) … . (𝜶 − 𝒏 + 𝟏) 𝒏
+ ∆ 𝒇(𝒙𝒐 ) + 𝑹𝒏
𝒏!
To find an expression for 𝑹𝒏 :
𝑹𝒏 = 𝒂𝒏+𝟏 (𝒙 − 𝒙𝒐 )(𝒙 − 𝒙𝟏 ) … (𝒙 − 𝒙𝒏 ) + 𝒂𝒏+𝟐 (𝒙 − 𝒙𝒐 )(𝒙 − 𝒙𝟏 ) … (𝒙 − 𝒙𝒏+𝟏 ) + ⋯
Using the Mean Value Theorem:
If 𝒇′ exists  𝒇[𝒙𝒐 , 𝒙𝟏 ] = 𝒇′ (𝝃), 𝒙𝒐 < 𝝃 < 𝒙𝟏
This can be extended as follows:
If 𝒇(𝒙) is continuous in [𝒂, 𝒃], and 𝒙𝒐 , 𝒙𝟏 , … , 𝒙𝒏 are distinct numbers in [𝒂, 𝒃],
then there is a number 𝝃 in [𝒂, 𝒃] such that:
𝒇𝒏 (𝝃)
𝒇[𝒙𝒏 , 𝒙𝒏−𝟏 , … . , 𝒙𝟏 , 𝒙𝒐 ] =
𝒏!
 With the Mean Value Theorem applied to 𝑹𝒏 (leading term):
𝒇𝒏+𝟏 (𝝃)
𝒂𝒏+𝟏 = 𝒇[𝒙𝒏+𝟏 , 𝒙𝒏 , … . , 𝒙𝟏 , 𝒙𝒐 ] =
(𝒏 + 𝟏)!
We can also write:
(𝒙 − 𝒙𝒐 )(𝒙 − 𝒙𝟏 )(𝒙 − 𝒙𝟐 ) … (𝒙 − 𝒙𝒏 ) = 𝜶𝒉. (𝜶 − 𝟏)𝒉. (𝜶 − 𝟐)𝒉 … . (𝜶 − 𝒏)𝒉
OR:
(𝒙 − 𝒙𝒐 )(𝒙 − 𝒙𝟏 )(𝒙 − 𝒙𝟐 ) … (𝒙 − 𝒙𝒏 ) = 𝜶(𝜶 − 𝟏)(𝜶 − 𝟐) … (𝜶 − 𝒏)𝒉𝒏+𝟏

𝒇𝒏+𝟏 (𝝃) 𝒏+𝟏


 𝑹𝒏 = 𝒉 𝜶(𝜶 − 𝟏)(𝜶 − 𝟐) … (𝜶 − 𝒏)
(𝒏 + 𝟏)!

Page 27 of 55
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

The Trapezoidal Rule


To evaluate:
𝒃 𝒙𝟏

𝑰 = ∫ 𝒇(𝒙)𝒅𝒙 = ∫ 𝒇(𝒙)𝒅𝒙
𝒂 𝒙𝒐

The approximating polynomial to 𝒇(𝒙) is:


𝒇(𝒙) ≅ 𝒇𝟏 (𝒙) = 𝑪𝒐 + 𝑪𝟏 𝒙 (𝟏)
𝒙 = 𝒂, 𝒇(𝒙) = 𝒇(𝒂)
𝒙 = 𝒃, 𝒇(𝒙) = 𝒇(𝒃)
𝒇(𝒃) − 𝒇(𝒂)
→ 𝒇𝟏 (𝒙) = 𝒇(𝒂) + (𝒙 − 𝒂) (𝟐)
𝒃−𝒂
From (1) & (2):
𝒂
𝑪𝒐 = 𝒇(𝒂) − (𝒇(𝒃) − 𝒇(𝒂)) (𝟑)
𝒃−𝒂

𝒇(𝒃) − 𝒇(𝒂)
𝑪𝟏 = (𝟒)
𝒃−𝒂
𝒃 𝒃 𝒃
𝒃
𝟏 𝟐
𝑰 = ∫ 𝒇(𝒙)𝒅𝒙 ≅ ∫ 𝒇𝟏 (𝒙)𝒅𝒙 = ∫(𝑪𝒐 + 𝑪𝟏 𝒙)𝒅𝒙 = [𝑪𝒐 𝒙 + 𝑪𝟏 𝒙 ]
𝟐 𝒂
𝒂 𝒂 𝒂
𝟏 𝟏
𝑰 = (𝑪𝒐 𝒃 + 𝑪𝟏 𝒃𝟐 ) − (𝑪𝒐 𝒂 + 𝑪𝟏 𝒂𝟐 )
𝟐 𝟐
𝟏
𝑰 = 𝑪𝒐 (𝒃 − 𝒂) + 𝑪𝟏 (𝒃𝟐 − 𝒂𝟐 ) (𝟓)
𝟐
Use (3) & (4) in (5):

𝟏 Trapezoidal Rule (6)


𝑰 = (𝒃 − 𝒂) [𝒇(𝒂) + 𝒇(𝒃)]
𝟐

Page 28 of 55
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

Error estimate of the Trapezoidal Rule


Recall Newton-Gregory formula:
𝜶(𝜶 − 𝟏) 𝟐
𝒇𝒏 (𝒙) = 𝒇(𝒙𝒐 ) + 𝜶∆𝒇(𝒙𝒐 ) + ∆ 𝒇(𝒙𝒐 ) + ⋯ + 𝑹𝒏
𝟐!
𝒇𝒏+𝟏 (𝝃) 𝒏+𝟏
𝑹𝒏 = 𝒉 𝜶(𝜶 − 𝟏)(𝜶 − 𝟐) … (𝜶 − 𝒏)
(𝒏 + 𝟏)!

𝒙 − 𝒙𝒐
𝜶= , 𝒉 = 𝒙𝒊+𝟏 − 𝒙𝒊
𝒉
For the trapezoidal rule: (1st order polynomial):
𝒏=𝟏
𝒇′′ (𝝃) 𝟐
→ 𝒇𝟏 (𝒙) = 𝒇(𝒙𝒐 ) + 𝜶∆𝒇(𝒙𝒐 ) + 𝒉 𝜶(𝜶 − 𝟏)
𝟐!
𝒃 𝒃

→ 𝑰 = ∫ 𝒇(𝒙)𝒅𝒙 ≅ ∫ 𝒇𝟏 (𝒙)𝒅𝒙
𝒂 𝒂
𝒃
𝒇′′ (𝝃) 𝟐
𝑰 = ∫ [𝒇(𝒂) + 𝜶∆𝒇(𝒂) + 𝒉 𝜶(𝜶 − 𝟏)] 𝒅𝒙
𝟐!
𝒂
𝒙 − 𝒙𝒐
𝜶= , → 𝜶𝒉 = 𝒙 − 𝒙𝒐 , → 𝒉𝒅𝜶 = 𝒅𝒙
𝒉
𝑨𝒕 𝒙 = 𝒙𝒐 = 𝒂: 𝜶 = 𝟎
𝑨𝒕 𝒙 = 𝒙𝟏 = 𝒃: 𝜶 = 𝟏
𝟏
𝒇′′ (𝝃) 𝟐
𝑰 = ∫ [𝒇(𝒂) + 𝜶∆𝒇(𝒂) + 𝒉 𝜶(𝜶 − 𝟏)] 𝒉𝒅𝜶
𝟐!
𝟎
𝟏
𝟏 𝟐 𝜶𝟑 𝜶𝟐 𝟐 ′′
𝑰 = 𝒉 [𝒇(𝒂)𝜶 + 𝜶 ∆𝒇(𝒂) + ( − ) 𝒉 𝒇 (𝝃)]
𝟐 𝟔 𝟒 𝟎
𝟏
𝟏 𝟏 𝟐 ′′
→ 𝑰 = 𝒉 [𝒇(𝒂) + ∆𝒇(𝒂) − 𝒉 𝒇 (𝝃)]
𝟐 𝟏𝟐 𝟎
𝟏 𝟏 𝟐 ′′
→ 𝑰 = 𝒉 [𝒇(𝒂) + ∆𝒇(𝒂) − 𝒉 𝒇 (𝝃)]
𝟐 𝟏𝟐
𝟏 𝟏 𝟏 𝟐 ′′
→ 𝑰 = 𝒉 [𝒇(𝒂) + 𝒇(𝒃) − 𝒇(𝒂)] − 𝒉 𝒇 (𝝃)
𝟐 𝟐 𝟏𝟐
Page 29 of 55
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

𝟏 𝟏 𝟐 ′′
→ 𝑰 = (𝒃 − 𝒂) [𝒇(𝒂) + 𝒇(𝒃)] − 𝒉 𝒇 (𝝃)
𝟐 𝟏𝟐
𝟏 𝟐 ′′
𝑬𝒓𝒓𝒐𝒓 = 𝒉 𝒇 (𝝃)
𝟏𝟐
Note that:
𝑬𝒓𝒓𝒐𝒓 → 𝟎 𝒂𝒔 𝒉 = (𝒃 − 𝒂) → 𝟎
𝑬𝒓𝒓𝒐𝒓 → 𝟎 𝒊𝒇 𝒇(𝒙) 𝒊𝒔 𝒍𝒊𝒏𝒆𝒂𝒓 (𝒊. 𝒆. , 𝒇′′ (𝝃) = 𝟎, 𝒂 < 𝝃 < 𝒃)

Graphical depiction of the trapezoidal rule.


Example:
Use the trapezoidal rule to numerically integrate
𝒇(𝒙) = 𝟎. 𝟐 + 𝟐𝟓𝒙 − 𝟐𝟎𝟎𝒙𝟐 + 𝟔𝟕𝟓𝒙𝟑 − 𝟗𝟎𝟎𝒙𝟒 + 𝟒𝟎𝟎𝒙𝟓
𝒇𝒓𝒐𝒎 𝒂 = 𝟎 𝒕𝒐 𝒃 = 𝟎. 𝟖
Solution:
𝒃 𝒃
𝟏
𝑰 = ∫ 𝒇(𝒙)𝒅𝒙 ≅ ∫ 𝒇𝟏 (𝒙)𝒅𝒙 = (𝒃 − 𝒂) [𝒇(𝒂) + 𝒇(𝒃)]
𝟐
𝒂 𝒂

𝒇(𝒂) = 𝒇(𝟎) = 𝟎. 𝟐, 𝒇(𝒃) = 𝒇(𝟎. 𝟖) = 𝟎. 𝟐𝟑𝟐


𝟏
𝑰 = (𝟎. 𝟖 − 𝟎) × × (𝟎. 𝟐 + 𝟎. 𝟐𝟑𝟐) = 𝟎. 𝟏𝟕𝟐𝟖
𝟐
Exact answer:
𝒃 𝟎.𝟖

𝑰𝒆𝒙𝒂𝒄𝒕 = ∫ 𝒇(𝒙)𝒅𝒙 = ∫ (𝟎. 𝟐 + 𝟐𝟓𝒙 − 𝟐𝟎𝟎𝒙𝟐 + 𝟔𝟕𝟓𝒙𝟑 − 𝟗𝟎𝟎𝒙𝟒 + 𝟒𝟎𝟎𝒙𝟓 ) 𝒅𝒙


𝒂 𝟎

𝑰𝒆𝒙𝒂𝒄𝒕 = 𝟏. 𝟔𝟒𝟎𝟓𝟑𝟑
True error:
Page 30 of 55
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

𝑬𝒕 = 𝟏. 𝟔𝟒𝟎𝟓𝟑𝟑 − 𝟎. 𝟏𝟕𝟐𝟖 = 𝟏. 𝟒𝟔𝟕𝟕𝟑𝟑


Approximate error:
𝟏 𝟐 ′′
𝑬𝒂 = − 𝒉 𝒇 (𝒙), 𝟎 < 𝒙 < 𝟎. 𝟖
𝟏𝟐
𝒇′′ (𝒙) = −𝟒𝟎𝟎 + 𝟒𝟎𝟓𝟎𝒙 − 𝟏𝟎𝟖𝟎𝟎𝒙𝟐 + 𝟖𝟎𝟎𝟎𝒙𝟑
Find an average value of 𝒇′′ (𝒙) over the given interval:
𝟎.𝟖 𝟎.𝟖
∫𝟎 𝒇′′ (𝒙)𝒅𝒙 ∫𝟎 (−𝟒𝟎𝟎 + 𝟒𝟎𝟓𝟎𝒙 − 𝟏𝟎𝟖𝟎𝟎𝒙𝟐 + 𝟖𝟎𝟎𝟎𝒙𝟑 )𝒅𝒙
̅̅
𝒇̅̅
′′ (𝒙) = = = −𝟔𝟎
𝟎. 𝟖 − 𝟎 𝟎. 𝟖 − 𝟎
𝟏 𝟏
𝑬𝒂 = − 𝒉𝟐 𝒇′′ (𝒙) = − (𝟎. 𝟖 − 𝟎)𝟐 (−𝟔𝟎) = 𝟐. 𝟓𝟔
𝟏𝟐 𝟏𝟐

𝑬𝒂 is of the same order of magnitude of 𝑬𝒕 .


The reason for this large error is evident from the graphical depiction below:

Page 31 of 55
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

The Multiple-Application Trapezoidal Rule


 One way to improve the accuracy of the
trapezoidal rule is to divide the integration
interval from a to b into a number of
segments and apply the method to each
segment.
 The areas of individual segments can then
be added to yield the integral for the entire
interval. The resulting equations are called
multiple-application, or composite,
integration formulas.

Page 32 of 55
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

The general format


and nomenclature
used to characterize
multiple-application
integrals is shown in
the figure   

Divide the whole


interval (a, b) into n
segments of equal
width h:

𝒃 − 𝒂 𝒙𝒏 − 𝒙𝒐
𝒉= =
𝒏 𝒏
 We have (n+1)
equally spaced
base points:
𝒙𝒐 , 𝒙𝟏 , 𝒙𝟐 , … , 𝒙𝒏

The general format and nomenclature for multiple-application integrals.

The total integral can be represented as:

𝒃−𝒂
With 𝒉 = , the above equation is re-written as:
𝒏

Page 33 of 55
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

An error for the multiple-application trapezoidal rule can be obtained by


summing the individual errors for each segment to give:

The result above can be simplified by estimating the mean or average value of the
second derivative for the entire interval as:

Therefor:

Page 34 of 55
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

Example:

Multiple Application – Trapezoidal Rule


Use the two-segment trapezoidal rule to estimate the integral of
𝒇(𝒙) = 𝟎. 𝟐 + 𝟐𝟓𝒙 − 𝟐𝟎𝟎𝒙𝟐 + 𝟔𝟕𝟓𝒙𝟑 − 𝟗𝟎𝟎𝒙𝟒 + 𝟒𝟎𝟎𝒙𝟓
from 𝒂 = 𝟎 𝒕𝒐 𝒃 = 𝟎. 𝟖, and estimate the error. Recall: the exact value of the
integral is 1.640533.
Solution:
𝒏 = 𝟐 (𝒉 = 𝟎. 𝟒)
𝒇(𝟎) = 𝟎. 𝟐, 𝒇(𝟎. 𝟒) = 𝟐. 𝟒𝟓𝟔, 𝒇(𝟎. 𝟖) = 𝟎. 𝟐𝟑𝟐

𝟎. 𝟐 + 𝟐 × 𝟐. 𝟒𝟓𝟔 + 𝟎. 𝟐𝟑𝟐
𝑰 = (𝟎. 𝟖) = 𝟏. 𝟎𝟔𝟖𝟖
𝟐×𝟐

𝑬𝒕 = 𝟏. 𝟔𝟒𝟎𝟓𝟑𝟑 − 𝟏. 𝟎𝟔𝟖𝟖 = 𝟎. 𝟓𝟕𝟏𝟕𝟑, ∈𝒕 = 𝟑𝟒. 𝟗%

𝟎.𝟖
(𝒃 − 𝒂)𝟑 ′′ ′′ ∫𝟎 𝒇′′ (𝒙)𝒅𝒙
𝑬𝒂 = − 𝒇̅ , ̅̅
𝒇̅̅(𝒙) = − 𝟔𝟎
𝟏𝟐𝒏𝟐 𝟎. 𝟖 − 𝟎
(𝟎. 𝟖)𝟑
𝑬𝒂 = − (−𝟔𝟎) = 𝟎. 𝟔𝟒
𝟏𝟐 × 𝟐𝟐

 Applying the trapezoidal rule with finer segmentation improves the


estimate of the integral.

Page 35 of 55
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

Simpson’s Rules

To obtain more accurate estimates of integrals, higher-order polynomials to


connect the points can be used.
 If there is an extra point midway between f(a) and f(b), the three

points can be connected with a parabola (Figure below) Simpson’s 1/3 Rule

Graphical depiction of Simpson’s 1/3 rule: It consists of taking the area under a parabola
connecting three points.

 If there are extra two points equally spaced between f(a) and f(b), the four

points can be connected with a third order polynomial (Figure below)


Simpson’s 3/8 Rule

Graphical depiction of Simpson’s 3/8 rule: It consists of taking the area under a third order
polynomial connecting four points.

Page 36 of 55
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

Simpson’s 1/3 Rule


2nd order polynomial is used to approximate 𝒇(𝒙):
𝒃 𝒃 𝒙𝟐

𝑰 = ∫ 𝒇(𝒙)𝒅𝒙 ≅ ∫ 𝒇𝟐 (𝒙)𝒅𝒙 = ∫ 𝒇𝟐 (𝒙)𝒅𝒙


𝒂 𝒂 𝒙𝒐

Newton – Gregory Formula (3rd order, NOT 2nd order!):


𝜶(𝜶 − 𝟏) 𝟐 𝜶(𝜶 − 𝟏)(𝜶 − 𝟐) 𝟑
𝒇𝟑 (𝒙) = 𝒇(𝒙𝒐 ) + 𝜶∆𝒇(𝒙𝒐 ) + ∆ 𝒇(𝒙𝒐 ) + ∆ 𝒇(𝒙𝒐 )
𝟐! 𝟑!
𝜶(𝜶 − 𝟏)(𝜶 − 𝟐) … . (𝜶 − 𝟑) 𝟒 (𝟒)
+ 𝒉 𝒇 (𝝃)
𝟒!
𝒙 − 𝒙𝒐
𝜶=
𝒉

Integrate:

Page 37 of 55
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

Note: The coefficient of the third divided difference is zero. This is why we used
4th order polynomial.

With 𝒉 = (𝒃 − 𝒂)/𝟐:

Truncation Error:

Page 38 of 55
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

With 𝒉 = (𝒃 − 𝒂)/𝟐:

Example:

Single Application of Simson’s 1/3 Rule


Use Simson’s 1/3 rule to estimate the integral of
𝒇(𝒙) = 𝟎. 𝟐 + 𝟐𝟓𝒙 − 𝟐𝟎𝟎𝒙𝟐 + 𝟔𝟕𝟓𝒙𝟑 − 𝟗𝟎𝟎𝒙𝟒 + 𝟒𝟎𝟎𝒙𝟓
from 𝒂 = 𝟎 𝒕𝒐 𝒃 = 𝟎. 𝟖, and estimate the error. Recall: the exact value of the
integral is 1.640533.
Solution:
𝒇(𝟎) = 𝟎. 𝟐, 𝒇(𝟎. 𝟒) = 𝟐. 𝟒𝟓𝟔, 𝒇(𝟎. 𝟖) = 𝟎. 𝟐𝟑𝟐

𝒇(𝒙𝒐 ) + 𝟒𝒇(𝒙𝟏 ) + 𝒇(𝒙𝟐 ) 𝟎. 𝟐 + 𝟒 × 𝟐. 𝟒𝟓𝟔 + 𝟎. 𝟐𝟑𝟐


𝑰 = (𝒃 − 𝒂) = (𝟎. 𝟖)
𝟔 𝟔
= 𝟏. 𝟑𝟔𝟕𝟒𝟔𝟕
𝑬𝒕 = 𝟏. 𝟔𝟒𝟎𝟓𝟑𝟑 − 𝟏. 𝟑𝟔𝟕𝟒𝟔𝟕 = 𝟎. 𝟐𝟕𝟑𝟎𝟔𝟔𝟕, ∈𝒕 = 𝟏𝟔. 𝟔%

𝟎.𝟖
(𝒃 − 𝒂)𝟓 ̅̅̅̅̅ ̅̅̅̅̅ ∫𝟎 𝒇(𝟒) (𝒙)𝒅𝒙
𝑬𝒂 = − 𝒇(𝟒) (𝝃), (𝟒)
𝒇 (𝝃) = = −𝟐𝟒𝟎𝟎
𝟐𝟖𝟖𝟎 𝟎. 𝟖 − 𝟎
(𝟎. 𝟖)𝟓
𝑬𝒂 = − (−𝟐𝟒𝟎𝟎) = 𝟎. 𝟐𝟕𝟑𝟎𝟔𝟔𝟕
𝟐𝟖𝟖𝟎
Note that 𝑬𝒂 = 𝑬𝒕 𝒇𝒐𝒓 𝒕𝒉𝒊𝒔 𝒆𝒙𝒂𝒎𝒑𝒍𝒆. Explain why?

Page 39 of 55
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

The Multiple-Application Simpson’s 1/3 Rule


Simpson’s rule can be improved by dividing the integration interval into n
segments of equal width h:
𝒃−𝒂
𝒉= , 𝒏 ≡ 𝒏𝒐. 𝒐𝒇 𝒔𝒆𝒈𝒎𝒆𝒏𝒕𝒔 (𝑬𝒗𝒆𝒏 𝒏𝒖𝒎𝒃𝒆𝒓; 𝟐, 𝟒, 𝟔, 𝟖, … . )
𝒏

Graphical representation of the multiple application of Simpson’s 1/3 rule. The method can be
employed only if the number of segments is even.

Combining terms and using 𝒉 = (𝒃 − 𝒂)/𝒏:

Page 40 of 55
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

An error estimate for the multiple-application Simpson’s rule is obtained by


summing the individual errors for the segments and averaging the derivative to
yield:

Example:
Use the Multiple-Application Version of Simpson’s 1/3 Rule with n = 4 to estimate
the integral of

Page 41 of 55
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

Simpson’s 3/8 Rule


3rd order polynomial is used to approximate 𝒇(𝒙):
𝒃 𝒃 𝒙𝟑

𝑰 = ∫ 𝒇(𝒙)𝒅𝒙 ≅ ∫ 𝒇𝟑 (𝒙)𝒅𝒙 = ∫ 𝒇𝟑 (𝒙)𝒅𝒙


𝒂 𝒂 𝒙𝒐

This yields:

𝟑𝒉
𝑰= [𝒇(𝒙𝒐 ) + 𝟑𝒇(𝒙𝟏 ) + 𝟑𝒇(𝒙𝟐 ) + 𝒇(𝒙𝟑 )]
𝟖
And with 𝒉 = (𝒃 − 𝒂)/𝟑, above equation is re-written as:

Simpson’s 3/8 rule has an error of:

OR:

Page 42 of 55
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

Example:
Use the Simpson’s 3/8 rule to estimate the integral of

Page 43 of 55
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

HW Problem Set 6 (Numerical Integration)


Problem 1

Problem 2
Compute the integral:
𝟏

𝑰 = ∫ 𝒙𝟐 𝒆𝒙 𝒅𝒙
𝟎

1. Using the trapezoidal rule with 𝒏 = 𝟏, 𝟐, 𝟒


2. Using Simpson’s 1/3 rule with 𝒏 = 𝟏, 𝟒
3. Using Simson’s 3/8 rule

Page 44 of 55
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

Richardson’s Extrapolation
An iterative technique to improve the accuracy of numerical
integration/differentiation. Two estimates are used to compute a third, more
accurate solution.
Using multiple trapezoidal rule to evaluate the integral:
𝒃

𝑰 = ∫ 𝒇(𝒙)𝒅𝒙 (𝟏)
𝒂

With
𝒃−𝒂
𝒉=
𝒏
The integration above can be written as:
𝑰 = 𝑰(𝒉) + 𝑬(𝒉) (𝟐)
Where:
𝑰(𝒉) ≡ 𝒕𝒉𝒆 𝒂𝒑𝒑𝒓𝒐𝒙𝒊𝒎𝒂𝒕𝒊𝒐𝒏 𝒇𝒓𝒐𝒎 𝒕𝒉𝒆 𝒎𝒖𝒍𝒕𝒊𝒑𝒍𝒆 𝒕𝒓𝒂𝒑𝒆𝒛𝒐𝒊𝒅𝒂𝒍 𝒓𝒖𝒍𝒆.
𝑬(𝒉) ≡ 𝑻𝒉𝒆 𝒕𝒓𝒖𝒏𝒄𝒂𝒕𝒊𝒐𝒏 𝒆𝒓𝒓𝒐𝒓
Now, take two separate steps with segment sizes 𝒉𝟏 , 𝒉𝟐 :
𝒃−𝒂 𝒃−𝒂
𝒉𝟏 = , 𝒉𝟐 =
𝒏𝟏 𝒏𝟐
→ 𝑰 = 𝑰(𝒉𝟏 ) + 𝑬(𝒉𝟏 ) = 𝑰(𝒉𝟐 ) + 𝑬(𝒉𝟐 ) (𝟑)
(𝒃 − 𝒂)𝟑 ′′ (𝒃 − 𝒂)𝟑 𝟐 ′′
𝑬≅− ̅̅̅̅
𝒇 =− 𝒉 ̅̅
𝒇̅̅
𝟏𝟐𝒏𝟐 𝟏𝟐
𝑬(𝒉𝟏 ) (𝒃 − 𝒂)𝟑 𝒉𝟐𝟏 /𝟏𝟐 ̅̅
𝒇̅̅
′′
𝟏 ̅̅
= , 𝒇̅̅
′′ ̅̅̅̅
𝟏 = 𝒇𝟐
′′
(𝟒)
𝟑 𝟐
𝑬(𝒉𝟐 ) (𝒃 − 𝒂) 𝒉𝟐 /𝟏𝟐 𝒇𝟐̅̅̅̅
′′

𝒉𝟐𝟏
𝑬(𝒉𝟏 ) = 𝟐 𝑬(𝒉𝟐 ) (𝟓)
𝒉𝟐
Substitute (5) in (3):
𝒉𝟐𝟏
𝑰(𝒉𝟏 ) + 𝟐 𝑬(𝒉𝟐 ) = 𝑰(𝒉𝟐 ) + 𝑬(𝒉𝟐 ) (𝟔)
𝒉𝟐
Solve (6) for 𝑬(𝒉𝟐 ):
𝑰(𝒉𝟏 ) − 𝑰(𝒉𝟐 )
→ 𝑬(𝒉𝟐 ) ≅ (𝟕)
𝟏 − (𝒉𝟏 ⁄𝒉𝟐 )𝟐
Page 45 of 55
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

Substitute (7) in (3):

𝟏
𝑰 = 𝑰(𝒉𝟐 ) + [𝑰(𝒉𝟐 ) − 𝑰(𝒉𝟏 )] (8)
(𝒉𝟏 ⁄𝒉𝟐 )𝟐 − 𝟏

Equation (8) applies also to derivatives:

𝟏
𝑫 = 𝑫(𝒉𝟐 ) + [𝑫(𝒉𝟐 ) − 𝑫(𝒉𝟏 )] (𝟗)
(𝒉𝟏 ⁄𝒉𝟐 )𝟐 − 𝟏

Example:
Given 𝒇(𝒙) = 𝒙𝟑 + 𝟐𝒙𝟐 + 𝟏
1. Compute numerically 𝒇′ (𝟏) using central difference, with 𝒉𝟏 = ∆𝒙𝟏 =
𝟎. 𝟐, 𝒂𝒏𝒅 𝒉𝟐 = ∆𝒙𝟐 = 𝟎. 𝟏
2. Use Richardson’s extrapolation to find a better estimate of 𝒇′ (𝟏) using the
results of part 1.

Solution:
Part 1
𝒇(𝟏. 𝟐) − 𝒇(𝟎. 𝟖) 𝟓. 𝟔𝟎𝟖 − 𝟐. 𝟕𝟗𝟐
𝒉𝟏 = 𝟎. 𝟐: 𝒇′ (𝟏) = = = 𝟕. 𝟎𝟒 ≡ 𝑫(𝒉𝟏 )
𝟐 × 𝟎. 𝟐 𝟎. 𝟒
𝒇(𝟏. 𝟏) − 𝒇(𝟎. 𝟗) 𝟒. 𝟕𝟓𝟏 − 𝟑. 𝟑𝟒𝟗
𝒉𝟐 = 𝟎. 𝟏: 𝒇′ (𝟏) = = = 𝟕. 𝟎𝟏 ≡ 𝑫(𝒉𝟐 )
𝟐 × 𝟎. 𝟏 𝟎. 𝟐

Part 2
𝟏
𝑫 = 𝑫(𝒉𝟐 ) + [𝑫(𝒉𝟐 ) − 𝑫(𝒉𝟏 )]
(𝒉𝟏 ⁄𝒉𝟐 )𝟐 − 𝟏

𝟏
𝑫 = 𝟕. 𝟎𝟏 + [𝟕. 𝟎𝟏 − 𝟕. 𝟎𝟒]
(𝟎. 𝟐⁄𝟎. 𝟏)𝟐 − 𝟏

𝟏
𝑫 = 𝟕. 𝟎𝟏 + [𝟕. 𝟎𝟏 − 𝟕. 𝟎𝟒] = 𝟕. 𝟎𝟏 − 𝟎. 𝟎𝟏 = 𝟕. 𝟎
𝟒−𝟏
Exact Solution:

𝒇′ (𝒙) = 𝟑𝒙𝟐 + 𝟒𝒙, 𝒇′ (𝟏) = 𝟑 + 𝟒 = 𝟕

Comparing the results with the exact solution: The 3rd estimate is more accurate
than 𝑫(𝒉𝟏 ) and 𝑫(𝒉𝟐 ).

Page 46 of 55
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

In Equations (8) or (9):


If 𝑰(𝒉𝟏 ) and 𝑰(𝒉𝟐 ) are both 𝑶(𝒉𝟐 )
The solution given by Equation 8 (and 9): I (and D) is 𝑶(𝒉𝟒 )
For 𝒉𝟐 = 𝒉𝟏 /𝟐:
𝟏
𝑰 = 𝑰(𝒉𝟐 ) + [𝑰(𝒉𝟐 ) − 𝑰(𝒉𝟏 )] + 𝑶(𝒉𝟒 )
𝟐𝟐 − 𝟏
𝟒 𝟏
𝑰= 𝑰(𝒉𝟐 )
⏟ − 𝑰(𝒉𝟏 ) + 𝑶(𝒉𝟒 )

𝟑 𝟑
𝒎𝒐𝒓𝒆 𝒂𝒄𝒄𝒖𝒓𝒂𝒕𝒆 𝒍𝒆𝒔𝒔 𝒂𝒄𝒄𝒖𝒓𝒂𝒕𝒆

𝑪𝒐𝒎𝒃𝒊𝒏𝒆 𝟐 𝑶(𝒉𝟐 )𝒂𝒑𝒑𝒓𝒐𝒙𝒊𝒎𝒂𝒕𝒊𝒐𝒏𝒔 → 𝒈𝒆𝒕 𝒂𝒏 𝑶(𝒉𝟒 ) 𝒂𝒑𝒑𝒓𝒐𝒙𝒊𝒎𝒂𝒕𝒊𝒐𝒏


𝑪𝒐𝒎𝒃𝒊𝒏𝒆 𝟐 𝑶(𝒉𝟒 )𝒂𝒑𝒑𝒓𝒐𝒙𝒊𝒎𝒂𝒕𝒊𝒐𝒏𝒔 → 𝒈𝒆𝒕 𝒂𝒏 𝑶(𝒉𝟔 ) 𝒂𝒑𝒑𝒓𝒐𝒙𝒊𝒎𝒂𝒕𝒊𝒐𝒏
𝑪𝒐𝒎𝒃𝒊𝒏𝒆 𝟐 𝑶(𝒉𝟔 )𝒂𝒑𝒑𝒓𝒐𝒙𝒊𝒎𝒂𝒕𝒊𝒐𝒏𝒔 → 𝒈𝒆𝒕 𝒂𝒏 𝑶(𝒉𝟖 ) 𝒂𝒑𝒑𝒓𝒐𝒙𝒊𝒎𝒂𝒕𝒊𝒐𝒏
Example:
Given
𝒇(𝒙) = 𝟎. 𝟐 + 𝟐𝟓𝒙 − 𝟐𝟎𝟎𝒙𝟐 + 𝟔𝟕𝟓𝒙𝟑 − 𝟗𝟎𝟎𝒙𝟒 + 𝟒𝟎𝟎𝒙𝟓
1. Use the trapezoidal rule to estimate the integral of 𝒇(𝒙) from 𝒂 = 𝟎 𝒕𝒐 𝒃 = 𝟎. 𝟖,
with 𝒏 = 𝟏, 𝟐, 𝟒.
2. Use the result in part (1) to get a more accurate estimate of the integral using
Richardson’s extrapolation.
Recall: the exact value of the integral is 1.640533.

Solution:
Part 1:
𝒏 = 𝟏 (𝒉 = 𝟎. 𝟖)
𝒇(𝟎) = 𝟎. 𝟐, 𝒇(𝟎. 𝟖) = 𝟎. 𝟐𝟑𝟐

𝟎. 𝟐 + 𝟎. 𝟐𝟑𝟐
𝑰 = (𝟎. 𝟖) = 𝟎. 𝟏𝟕𝟐𝟖, ∈𝒕 = 𝟖𝟗. 𝟓%
𝟐
𝒏 = 𝟐 (𝒉 = 𝟎. 𝟒)
𝒇(𝟎) = 𝟎. 𝟐, 𝒇(𝟎. 𝟒) = 𝟐. 𝟒𝟓𝟔, 𝒇(𝟎. 𝟖) = 𝟎. 𝟐𝟑𝟐

𝟎. 𝟐 + 𝟐 × 𝟐. 𝟒𝟓𝟔 + 𝟎. 𝟐𝟑𝟐
𝑰 = (𝟎. 𝟖) = 𝟏. 𝟎𝟔𝟖𝟖, ∈𝒕 = 𝟑𝟒. 𝟗%
𝟐×𝟐
Page 47 of 55
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

𝒏 = 𝟒 (𝒉 = 𝟎. 𝟐)
𝒇(𝒙𝒐 ) + 𝟐𝒇(𝒙𝟏 ) + 𝟐𝒇(𝒙𝟐 ) + 𝟐𝒇(𝒙𝟑 ) + 𝒇(𝒙𝟒 )
𝑰 = (𝒃 − 𝒂)
𝟖
𝒇(𝟎) + 𝟐𝒇(𝟎. 𝟐) + 𝟐𝒇(𝟎. 𝟒) + 𝟐𝒇(𝟎. 𝟔) + 𝒇(𝟎. 𝟖)
𝑰 = (𝟎. 𝟖) = 𝟏. 𝟒𝟖𝟒𝟖
𝟖
∈𝒕 = 𝟗. 𝟓%
Part 2:
Using the first and second estimates:
𝟒 𝟏
𝑰= (𝟏. 𝟎𝟔𝟖𝟖) − (𝟎. 𝟏𝟕𝟐𝟖) = 𝟏. 𝟑𝟔𝟕𝟒𝟔𝟔𝟔𝟕, ∈𝒕 = 𝟏𝟔. 𝟔𝟒 %
𝟑 𝟑
Using the second and third estimates:
𝟒 𝟏
𝑰= (𝟏. 𝟒𝟖𝟒𝟖) − (𝟏. 𝟎𝟔𝟖𝟖) = 𝟏. 𝟔𝟐𝟑𝟒𝟔𝟔𝟔𝟕, ∈𝒕 = 𝟏. 𝟎𝟒 %
𝟑 𝟑
--------------------------------------------------------------------------------------------------------
Note:
For Richardson’s Extrapolation:
𝟏
𝑰 = 𝑰(𝒉𝟐 ) + [𝑰(𝒉𝟐 ) − 𝑰(𝒉𝟏 )]
(𝒉𝟏 ⁄𝒉𝟐 )𝟐 − 𝟏
For 𝒉𝟐 = 𝒉𝟏 /𝟐:
𝟒 𝟏
𝑰= 𝑰⏟
𝒎 − 𝑰⏟𝒍
𝟑 𝟑
𝒎𝒐𝒓𝒆 𝒂𝒄𝒄𝒖𝒓𝒂𝒕𝒆 𝒍𝒆𝒔𝒔 𝒂𝒄𝒄𝒖𝒓𝒂𝒕𝒆

For 𝒉𝟐 = 𝒉𝟏 /𝟒:
𝟏𝟔 𝟏
𝑰= 𝑰⏟
𝒎 − 𝑰⏟𝒍
𝟏𝟓 𝟏𝟓
𝒎𝒐𝒓𝒆 𝒂𝒄𝒄𝒖𝒓𝒂𝒕𝒆 𝒍𝒆𝒔𝒔 𝒂𝒄𝒄𝒖𝒓𝒂𝒕𝒆

For 𝒉𝟐 = 𝒉𝟏 /𝟖:
𝟔𝟒 𝟏
𝑰= 𝑰⏟
𝒎 − 𝑰⏟𝒍
𝟔𝟑 𝟔𝟑
𝒎𝒐𝒓𝒆 𝒂𝒄𝒄𝒖𝒓𝒂𝒕𝒆 𝒍𝒆𝒔𝒔 𝒂𝒄𝒄𝒖𝒓𝒂𝒕𝒆

Page 48 of 55
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

Gauss Quadrature – Gauss Legendre Formulas


To compute:
𝒃

𝑰 = ∫ 𝒇(𝒙)𝒅𝒙
𝒂

Using trapezoidal rule:


𝟏
𝑰 = (𝒃 − 𝒂) [𝒇(𝒂) + 𝒇(𝒃)]
𝟐
𝒃−𝒂 𝒃−𝒂
𝑰= 𝒇(𝒂) + 𝒇(𝒃)
𝟐 𝟐
Trapezoidal rule uses fixed end points; a, b.

(a) Graphical depiction of the trapezoidal rule as the area under the straight line joining fixed end
points.
(b) An improved integral estimate obtained by taking the area under the straight line passing
through two intermediate points. By positioning these points wisely, the positive and negative
errors are balanced, and an improved integral estimate results.

Page 49 of 55
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

With Gauss Quadrature (Gauss-Legendre), these points float:


𝟏

𝑰 = ∫ 𝒇(𝒙)𝒅𝒙 = 𝑪𝒐 𝒇(𝒙𝒐 ) + 𝑪𝟏 𝒇(𝒙𝟏 )


−𝟏

Note that the integration limits are from -1 to 1 rather than a to b.


To simplify the math of evaluating the integral
𝒃

𝑰 = ∫ 𝒇(𝒙)𝒅𝒙
𝒂

Use transformation of variables , so that instead of integrating from a to b,


integration is from -1 to 1.
Linear Transformation:
𝝃 = 𝒌𝟏 + 𝒌𝟐 𝒙 → 𝒅𝝃 = 𝒌𝟐 𝒅𝒙
𝒙 = 𝒂: 𝝃 = −𝟏, → −𝟏 = 𝒌𝟏 + 𝒌𝟐 𝒂
𝒙 = 𝒃: 𝝃 = 𝟏, → 𝟏 = 𝒌 𝟏 + 𝒌𝟐 𝒃
Solve above equations for 𝒌𝟏 , 𝒌𝟐 :
−𝒃 − 𝒂 𝟐
𝒌𝟏 = , 𝒌𝟐 =
𝒃−𝒂 𝒃−𝒂
𝒃 𝟏 𝟏
𝟏
→ 𝑰 = ∫ 𝒇(𝒙)𝒅𝒙 = ∫ 𝒇(𝝃) 𝒅𝝃 = ∫ 𝒈(𝝃)𝒅𝝃
𝒌𝟐
𝒂 −𝟏 −𝟏

As opposed to the trapezoidal rule using fixed end points; a, b, in Gauss


Quadrature, these points float:
𝟏

𝑰 = ∫ 𝒇(𝒙)𝒅𝒙 = 𝑪𝒐 𝒇(𝒙𝒐 ) + 𝑪𝟏 𝒇(𝒙𝟏 )


−𝟏

𝑪𝒐 , 𝑪𝟏 : 𝒘𝒆𝒊𝒈𝒉𝒕 𝒇𝒂𝒄𝒕𝒐𝒓
𝒙𝒐 , 𝒙𝟏 : 𝒇𝒖𝒏𝒄𝒕𝒊𝒐𝒏 𝒂𝒓𝒈𝒖𝒎𝒆𝒏𝒕𝒔
In the above equation, we have 4 unknowns: 𝑪𝒐 , 𝒙𝒐 , 𝑪𝟏 , 𝒙𝟏
Find 𝑪𝒐 , 𝒙𝒐 , 𝑪𝟏 , 𝒙𝟏 such that the above integral is exact when the function 𝒇(𝒙) is
up to third order polynomial;
𝒇(𝒙) = 𝒙𝟎 , 𝒙𝟏 , 𝒙𝟐 , 𝒙𝟑
Page 50 of 55
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

𝒇(𝒙) = 𝟏, → 𝑪𝒐 𝒇(𝟏) + 𝑪𝟏 𝒇(𝟏) = ∫ 𝟏. 𝒅𝒙 = 𝟐


−𝟏

𝑪𝒐 + 𝑪𝟏 = 𝟐
𝟏 𝟏
𝒙𝟐
𝒇(𝒙) = 𝒙, → 𝑪𝒐 𝒙𝒐 + 𝑪𝟏 𝒙𝟏 = ∫ 𝒙. 𝒅𝒙 = [ ] = 𝟎
𝟐 −𝟏
−𝟏

𝑪𝒐 𝒙𝒐 + 𝑪𝟏 𝒙𝟏 = 𝟎
𝟏 𝟏
𝒙𝟑 𝟐
𝒇(𝒙) = 𝒙 , → 𝟐
𝑪𝒐 𝒙𝟐𝒐 + 𝑪𝟏 𝒙𝟐𝟏 𝟐
= ∫ 𝒙 . 𝒅𝒙 = [ ] =
𝟑 −𝟏 𝟑
−𝟏
𝟐
𝑪𝒐 𝒙𝟐𝒐 + 𝑪𝟏 𝒙𝟐𝟏 =
𝟑
𝟏 𝟏
𝟑 𝟑 𝟑 𝟑
𝒙𝟒
𝒇(𝒙) = 𝒙 , → 𝑪𝒐 𝒙𝒐 + 𝑪𝟏 𝒙𝟏 = ∫ 𝒙 . 𝒅𝒙 = [ ] = 𝟎
𝟒 −𝟏
−𝟏

𝑪𝒐 𝒙𝟑𝒐 + 𝑪𝟏 𝒙𝟑𝟏 = 𝟎
Solve above equations for 𝑪𝒐 , 𝒙𝒐 , 𝑪𝟏 , 𝒙𝟏 :
−𝟏 𝟏
𝑪𝒐 = 𝟏, 𝑪𝟏 = 𝟏, 𝒙𝒐 = , 𝒙𝟏 =
√𝟑 √𝟑

𝑰 = ∫ 𝒇(𝒙)𝒅𝒙 = 𝟏. 𝒇(−𝟏/√𝟑) + 𝟏. 𝒇(𝟏/√𝟑) Exact for up to 3rd order


−𝟏 polynomial

Example:
Use the two-point Gauss -Legendre formula to evaluate the integral:
𝟒

𝑰 = ∫(𝒙𝟑 + 𝟐𝒙) 𝒅𝒙
𝟎

Exact solution:
𝟒 𝟒
𝒙𝟒
𝑰 = ∫(𝒙 + 𝟐𝒙) 𝒅𝒙 = [ + 𝒙𝟐 ] = 𝟖𝟎
𝟑
𝟒 𝟎
𝟎

Using Gauss Quadrature:


Page 51 of 55
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

Before integrating the function using Gauss Quadrature formula, we must


perform a change of variable so that the limits are from -1 to 1:
𝝃 = 𝒌𝟏 + 𝒌𝟐 𝒙
𝒂 = 𝟎, 𝒃 = 𝟒
−𝒃 − 𝒂 𝟐
𝒌𝟏 = , 𝒌𝟐 =
𝒃−𝒂 𝒃−𝒂
−𝟒 − 𝟎 𝟐 𝟏
𝒌𝟏 = = −𝟏, 𝒌𝟐 = =
𝟒−𝟎 𝟒−𝟎 𝟐
𝟏
𝝃 = −𝟏 + 𝒙, 𝒙 = 𝟐𝝃 + 𝟐
𝟐
𝟏
𝒅𝝃 = 𝒅𝒙
𝟐
𝟒 𝟏 𝟏

𝑰 = ∫(𝒙𝟑 + 𝟐𝒙) 𝒅𝒙 = ∫[(𝟐𝝃 + 𝟐)𝟑 + 𝟐(𝟐𝝃 + 𝟐)]. 𝟐𝒅𝝃 = ∫ 𝒇(𝝃)𝒅𝝃


𝟎 −𝟏 −𝟏

𝒇(𝝃) = 𝟐[(𝟐𝝃 + 𝟐)𝟑 + 𝟐(𝟐𝝃 + 𝟐)]


𝟏

∫ 𝒇(𝝃)𝒅𝝃 = 𝒇(−𝟏/√𝟑) + 𝒇(𝟏/√𝟑)


−𝟏

𝒇(−𝟏/√𝟑) = 𝟒. 𝟓𝟖𝟗𝟏𝟖𝟑𝟒𝟗, 𝒇(𝟏/√𝟑) = 𝟕𝟓. 𝟒𝟏𝟎𝟖𝟏𝟔𝟓𝟏

𝟏
∫−𝟏 𝒇(𝝃)𝒅𝝃 = 𝟒. 𝟓𝟖𝟗𝟏𝟖𝟑𝟒𝟗 + 𝟕𝟓. 𝟒𝟏𝟎𝟖𝟏𝟔𝟓𝟏 = 𝟖𝟎 Exact!

General Gauss - Legendre Formula:


𝟏

𝑰 = ∫ 𝒇(𝒙)𝒅𝒙 = 𝑪𝒐 𝒇(𝒙𝒐 ) + 𝑪𝟏 𝒇(𝒙𝟏 ) + ⋯ + 𝑪𝒏−𝟏 𝒇(𝒙𝒏−𝟏 )


−𝟏

𝒏: 𝒊𝒔 𝒕𝒉𝒆 𝒏𝒖𝒎𝒃𝒆𝒓 𝒐𝒇 𝒑𝒐𝒊𝒏𝒕𝒔


𝟏 𝒏−𝟏

𝑰 = ∫ 𝒇(𝒙)𝒅𝒙 = ∑ 𝑪𝒊 𝒇(𝒙𝒊 )
−𝟏 𝒊=𝟎

𝒇(𝒙) is integrated exactly with Gauss Quadrature formula for polynomials of


degree ≤ 𝟐𝒏 − 𝟏
Two-point Gauss Quadrature Formula
Page 52 of 55
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

𝒏 = 𝟐: 𝑰 = ∫ 𝒇(𝒙)𝒅𝒙 = 𝑪𝒐 𝒇(𝒙𝒐 ) + 𝑪𝟏 𝒇(𝒙𝟏 ) 𝒙𝟑


−𝟏

Three-point Gauss Quadrature Formula


𝟏

𝒏 = 𝟑: 𝑰 = ∫ 𝒇(𝒙)𝒅𝒙 = 𝑪𝒐 𝒇(𝒙𝒐 ) + 𝑪𝟏 𝒇(𝒙𝟏 ) + 𝑪𝟐 𝒇(𝒙𝟐 ) 𝒙𝟓


−𝟏

Four-point Gauss Quadrature Formula


𝟏

𝒏 = 𝟒: 𝑰 = ∫ 𝒇(𝒙)𝒅𝒙 = 𝑪𝒐 𝒇(𝒙𝒐 ) + 𝑪𝟏 𝒇(𝒙𝟏 ) + 𝑪𝟐 𝒇(𝒙𝟐 ) + 𝑪𝟑 𝒇(𝒙𝟑 ) 𝒙𝟕


−𝟏

Page 53 of 55
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

Example:
Use the three-point formula from the table above to estimate the integral for the
function:
𝒇(𝒙) = 𝟎. 𝟐 + 𝟐𝟓𝒙 − 𝟐𝟎𝟎𝒙𝟐 + 𝟔𝟕𝟓𝒙𝟑 − 𝟗𝟎𝟎𝒙𝟒 + 𝟒𝟎𝟎𝒙𝟓
From 𝒂 = 𝟎, 𝒕𝒐 𝒃 = 𝟎. 𝟖
Recall the exact answer is :
𝒃 𝟎.𝟖

𝑰𝒆𝒙𝒂𝒄𝒕 = ∫ 𝒇(𝒙)𝒅𝒙 = ∫ (𝟎. 𝟐 + 𝟐𝟓𝒙 − 𝟐𝟎𝟎𝒙𝟐 + 𝟔𝟕𝟓𝒙𝟑 − 𝟗𝟎𝟎𝒙𝟒 + 𝟒𝟎𝟎𝒙𝟓 ) 𝒅𝒙


𝒂 𝟎

𝑰𝒆𝒙𝒂𝒄𝒕 = 𝟏. 𝟔𝟒𝟎𝟓𝟑𝟑
Using three-point Gauss -Legendre (gives exact result for polynomials up to 5th
order):
𝟏

𝑰 = ∫ 𝒇(𝒙)𝒅𝒙 = 𝑪𝒐 𝒇(𝒙𝒐 ) + 𝑪𝟏 𝒇(𝒙𝟏 ) + 𝑪𝟐 𝒇(𝒙𝟐 )


−𝟏

𝝃 = 𝒌𝟏 + 𝒌𝟐 𝒙
𝒂 = 𝟎, 𝒃 = 𝟎. 𝟖
−𝒃 − 𝒂 𝟐
𝒌𝟏 = , 𝒌𝟐 =
𝒃−𝒂 𝒃−𝒂
−𝟎. 𝟖 − 𝟎 𝟐
𝒌𝟏 = = −𝟏, 𝒌𝟐 = = 𝟐. 𝟓
𝟎. 𝟖 − 𝟎 𝟎. 𝟖 − 𝟎
𝝃 = −𝟏 + 𝟐. 𝟓𝒙, 𝒙 = 𝟎. 𝟒 + 𝟎. 𝟒𝝃
𝒅𝝃 = 𝟐. 𝟓𝒅𝒙
𝒇(𝒙) = 𝟎. 𝟐 + 𝟐𝟓𝒙 − 𝟐𝟎𝟎𝒙𝟐 + 𝟔𝟕𝟓𝒙𝟑 − 𝟗𝟎𝟎𝒙𝟒 + 𝟒𝟎𝟎𝒙𝟓
𝒇(𝝃) = 𝟎. 𝟒[𝟎. 𝟐 + 𝟐𝟓(𝟎. 𝟒 + 𝟎. 𝟒𝝃) − 𝟐𝟎𝟎(𝟎. 𝟒 + 𝟎. 𝟒𝝃)𝟐 + 𝟔𝟕𝟓(𝟎. 𝟒 + 𝟎. 𝟒𝝃)𝟑
− 𝟗𝟎𝟎(𝟎. 𝟒 + 𝟎. 𝟒𝝃)𝟒 + 𝟒𝟎𝟎(𝟎. 𝟒 + 𝟎. 𝟒𝝃)𝟓 ]
𝑰 = 𝑪𝒐 𝒇(𝝃𝒐 ) + 𝑪𝟏 𝒇(𝝃𝟏 ) + 𝑪𝟐 𝒇(𝝃𝟐 )

Page 54 of 55
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan

HW Problem Set 7 (Numerical Integration)


Problem 1
Evaluate the following integrals numerically:
1. Using Simpson’s 1/3 rule with 𝒏 = 𝟐
2. Using Simpson’s 1/3 rule with 𝒏 = 𝟒
3. Apply Richardson’s extrapolation to find a new estimate of the integral
using your results in parts 1 and 2.
𝟐 𝟑
𝟏 𝟐
𝑰 = ∫ (𝒙 + ) 𝒅𝒙 , 𝑰 = ∫ 𝒙𝒆𝟐𝒙 𝒅𝒙
𝒙
𝟏 𝟎

Problem 2
Evaluate the following integrals:
1. Using three and four-point Gauss – Legendre formulas
2. Noting that the exact value is 0.966105, calculate the error.

𝟏.𝟓
𝟐 𝟐
𝑰= ∫ 𝒆−𝒙 𝒅𝒙
√𝝅
𝟎

Page 55 of 55

You might also like