Chapter 4 Interpolation Curve Fitting (Part 1)
Chapter 4 Interpolation Curve Fitting (Part 1)
Interpolation
A method of estimating the value of a function for any intermediate
value of the independent variable
Newton’s Lagrange
Interpolating Interpolating
Polynomials Polynomials
Curve Fitting
- Find the polynomial function that fits a given set of points
1
BEKG 2452 Numerical Methods
𝑓 𝑥 = 𝑏0 + 𝑏1 (𝑥 − 𝑥0 )
𝑓 𝑥 = 𝑏0 + 𝑏1 𝑥 − 𝑥0 + 𝑏2 𝑥 − 𝑥0 𝑥 − 𝑥1
+ ⋯ + 𝑏𝑛−1 𝑥 − 𝑥0 … 𝑥 − 𝑥𝑛−2
2
BEKG 2452 Numerical Methods
Example:
Construct the parabola that passing through 𝑥0 , 𝑦0 ,
𝑥1 , 𝑦1 and 𝑥2 , 𝑦2 .
From Newton’s Interpolation, the parabolic equation is
𝑓 𝑥 = 𝑏0 + 𝑏1 𝑥 − 𝑥0 + 𝑏2 (𝑥 − 𝑥0 )(𝑥 − 𝑥1 )
Derivation of coefficient 𝒃𝟎 , 𝒃𝟏 , 𝒃𝟐 :
Substitute 𝑥0 , 𝑦0 into 𝑥 and 𝑦:
0 0
𝑦0 = 𝑏0 + 𝑏1 𝑥0 − 𝑥0 + 𝑏2 (𝑥0 − 𝑥0 )(𝑥0 − 𝑥1 )
∴ 𝑏0 = 𝑦0
[email protected]
3
BEKG 2452 Numerical Methods
𝑏0 𝑏1 𝑏2 𝑏3 𝑏4
𝑖 𝑥𝑖 𝑓(𝑥𝑖 ) ∆𝑓𝑖 ∆2 𝑓𝑖 ∆3 𝑓𝑖 ∆4 𝑓𝑖
0 𝑥0 𝑦0
𝑦1 − 𝑦0
∆𝑓0 =
𝑥1 − 𝑥0
1 𝑥1 𝑦1 ∆𝑓1 − ∆𝑓0
∆2 𝑓0 =
𝑥2 − 𝑥0
𝑦2 − 𝑦1 ∆2 𝑓1 − ∆2 𝑓0
∆𝑓1 = ∆3 𝑓0 =
𝑥2 − 𝑥1 𝑥3 − 𝑥0
2 𝑥2 𝑦2 ∆𝑓2 − ∆𝑓1 ∆3 𝑓1 − ∆3 𝑓0
∆2 𝑓1 = ∆4 𝑓0 =
𝑥3 − 𝑥1 𝑥4 − 𝑥0
𝑦3 − 𝑦2 ∆2 𝑓2 − ∆2 𝑓1
∆𝑓2 = ∆3 𝑓1 =
𝑥3 − 𝑥2 𝑥4 − 𝑥1
3 𝑥3 𝑦3 ∆𝑓3 − ∆𝑓2
∆2 𝑓2 =
𝑥4 − 𝑥2
𝑦4 − 𝑦3
∆𝑓3 =
𝑥4 − 𝑥3
4 𝑥4 𝑦4
Table:
𝑖 𝑥𝑖 𝑓(𝑥𝑖 ) ∆𝑓𝑖
0 𝑥0 𝑦0
𝑦1 − 𝑦0
∆𝑓0 =
𝑥1 − 𝑥0
1 𝑥1 𝑦1
[email protected]
4
BEKG 2452 Numerical Methods
𝑓 𝑥 = 𝑏0 + 𝑏1 𝑥 − 𝑥0 = 0.5493(𝑥 − 1) ≈ 𝐥𝐧 𝒙
∴ 𝒇 𝟐 = 𝟎. 𝟓𝟒𝟗𝟑
[email protected]
Table:
𝑖 𝑥𝑖 𝑓(𝑥𝑖 ) ∆𝑓𝑖 ∆2 𝑓𝑖
0 𝑥0 𝑦0
𝑦1 − 𝑦0
∆𝑓0 =
𝑥1 − 𝑥0
1 𝑥1 𝑦1 ∆𝑓1 − ∆𝑓0
∆2 𝑓0 =
𝑥2 − 𝑥0
𝑦2 − 𝑦1
∆𝑓1 =
𝑥2 − 𝑥1
2 𝑥2 𝑦2
5
BEKG 2452 Numerical Methods
𝑓 𝑥 = 𝑏0 + 𝑏1 𝑥 − 𝑥0 + 𝑏2 (𝑥 − 𝑥0 )(𝑥 − 𝑥1 )
= 1 − 2𝑥 − 0.125𝑥(𝑥 − 2)
∴ 𝑓 1.7 = −2.3363
[email protected]
0 𝑥0 𝑦0
𝑦1 − 𝑦0
∆𝑓0 =
𝑥1 − 𝑥0
1 𝑥1 𝑦1 ∆𝑓1 − ∆𝑓0
∆2 𝑓0 =
𝑥2 − 𝑥0
𝑦2 − 𝑦1 ∆2 𝑓1 − ∆2 𝑓0
∆𝑓1 = ∆3 𝑓0 =
𝑥2 − 𝑥1 𝑥3 − 𝑥0
2 𝑥2 𝑦2 ∆𝑓2 − ∆𝑓1
∆2 𝑓1 =
𝑥3 − 𝑥1
𝑦3 − 𝑦2
∆𝑓2 =
𝑥3 − 𝑥2
3 𝑥3 𝑦3
6
BEKG 2452 Numerical Methods
Example:
Estimate 𝑓(5.3) using cubic interpolation given
1, 1 , 4, 9 , 7, 13 , 10, 20 .
Answer:
𝑖 𝑥𝑖 𝑓(𝑥𝑖 ) ∆𝑓𝑖 ∆2 𝑓𝑖 ∆3 𝑓𝑖
0 1 1 𝑏0
2.6667 𝑏1
1 4 9 −0.2222 𝑏2
1.3333 0.0432 𝑏3
2 7 13 0.1667
2.3333
3 10 20
𝑓 𝑥
= 1 + 2.6667 𝑥 − 1 − 0.2222 𝑥 − 1 𝑥 − 4
+ 0.0432(𝑥 − 1)(𝑥 − 4)(𝑥 − 7) ∴ 𝑓 5.3 = 10.8142
Example 4.1:
Given the following data
𝑖 0 1 2 3
𝑥𝑖 0 1 2 3
𝑓(𝑥𝑖 ) 10 8 2 −9
7
BEKG 2452 Numerical Methods
𝑥 − 𝑥1 𝑥 − 𝑥0
𝑓 𝑥 = 𝑓 𝑥0 + 𝑓 𝑥1
𝑥0 − 𝑥1 𝑥1 − 𝑥0
8
BEKG 2452 Numerical Methods
𝑓𝑛 𝑥 = 𝐿𝑖 𝑥 𝑓(𝑥𝑖 ) = 𝐿0 𝑥 𝑓 𝑥0 + ⋯ + 𝐿𝑛 𝑥 𝑓(𝑥𝑛 )
𝑖=0
where
𝑛
𝑥 − 𝑥𝑗
𝐿𝑖 𝑥 =
𝑥𝑖 − 𝑥𝑗
𝑗=0,𝑗≠𝑖
𝑥 − 𝑥0 𝑥 − 𝑥1 𝑥 − 𝑥𝑖−1 𝑥 − 𝑥𝑖+1 𝑥 − 𝑥𝑛
= … …
𝑥𝑖 − 𝑥0 𝑥𝑖 − 𝑥1 𝑥𝑖 − 𝑥𝑖−1 𝑥𝑖 − 𝑥𝑖+1 𝑥𝑖 − 𝑥𝑛
𝐿𝑖 𝑥𝑗 = 1
𝑖=0
9
BEKG 2452 Numerical Methods
Example:
Use Lagrange Interpolating Polynomial of degree 1 to
estimate 𝑓(4.7) given 𝑓 4.3 = 0.1678 and 𝑓 4.9 =
0.2451 .
Answer:
𝑓 𝑥 = 𝐿0 𝑥 𝑓 𝑥0 + 𝐿1 𝑥 𝑓 𝑥1
where
𝑥 − 𝑥1 𝑥 − 4.9
𝐿0 𝑥 = =
𝑥0 − 𝑥1 4.3 − 4.9
𝑥 − 𝑥0 𝑥 − 4.3
𝐿1 𝑥 = =
𝑥1 − 𝑥0 4.9 − 4.3
10
BEKG 2452 Numerical Methods
Recall:
𝑓 4.3 = 0.1678
Answer: (cont.) 𝑓 4.9 = 0.2451
𝑓 𝑥 = 𝐿0 𝑥 𝑓 𝑥0 + 𝐿1 𝑥 𝑓 𝑥1
𝑥 − 4.9 𝑥 − 4.3
𝑓 𝑥 = 0.1678 + 0.2451
4.3 − 4.9 4.9 − 4.3
4.7 − 4.9 4.7 − 4.3
𝑓 4.7 = 0.1678 + 0.2451
4.3 − 4.9 4.9 − 4.3
= 0.2193
11
BEKG 2452 Numerical Methods
Example:
Use Lagrange Interpolating Polynomial of degree 2 to
estimate 𝑓(−3.8) given 𝑓 −10.3 = 1.0823, 𝑓 −5.1 =
4.7798 and 𝑓 −1.5 = 9.1514.
Answer:
𝑓 𝑥 = 𝐿0 𝑥 𝑓 𝑥0 + 𝐿1 𝑥 𝑓 𝑥1 + 𝐿2 𝑥 𝑓 𝑥2
where
𝑥 − 𝑥1 𝑥 − 𝑥2 𝑥 + 5.1 𝑥 + 1.5
𝐿0 𝑥 = =
𝑥0 − 𝑥1 𝑥0 − 𝑥2 −10.3 + 5.1 −10.3 + 1.5
𝑥 − 𝑥0 𝑥 − 𝑥2 𝑥 + 10.3 𝑥 + 1.5
𝐿1 𝑥 = =
𝑥1 − 𝑥0 𝑥1 − 𝑥2 −5.1 + 10.3 −5.1 + 1.5
𝑥 − 𝑥0 𝑥 − 𝑥1 𝑥 + 10.3 𝑥 + 5.1
𝐿2 𝑥 = =
𝑥2 − 𝑥0 𝑥2 − 𝑥1 −1.5 + 10.3 −1.5 + 5.1
Answer: (cont.)
Recall:
𝑓 −10.3 = 1.0823
𝑓 −5.1 = 4.7798
𝑓 −1.5 = 9.1514
𝑓 𝑥 = 𝐿0 𝑥 𝑓 𝑥0 + 𝐿1 𝑥 𝑓 𝑥1 + 𝐿2 𝑥 𝑓 𝑥2
12
BEKG 2452 Numerical Methods
Answer: (cont.)
𝑓 𝑥 = 𝐿0 𝑥 𝑓 𝑥0 + 𝐿1 𝑥 𝑓 𝑥1 + 𝐿2 𝑥 𝑓 𝑥2
𝑥+5.1 𝑥+1.5 𝑥+10.3 𝑥+1.5
= 1.0823 − 4.7798
45.76 18.72
𝑥+10.3 𝑥+5.1
+ 9.1514
31.68
−3.8+5.1 −3.8+1.5
∴ 𝑓 −3.8 = 1.0823
45.76
−3.8+10.3 −3.8+1.5
− 4.7798
18.72
−3.8+10.3 −3.8+5.1
+ 9.1514
31.68
= 6.1874
Example 4.2:
Given the following data
𝑖 0 1 2
𝑥𝑖 −1 1 3
𝑓(𝑥𝑖 ) 11 8 3
13
BEKG 2452 Numerical Methods
Example:
Find the Lagrange approximation polynomial of degree 3
𝑥 2 −𝑒 𝑥 +ln 𝑥
for the function 𝑓 𝑥 = . Use the 𝑥0 = 1, 𝑥1 = 3,
𝑥+sin 𝑥
𝑥2 = 4 and 𝑥3 = 7. Then estimate 𝑓 5 .
Answer:
Find the points of the given function.
𝑖 0 1 2 3
𝑥𝑖 1 3 4 7
𝑓(𝑥𝑖 ) −1.2662 −5.6349 −20.6631 −377.8965
𝑓 𝑥 = 𝐿0 𝑥 𝑓 𝑥0 + 𝐿1 𝑥 𝑓 𝑥1 + 𝐿2 𝑥 𝑓 𝑥2 + 𝐿3 𝑥 𝑓 𝑥3
14
BEKG 2452 Numerical Methods
Answer: (cont.)
𝑖 0 1 2 3
𝑥𝑖 1 3 4 7
𝑓(𝑥𝑖 ) −1.2662 −5.6349 −20.6631 −377.8965
Answer: (cont.)
𝑓 𝑥 = 𝐿0 𝑥 𝑓 𝑥0 + 𝐿1 𝑥 𝑓 𝑥1 + 𝐿2 𝑥 𝑓 𝑥2 + 𝐿3 𝑥 𝑓 𝑥3
𝑥−3 𝑥−4 𝑥−7 𝑥−1 𝑥−4 𝑥−7
= −1.2662 + −5.6349
−36 8
𝑥−1 𝑥−3 𝑥−7 𝑥−1 𝑥−3 𝑥−4
+ (−20.6631) + −377.8965
−9 72
15
BEKG 2452 Numerical Methods
Example 4.3:
Construct the Lagrange Interpolation polynomial
of degree 3 with the data set given below:
𝑖 0 1 2 𝟑
𝑥𝑖 −1 0 1 2
𝑓(𝑥𝑖 ) 1 1 1 −5
16