Lecture Notes - Differentiation and Integration
Lecture Notes - Differentiation and Integration
The graphical definition of a derivative: as ∆𝒙 approaches zero in going from (a) to (c), the
difference approximation becomes a derivative.
(𝒙 − 𝒙𝒊 )𝟐 ′′ (𝒙 − 𝒙𝒊 )𝟑 ′′′
𝒇(𝒙) = 𝒇(𝒙𝒊 ) + (𝒙 − 𝒙𝒊 )𝒇′ (𝒙𝒊 ) + 𝒇 (𝒙 )
𝒊 + 𝒇 (𝒙𝒊 ) + ⋯
𝟐! 𝟑!
(𝒙 − 𝒙𝒊 )𝒏 (𝒏)
+ 𝒇 (𝒙𝒊 ) (𝟏)
𝒏!
Page 1 of 55
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan
∆𝒙 = 𝒙𝒊+𝟏 − 𝒙𝒊
𝒅𝒇 𝒇𝒊+𝟏 − 𝒇𝒊
𝒇′𝒊 ≡ ( ) ≅ + 𝑶(∆𝒙) (𝟒)
𝒅𝒙 𝒊 ∆𝒙
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
Page 3 of 55
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan
𝟐(∆𝒙)𝟑 ′′′
𝒇𝒊+𝟏 − 𝒇𝒊−𝟏 = 𝟐∆𝒙𝒇′𝒊 + 𝒇𝒊 + ⋯
𝟑!
𝒅𝒇
Solve for 𝒇′𝒊 ≡ ( ) :
𝒅𝒙 𝒊
𝒅𝒇 𝒇𝒊+𝟏 − 𝒇𝒊−𝟏
𝒇′𝒊 ≡ ( ) = + 𝑶(∆𝒙)𝟐
𝒅𝒙 𝒊 𝟐∆𝒙
Page 4 of 55
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan
𝒅𝒇 𝒇𝒊+𝟏 − 𝒇𝒊
𝒇′𝒊 ≡ ( ) ≅ + 𝑶(∆𝒙) 𝐅𝐨𝐫𝐰𝐚𝐫𝐝 𝐃𝐢𝐟𝐟𝐞𝐫𝐞𝐧𝐜𝐞
𝒅𝒙 𝒊 ∆𝒙
𝒅𝒇 𝒇𝒊 − 𝒇𝒊−𝟏
𝒇′𝒊 ≡ ( ) = + 𝑶(∆𝒙) 𝐁𝐚𝐜𝐤𝐰𝐚𝐫𝐝 𝐃𝐢𝐟𝐟𝐞𝐫𝐞𝐧𝐜𝐞
𝒅𝒙 𝒊 ∆𝒙
𝒅𝒇 𝒇𝒊+𝟏 − 𝒇𝒊−𝟏
𝒇′𝒊 ≡ ( ) = + 𝑶(∆𝒙)𝟐 𝐂𝐞𝐧𝐭𝐫𝐚𝐥 𝐃𝐢𝐟𝐟𝐞𝐫𝐞𝐧𝐜𝐞
𝒅𝒙 𝒊 𝟐∆𝒙
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:
𝒇′ (𝒙) = 𝟑𝟎𝒙𝟐 + 𝟏𝟎𝒙, → 𝒇′ (𝟓) = 𝟑𝟎(𝟓)𝟐 + 𝟏𝟎(𝟓) = 𝟖𝟎𝟎
Error = 1.950 %
Error = 1.925 %
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
𝟒(∆𝒙)𝟑 ′′′
𝟒𝒇𝒊+𝟏 − 𝒇𝒊+𝟐 = 𝟑𝒇𝒊 + 𝟐∆𝒙𝒇′𝒊 − 𝒇𝒊
𝟑!
Solve for 𝒇′𝒊
Page 7 of 55
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan
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:
Page 9 of 55
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan
Page 10 of 55
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan
To eliminate 𝒇′𝒊 :
𝒇𝒊 − 𝟐𝒇𝒊+𝟏 + 𝒇𝒊+𝟐
𝒇′′
𝒊 = + 𝑶(∆𝒙)
(∆𝒙)𝟐
Page 11 of 55
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan
To eliminate 𝒇′′′
𝒊 from the above equations:
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
Page 16 of 55
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan
𝟓
𝒇𝒊+𝟏 − 𝟐𝒇𝒊 + 𝒇𝒊−𝟏 − 𝒉(𝒇𝒊+𝟏 − 𝒇𝒊−𝟏 ) − 𝟔𝒉𝟐 𝒇𝒊 = 𝟎
𝟐
Re-arrange:
(𝟏 + 𝟐. 𝟓𝒉)𝒇𝒊−𝟏 − (𝟐 + 𝟔𝒉𝟐 )𝒇𝒊 + (𝟏 − 𝟐. 𝟓𝒉)𝒇𝒊+𝟏 = 𝟎
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:
𝒚′′ + 𝒂𝒚′ + 𝒃𝒚 = 𝟎, 𝒙 ∈ [𝟎, 𝑳] (𝟏)
𝒚′ (𝟎) = 𝜶, 𝒚′ (𝑳) = 𝜷 (𝟐)
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 𝒚𝒐 :
3. The boundary condition can be given in terms of the dependent variable and
its derivative:
General Form:
𝒚′ + 𝜶𝒚 = 𝜷 𝒂𝒕 𝒕𝒉𝒆 𝒃𝒐𝒖𝒏𝒅𝒂𝒓𝒚 (𝟏)
Example:
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:
𝝏𝒇 𝒇(𝒙𝒊+𝟏 , 𝒚𝒋 ) − 𝒇(𝒙𝒊 , 𝒚𝒋 ) 𝒇𝒊+𝟏,𝒋 − 𝒇𝒊,𝒋
( ) = =
𝝏𝒙 𝒊,𝒋 ∆𝒙 ∆𝒙
𝝏𝒇 𝒇(𝒙𝒊 , 𝒚𝒋+𝟏 ) − 𝒇(𝒙𝒊 , 𝒚𝒋 ) 𝒇𝒊,𝒋+𝟏 − 𝒇𝒊,𝒋
( ) = =
𝝏𝒚 𝒊,𝒋 ∆𝒚 ∆𝒚
Page 21 of 55
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan
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:
𝒃 𝒏
𝑰 = ∫ 𝒇(𝒙)𝒅𝒙 ≅ ∫ 𝒇𝒏 (𝒙)𝒅𝒙
𝒂 𝒂
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
(𝒙 − 𝒙𝒐 )𝒏+𝟏 (𝒏+𝟏)
𝑹𝒏 = 𝒇 (𝝃 ) 𝒙𝒐 < 𝝃 < 𝒙 (𝟑)
(𝒏 + 𝟏)!
𝒇[𝒙𝟑 , 𝒙𝟐 , 𝒙𝟏 ] − 𝒇[𝒙𝟐 , 𝒙𝟏 , 𝒙𝒐 ]
𝒂𝟑 = 𝒇[𝒙𝟑 , 𝒙𝟐 , 𝒙𝟏 , 𝒙𝒐 ] =
𝒙𝟑 − 𝒙𝒐
𝒇(𝒙𝟑 ) − 𝟑𝒇(𝒙𝟐 ) + 𝟑𝒇(𝒙𝟏 ) − 𝒇(𝒙𝒐 ) ∆𝟑 𝒇(𝒙𝒐 ) ∆𝟑 𝒇(𝒙𝒐 )
= = =
𝟔𝒉𝟑 𝟔𝒉𝟑 𝟑! 𝒉𝟑
∆𝟒 𝒇(𝒙𝒐 )
𝒂𝟒 =
𝟒! 𝒉𝟒
……………
……………
∆𝒏 𝒇(𝒙𝒐 )
𝒂𝒏 =
𝒏! 𝒉𝒏
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
𝑰 = ∫ 𝒇(𝒙)𝒅𝒙 = ∫ 𝒇(𝒙)𝒅𝒙
𝒂 𝒙𝒐
𝒇(𝒃) − 𝒇(𝒂)
𝑪𝟏 = (𝟒)
𝒃−𝒂
𝒃 𝒃 𝒃
𝒃
𝟏 𝟐
𝑰 = ∫ 𝒇(𝒙)𝒅𝒙 ≅ ∫ 𝒇𝟏 (𝒙)𝒅𝒙 = ∫(𝑪𝒐 + 𝑪𝟏 𝒙)𝒅𝒙 = [𝑪𝒐 𝒙 + 𝑪𝟏 𝒙 ]
𝟐 𝒂
𝒂 𝒂 𝒂
𝟏 𝟏
𝑰 = (𝑪𝒐 𝒃 + 𝑪𝟏 𝒃𝟐 ) − (𝑪𝒐 𝒂 + 𝑪𝟏 𝒂𝟐 )
𝟐 𝟐
𝟏
𝑰 = 𝑪𝒐 (𝒃 − 𝒂) + 𝑪𝟏 (𝒃𝟐 − 𝒂𝟐 ) (𝟓)
𝟐
Use (3) & (4) in (5):
Page 28 of 55
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan
𝒙 − 𝒙𝒐
𝜶= , 𝒉 = 𝒙𝒊+𝟏 − 𝒙𝒊
𝒉
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:
𝑬𝒓𝒓𝒐𝒓 → 𝟎 𝒂𝒔 𝒉 = (𝒃 − 𝒂) → 𝟎
𝑬𝒓𝒓𝒐𝒓 → 𝟎 𝒊𝒇 𝒇(𝒙) 𝒊𝒔 𝒍𝒊𝒏𝒆𝒂𝒓 (𝒊. 𝒆. , 𝒇′′ (𝝃) = 𝟎, 𝒂 < 𝝃 < 𝒃)
𝑰𝒆𝒙𝒂𝒄𝒕 = 𝟏. 𝟔𝟒𝟎𝟓𝟑𝟑
True error:
Page 30 of 55
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan
Page 31 of 55
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan
Page 32 of 55
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan
𝒃 − 𝒂 𝒙𝒏 − 𝒙𝒐
𝒉= =
𝒏 𝒏
We have (n+1)
equally spaced
base points:
𝒙𝒐 , 𝒙𝟏 , 𝒙𝟐 , … , 𝒙𝒏
𝒃−𝒂
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
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:
𝟎. 𝟐 + 𝟐 × 𝟐. 𝟒𝟓𝟔 + 𝟎. 𝟐𝟑𝟐
𝑰 = (𝟎. 𝟖) = 𝟏. 𝟎𝟔𝟖𝟖
𝟐×𝟐
𝟎.𝟖
(𝒃 − 𝒂)𝟑 ′′ ′′ ∫𝟎 𝒇′′ (𝒙)𝒅𝒙
𝑬𝒂 = − 𝒇̅ , ̅̅
𝒇̅̅(𝒙) = − 𝟔𝟎
𝟏𝟐𝒏𝟐 𝟎. 𝟖 − 𝟎
(𝟎. 𝟖)𝟑
𝑬𝒂 = − (−𝟔𝟎) = 𝟎. 𝟔𝟒
𝟏𝟐 × 𝟐𝟐
Page 35 of 55
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan
Simpson’s Rules
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
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
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:
𝟎.𝟖
(𝒃 − 𝒂)𝟓 ̅̅̅̅̅ ̅̅̅̅̅ ∫𝟎 𝒇(𝟒) (𝒙)𝒅𝒙
𝑬𝒂 = − 𝒇(𝟒) (𝝃), (𝟒)
𝒇 (𝝃) = = −𝟐𝟒𝟎𝟎
𝟐𝟖𝟖𝟎 𝟎. 𝟖 − 𝟎
(𝟎. 𝟖)𝟓
𝑬𝒂 = − (−𝟐𝟒𝟎𝟎) = 𝟎. 𝟐𝟕𝟑𝟎𝟔𝟔𝟕
𝟐𝟖𝟖𝟎
Note that 𝑬𝒂 = 𝑬𝒕 𝒇𝒐𝒓 𝒕𝒉𝒊𝒔 𝒆𝒙𝒂𝒎𝒑𝒍𝒆. Explain why?
Page 39 of 55
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan
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.
Page 40 of 55
College of Engineering, Department of Mechanical Engineering
Lecture Notes 0402307 Numerical Analysis Khalid Ramadan
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
This yields:
𝟑𝒉
𝑰= [𝒇(𝒙𝒐 ) + 𝟑𝒇(𝒙𝟏 ) + 𝟑𝒇(𝒙𝟐 ) + 𝒇(𝒙𝟑 )]
𝟖
And with 𝒉 = (𝒃 − 𝒂)/𝟑, above equation is re-written as:
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
Problem 2
Compute the integral:
𝟏
𝑰 = ∫ 𝒙𝟐 𝒆𝒙 𝒅𝒙
𝟎
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
𝟏
𝑰 = 𝑰(𝒉𝟐 ) + [𝑰(𝒉𝟐 ) − 𝑰(𝒉𝟏 )] (8)
(𝒉𝟏 ⁄𝒉𝟐 )𝟐 − 𝟏
𝟏
𝑫 = 𝑫(𝒉𝟐 ) + [𝑫(𝒉𝟐 ) − 𝑫(𝒉𝟏 )] (𝟗)
(𝒉𝟏 ⁄𝒉𝟐 )𝟐 − 𝟏
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
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
𝑰 = ∫ 𝒇(𝒙)𝒅𝒙
𝒂
(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
𝑰 = ∫ 𝒇(𝒙)𝒅𝒙
𝒂
𝑪𝒐 , 𝑪𝟏 : 𝒘𝒆𝒊𝒈𝒉𝒕 𝒇𝒂𝒄𝒕𝒐𝒓
𝒙𝒐 , 𝒙𝟏 : 𝒇𝒖𝒏𝒄𝒕𝒊𝒐𝒏 𝒂𝒓𝒈𝒖𝒎𝒆𝒏𝒕𝒔
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 𝑪𝒐 , 𝒙𝒐 , 𝑪𝟏 , 𝒙𝟏 :
−𝟏 𝟏
𝑪𝒐 = 𝟏, 𝑪𝟏 = 𝟏, 𝒙𝒐 = , 𝒙𝟏 =
√𝟑 √𝟑
Example:
Use the two-point Gauss -Legendre formula to evaluate the integral:
𝟒
𝑰 = ∫(𝒙𝟑 + 𝟐𝒙) 𝒅𝒙
𝟎
Exact solution:
𝟒 𝟒
𝒙𝟒
𝑰 = ∫(𝒙 + 𝟐𝒙) 𝒅𝒙 = [ + 𝒙𝟐 ] = 𝟖𝟎
𝟑
𝟒 𝟎
𝟎
𝟏
∫−𝟏 𝒇(𝝃)𝒅𝝃 = 𝟒. 𝟓𝟖𝟗𝟏𝟖𝟑𝟒𝟗 + 𝟕𝟓. 𝟒𝟏𝟎𝟖𝟏𝟔𝟓𝟏 = 𝟖𝟎 Exact!
𝑰 = ∫ 𝒇(𝒙)𝒅𝒙 = ∑ 𝑪𝒊 𝒇(𝒙𝒊 )
−𝟏 𝒊=𝟎
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
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