Numerical Method-Trang-1
Numerical Method-Trang-1
1. Numerical Integration
1.1. Trapezoidal Rule
𝑏
𝑓(𝑏) + 𝑓(𝑎)
𝐼 = ∫ 𝑓(𝑥)𝑑𝑥 ≈ (𝑏 − 𝑎)
𝑎 2
Error:
−(𝑏 − 𝑎)3 ′′
𝐸𝑎 = ̅̅̅̅
𝑓
12
𝑏
̅̅̅̅ 𝑓 ′′ (𝑥)
𝑓 ′′ = ∫ 𝑑𝑥
𝑎 𝑏−𝑎
𝑓(𝑥0 ) + 2 ∑𝑛−1
𝑖=1 𝑓(𝑥𝑖 ) + 𝑓(𝑥𝑛 )
𝐼 ≈ (𝑏 − 𝑎)
2𝑛
Error:
−(𝑏 − 𝑎)3 ′′
𝐸𝑎 = ̅̅̅̅
𝑓 (𝑥)
12𝑛2
Example 1.1: Use 2-segments trapezoidal rule to numerically integrate the function [𝒂, 𝒃] =
[𝟎, 𝟐]; 𝑓(𝑥) = 0.2 + 25𝑥 + 3𝑥 2
Solution:
𝑏−𝑎
𝑛 = 2; ℎ = =1
𝑛
𝑓(0) = 0.2; 𝑓(1) = 28.2; 𝑓(2) = 62.2
𝑓(𝑥0 ) + 2 ∑𝑛−1
𝑖=1 𝑓(𝑥𝑖 ) + 𝑓(𝑥𝑛 )
𝐼 ≈ (𝑏 − 𝑎) = 59.4
2𝑛
Error:
2
∫ 6𝑑𝑥
𝑓 ′′ = 0
𝑓 ′′ (𝑥) = 6, ̅̅̅̅ =6
2−0
(2 − 0)3
𝐸𝑎 = − 6 = −1
12 ∙ 22
The exact solution is 59.4 − 1 = 58.4, The relative error is 1.71%
1.2. Simpson’s Rule
Multiple-application Simpson’s rule:
𝑏 𝑚 𝑚−1
ℎ
∫ 𝑓(𝑥)𝑑𝑥 ≈ [𝑓0 + 𝑓2𝑚 + 4 ∑ 𝑓2𝑘−1 + 2 ∑ 𝑓2𝑘 ]
𝑎 3
𝑘=1 𝑘=1
Error:
−(𝑏 − 𝑎)5 (4)
𝐸𝑎 = 𝑓̅
180𝑛4
Where 𝑓 ̅(4) is the average fourth derivative for the interval. (Don’t be mistaken with 𝒇𝟒 )
𝑏
𝑓 (4) (𝑥)
𝑓 ̅(4) = ∫
𝑎 𝑏−𝑎
Example 1.2: with 𝑛 = 4, estimate the integral and error of
𝑓(𝑥) = 0.2 + 25𝑥 − 200𝑥 2 + 675𝑥 3 − 900𝑥 4 + 400𝑥 5
From 𝑎 = 0 to 𝑏 = 0.8. The exact integral is 1.640533
0.8−0
Solution: ℎ = = 0.2
4
k x f(x) 0.2
𝐼≈ [0.2 + 0.232 + 4(1.288 + 3.464) + 2(2.456)] = 1.623467
0 0 0.2 3
1 0.2 1.288 𝐸𝑡 = 1.623467 − 1.640533 = 0.017067
2 0.4 2.456 0.017067
3 0.6 3.464 𝜀𝑡 = = 1.04%
1.640533
4 0.8 0.232
0.8 48000𝑥−21600
Error: 𝑓 (4) = 48000𝑥 − 21600; 𝑓 ̅(4) = ∫0 0.8−0
= −2400
−0.85
Estimated error is 𝐸𝑎 = 180∙44 (−2400) = 0.017067
Note: Tactics to estimate the integral using Simpson's Rule: First, draw a table with
variables k, x, and f(x), incrementing by step h. Second, substitute the first and last 𝑓(𝑥) (𝒇𝟎
and 𝒇𝟐𝒎 ), and then replace all the odd and even 𝑓(𝑥) values according to k in the equation.
Finally, use CASIO to compute the sum.
1.3. Newton – Cotes Method
1
Given function 𝑃(𝑥), numerically integrate ∫−1 𝑃(𝑥)𝑑𝑥
𝑛
𝐼 ≈ ∑ 𝑤𝑖 𝑃(𝑥𝑖 )
𝑖=0
N 𝒊 𝒘𝒊 Order m
2 −1, +1 1 1
0 4/3 3
3
−1, +1 1/3
−1/3, +1/3 3/4 3
4
−1, +1 1/4
0 12/45 5
5 −1/2, +1/2 32/45
−1, +1 7/45
−1/5, +1/5 50/144 5
6 −3/5, +3/5 75/144
−1, +1 19/144
N: number of points of integration; m: order of polynomial; w: factor
Table 1.1 one-dimensional Newton-Cotes method
2. Numerical Differentiation
2.1. First Order Derivatives
The first forward finite divided difference is
𝑓(𝑥𝑖+1 ) − 𝑓(𝑥𝑖 )
𝑓 ′ (𝑥𝑖 ) ≈
ℎ
The first backward finite divided difference is
𝑓(𝑥𝑖 ) − 𝑓(𝑥𝑖−1 )
𝑓 ′ (𝑥𝑖 ) ≈
ℎ
The first centered finite divided difference is
𝑓(𝑥𝑖+1 ) − 𝑓(𝑥𝑖−1 )
𝑓 ′ (𝑥𝑖 ) ≈
2ℎ
In case that we consider 4 points
−𝑓(𝑥0 + 2ℎ) + 8𝑓(𝑥0 + ℎ) − 8𝑓(𝑥0 − ℎ) + 𝑓(𝑥0 − 2ℎ)
𝑓 ′ (𝑥0 ) ≈
12ℎ
Example 2.1: Estimate the centered first order derivative of 𝑓(𝑥) at 𝑥 = 0.5 and ℎ = 0.5
𝑓(𝑥) = −0.1𝑥 4 − 0.15𝑥 3 − 0.5𝑥 2 − 0.25𝑥 + 1.2
Solution:
3. Interpolation
3.1. Lagrange polynomial
The Lagrange polynomials associated with the nodes are defined to be
𝑛
𝑘
𝑥 − 𝑥𝑗
𝐿𝑘𝑛 (𝑥) = ∏
𝑥𝑘 − 𝑥𝑗
𝑗=0,𝑗≠𝑘
Example 3.1:
Find shape function in this coordinate: