MathEng5-M - Part 6-1
MathEng5-M - Part 6-1
12/6/2021
Part 6
INTERPOLATION
2
Interpolation
12/6/2021
MathEng5-M - Numerical Solutions to CE Problems
Polynomial interpolation – consists of
determining the unique nth-order
polynomial that fits 𝑛 + 1 data points.
𝑓 𝑥 = 𝑎0 + 𝑎1 𝑥 + 𝑎2 𝑥 2 + ⋯ + 𝑎𝑛 𝑥 𝑛
12/6/2021
MathEng5-M - Numerical Solutions to CE Problems
Linear Interpolation – connecting two data
points with a straight line
❖ Using similar triangles (from Figure 2)
𝑓1 𝑥 − 𝑓 𝑥0 𝑓 𝑥1 − 𝑓 𝑥0
=
𝑥 − 𝑥0 𝑥1 − 𝑥0
❖ Rearranging the equation yields
𝑓 𝑥1 −𝑓 𝑥0
𝑓1 𝑥 = 𝑓 𝑥0 + 𝑥 − 𝑥0 linear
𝑥1 −𝑥0
interpolation formula
4
Example 1:
12/6/2021
MathEng5-M - Numerical Solutions to CE Problems
Evaluate the common logarithm of 10 using linear interpolation
a) Interpolate between log 8 and log 12
b) Interpolate between log 9 and log 11
For each of the interpolation, compute the percent relative error
based on the true value.
5
Solution:
12/6/2021
MathEng5-M - Numerical Solutions to CE Problems
a) log 8 = 0.903089987 , log 12 = 1.079181246
True value: log 10 = 1
Let: 𝑥0 = log 8 , 𝑥1 = log 12 , 𝑓 𝑥0 = 0.903089987 , 𝑓 𝑥1 = 1.079181246
Formula:
𝑓 𝑥1 −𝑓 𝑥0
𝑓1 𝑥 = 𝑓 𝑥0 + 𝑥 − 𝑥0
𝑥1 −𝑥0
1.079181246−0.903089987
𝑓1 𝑥 = log 10 = 0.903089987 + 10 − 8
12−8
𝑓1 𝑥 = 0.9911356165
1−0.9911356165
𝜀𝑡 = ∗ 100% = 0.8864%
1
6
b) log 9 = 0.9542425094 , log 11 = 1.041392685
12/6/2021
MathEng5-M - Numerical Solutions to CE Problems
True value: log 10 = 1
Let: 𝑥0 = log 9 , 𝑥1 = log 11 , 𝑓 𝑥0 = 0.9542425094 , 𝑓 𝑥1 = 1.041392685
Formula:
𝑓 𝑥1 −𝑓 𝑥0
𝑓1 𝑥 = 𝑓 𝑥0 + 𝑥 − 𝑥0
𝑥1 −𝑥0
1.041392685−0.9542425094
𝑓1 𝑥 = log 10 = 0.9542425094 + 10 − 9
11−9
𝑓1 𝑥 = 0.9978175973
1−0.9978175973
𝜀𝑡 = ∗ 100% = 0.2182%
1
7
Quadratic Interpolation
12/6/2021
MathEng5-M - Numerical Solutions to CE Problems
Quadratic Interpolation – introducing some curvature into the line connecting
the points. It is also called a quadratic polynomial or a parabola.
a) General form of the equation
𝑓2 𝑥 = 𝑏0 + 𝑏1 𝑥 − 𝑥0 + 𝑏2 𝑥 − 𝑥0 𝑥 − 𝑥1
b) Multiplying the terms yields
𝑓2 𝑥 = 𝑏0 + 𝑏1 𝑥 − 𝑏1 𝑥0 + 𝑏2 𝑥 2 + 𝑏2 𝑥0 𝑥1 − 𝑏2 𝑥𝑥0 − 𝑏2 𝑥𝑥1
c) Or, collecting terms
𝑓2 𝑥 = 𝑎0 + 𝑎1 𝑥 + 𝑎2 𝑥 2
where:
𝑎0 = 𝑏0 − 𝑏1 𝑥0 + 𝑏2 𝑥0 𝑥1 𝑎1 = 𝑏1 − 𝑏2 𝑥0 − 𝑏2 𝑥1 𝑎2 = 𝑏2
8
Quadratic Interpolation
12/6/2021
MathEng5-M - Numerical Solutions to CE Problems
d) With x = x0
𝑏0 = 𝑓 𝑥0
e) Substituting b0 to the general equation and with x = x1
𝑓 𝑥1 −𝑓 𝑥0
𝑏1 =
𝑥1 −𝑥0
12/6/2021
MathEng5-M - Numerical Solutions to CE Problems
Fit a second order Newton’s interpolating polynomial to estimate log 10
using the data in Example 1 at 𝑥 = 8, 9, 11 . Compute the true percent
relative error.
Solution:
❖ True value: log 10 = 1
❖ Let:
𝑥0 = log 8 𝑓 𝑥0 = 0.903089987
𝑥1 = log 9 𝑓 𝑥1 = 0.9542425094
𝑥2 = log 11 𝑓 𝑥2 = 1.041392685
10
Formula:
12/6/2021
MathEng5-M - Numerical Solutions to CE Problems
𝑓2 𝑥 = 𝑏0 + 𝑏1 𝑥 − 𝑥0 + 𝑏2 𝑥 − 𝑥0 𝑥 − 𝑥1
𝑏0 = 𝑓 𝑥0 = 0.903089987
𝑓 𝑥1 −𝑓 𝑥0 0.9542425094−0.903089987
𝑏1 = = = 0.05115252245
𝑥1 −𝑥0 9−8
𝑏2 = −2.525811529𝑥10−3
𝑓2 𝑥 = log 10 = 0.903089987 + 0.05115252245 10 − 8 + 2.525811529𝑥10−3 −
10 − 8 10 − 9
1−1.000343409
𝒇𝟐 𝒙 = 𝟏. 𝟎𝟎𝟎𝟑𝟒𝟑𝟒𝟎𝟗 𝜀𝑡 = ∗ 100% = −𝟎. 𝟎𝟑𝟒𝟑𝟒%
1
11
General Form of Newton’s Interpolating Polynomials
12/6/2021
MathEng5-M - Numerical Solutions to CE Problems
❖ For nth-order polynomial ❖ The bracketed function evaluations
𝑓𝑛 𝑥 = 𝑏0 + 𝑏1 𝑥 − 𝑥0 + ⋯ + are finite divided differences
𝑏𝑛 𝑥 − 𝑥0 𝑥 − 𝑥1 … 𝑥 − 𝑥𝑛−1 𝑓 𝑥𝑖 − 𝑓 𝑥𝑗
𝑓 𝑥𝑖 , 𝑥𝑗 =
❖ To evaluate the coefficients 𝑥𝑖 − 𝑥𝑗
𝑏𝑜 = 𝑓 𝑥0 𝑓 𝑥𝑖 , 𝑥𝑗 − 𝑓 𝑥𝑗 , 𝑥𝑘
𝑓 𝑥𝑖 , 𝑥𝑗 , 𝑥𝑘 =
𝑏1 = 𝑓 𝑥1 , 𝑥0 𝑥𝑖 − 𝑥𝑘
𝑓 𝑥𝑛 , 𝑥𝑛−1 , … , 𝑥1 , 𝑥0
𝑏2 = 𝑓 𝑥2 , 𝑥1 , 𝑥0
𝑓 𝑥𝑛 , 𝑥𝑛−1 , … , 𝑥1 − 𝑓 𝑥𝑛−1 , 𝑥𝑛−2 , … , 𝑥0
⋮ ⋮ =
𝑥𝑛 − 𝑥0
𝑏𝑛 = 𝑏2 = 𝑓 𝑥𝑛 , 𝑥𝑛−1 , … , 𝑥1 , 𝑥0
12
General Form of Newton’s Interpolating Polynomials
12/6/2021
MathEng5-M - Numerical Solutions to CE Problems
❖ These differences can be used to evaluate the coefficients which can
then be substituted to the general equation to yield interpolating
polynomial
𝑓𝑛 𝑥 = 𝑓 𝑥0 + 𝑥 − 𝑥0 𝑓 𝑥1 , 𝑥0 + 𝑥 − 𝑥0 𝑥 − 𝑥1 𝑓 𝑥2 , 𝑥1 , 𝑥0 + ⋯ +
𝑥 − 𝑥0 𝑥 − 𝑥1 𝑥 − 𝑥𝑛−1 𝑓 𝑥𝑛 , 𝑥𝑛−1 , … , 𝑥0
which is called the Newton’s divided difference interpolating
polynomial.
❖ Errors of Newton’s Interpolating Polynomials
𝑅𝑛 ≅ 𝑓 𝑥𝑛+1 , 𝑥𝑛 , 𝑥𝑛−1 , … , 𝑥0 𝑥 − 𝑥0 𝑥 − 𝑥1 … 𝑥 − 𝑥𝑛
13
Example 3
12/6/2021
MathEng5-M - Numerical Solutions to CE Problems
Fit a third order Newton’s interpolating polynomial to estimate log 10 using
the data in Example 1.
𝑥0 = log 8 𝑓 𝑥0 = 0.903089987 𝑏0
𝑥1 = log 12 𝑓 𝑥1 = 1.079181246
𝑥2 = log 9 𝑓 𝑥2 = 0.9542425094
𝑥3 = log 11 𝑓 𝑥3 = 1.041392685
14
Solution:
12/6/2021
MathEng5-M - Numerical Solutions to CE Problems
a) First finite divided difference
𝑓 𝑥1 −𝑓 𝑥0 1.079181246−0.903089987
𝑓 𝑥1 , 𝑥0 = 𝑥1 −𝑥0
= 12−8
= 0.04402281476 𝑏1
𝑓 𝑥2 −𝑓 𝑥1 0.9542425094−1.079181246
𝑓 𝑥2 , 𝑥1 = = = 0.04164624554
𝑥2 −𝑥1 9−12
𝑓 𝑥3 −𝑓 𝑥2 1.041392685−0.9542425094
𝑓 𝑥3 , 𝑥2 = 𝑥3 −𝑥2
= 11−9
= 0.04357508786
12/6/2021
MathEng5-M - Numerical Solutions to CE Problems
𝑓 𝑥3 ,𝑥2 ,𝑥1 −𝑓 𝑥2 ,𝑥1 ,𝑥0 −1.92884232𝑥10−3 − −2.37656917𝑥10−3
𝑓 𝑥3 , 𝑥2 , 𝑥1 , 𝑥0 = =
𝑥3 −𝑥0 11−8
𝑓 𝑥3 , 𝑥2 , 𝑥1 , 𝑥0 = −2.37656917𝑥10−3 𝑏3
d) Solving for 𝒇𝟑 𝒙
𝑓3 𝑥 = 𝑏0 + 𝑏1 𝑥 − 𝑥0 + 𝑏2 𝑥 − 𝑥0 𝑥 − 𝑥1 + 𝑏3 𝑥 − 𝑥0 𝑥 − 𝑥1 𝑥 − 𝑥2
𝑓3 𝑥 = 0.903089987 + 0.04402281476 10 − 8 + −2.37656917𝑥10−3 ሺ10 −
8ሻ 10 − 12 + −2.37656917𝑥10−3 10 − 8 10 − 12 10 − 9
𝑓3 𝑥 = 1.001238862
e) True percent relative error
1−1.001238862
𝜀𝑡 = ∗ 100% = 𝟎. 𝟏𝟐𝟑𝟗%
1
16
Example 4
12/6/2021
MathEng5-M - Numerical Solutions to CE Problems
Given the data:
12/6/2021
MathEng5-M - Numerical Solutions to CE Problems
𝑓 𝑥1 −𝑓 𝑥0
𝑓1 𝑥 = 𝑓 𝑥0 + 𝑥 − 𝑥0
𝑥1 −𝑥0
𝑥0 = 1.6 𝑓 𝑥0 = 2
8−2
𝑓1 𝑥 = 2 + 2.8 − 1.6 = 𝟓 Answer
4−1.6
𝑥1 = 4 𝑓 𝑥1 = 8
𝑅1 ≅ 𝑓 𝑥2 , 𝑥1 , 𝑥0 𝑥 − 𝑥0 𝑥 − 𝑥1
𝑥2 = 2.5 𝑓 𝑥2 = 14
𝑓 𝑥1 −𝑓 𝑥0 8−2
𝑓 𝑥1 , 𝑥0 = = 4−1.6 = 2.5
𝑥3 = 4.5 𝑓 𝑥3 = 2 𝑥1 −𝑥0
𝑓 𝑥2 −𝑓 𝑥1 14−8
𝑥4 = 3.2 𝑓 𝑥4 = 15 𝑓 𝑥2 , 𝑥1 = = 2.5−4 = −4
𝑥2 −𝑥1
12/6/2021
MathEng5-M - Numerical Solutions to CE Problems
𝑏0 = 𝑓 𝑥0 = 2
𝑓 𝑥1 −𝑓 𝑥0 8−2
𝑏1 = = 4−1.6 = 2.5
𝑥1 −𝑥0
𝑓 𝑥2 −𝑓 𝑥1 𝑓 𝑥1 −𝑓 𝑥0 14−8 8−2
𝑥2 −𝑥1
− 𝑥1 −𝑥0 − 4−1.6 65
2.5−4
𝑏2 = = =−
𝑥2 −𝑥0 2.5−1.6 9
65
𝑓2 𝑥 = 2 + 2.5 2.8 − 1.6 + − 2.8 − 1.6 2.8 − 4 = 𝟏𝟓. 𝟒 Answer
9
𝑅2 ≅ 𝑓 𝑥3 , 𝑥2 , 𝑥1 , 𝑥0 𝑥 − 𝑥0 𝑥 − 𝑥1 𝑥 − 𝑥2
𝑓 𝑥1 −𝑓 𝑥0 8−2
𝑓 𝑥1 , 𝑥0 = = 4−1.6 = 2.5
𝑥1 −𝑥0
𝑓 𝑥2 −𝑓 𝑥1 14−8
𝑓 𝑥2 , 𝑥1 = = 2.5−4 = −4
𝑥2 −𝑥1
𝑓 𝑥3 −𝑓 𝑥2 2−14
𝑓 𝑥3 , 𝑥2 = 𝑥3 −𝑥2
= 4.5−2.5 = −6
19
𝑓 𝑥2 ,𝑥1 −𝑓 𝑥1 ,𝑥0 −4−2.5 65
𝑓 𝑥2 , 𝑥1 , 𝑥0 = = 2.5−1.6 = −
𝑥2 −𝑥0 9
12/6/2021
MathEng5-M - Numerical Solutions to CE Problems
𝑓 𝑥3 ,𝑥2 −𝑓 𝑥2 ,𝑥1 −6− −4
𝑓 𝑥3 , 𝑥2 , 𝑥1 = = = −4
𝑥3 −𝑥1 4.5−4
65
𝑓 𝑥3 ,𝑥2 ,𝑥1 −𝑓 𝑥2 ,𝑥1 ,𝑥0 −4− 10
9
𝑓 𝑥3 , 𝑥2 , 𝑥1 , 𝑥0 = = =
𝑥3 −𝑥0 4.5−1.6 9
10
𝑅2 ≅ 2.8 − 1.6 2.8 − 4 2.8 − 2.5 = −𝟎. 𝟒𝟖% Answer
9
𝑓 𝑥3 −𝑓 𝑥2 2−14 𝑓 𝑥4 −𝑓 𝑥3 15−2
𝑓 𝑥3 , 𝑥2 = = = −6 𝑓 𝑥4 , 𝑥3 = = = −10
𝑥3 −𝑥2 4.5−2.5 𝑥4 −𝑥3 3.2−4.5
20
d) Second finite divided difference
12/6/2021
MathEng5-M - Numerical Solutions to CE Problems
𝑓 𝑥2 , 𝑥1 − 𝑓 𝑥1 , 𝑥0 −4 − 2.5 65
𝑓 𝑥2 , 𝑥1 , 𝑥0 = = =−
𝑥2 − 𝑥0 2.5 − 1.6 9
𝑓 𝑥3 , 𝑥2 − 𝑓 𝑥2 , 𝑥1 −6 − −4
𝑓 𝑥3 , 𝑥2 , 𝑥1 = = = −4
𝑥3 − 𝑥1 4.5 − 4
𝑓 𝑥4 , 𝑥3 − 𝑓 𝑥3 , 𝑥2 −10 − −6 40
𝑓 𝑥4 , 𝑥3 , 𝑥2 = = =−
𝑥4 − 𝑥2 3.2 − 2.5 7
e) Third finite divided difference
65
𝑓 𝑥3 , 𝑥2 , 𝑥1 − 𝑓 𝑥2 , 𝑥1 , 𝑥0 −4 − 10
9
𝑓 𝑥3 , 𝑥2 , 𝑥1 , 𝑥0 = = =
𝑥3 − 𝑥0 4.5 − 1.6 9
40
𝑓 𝑥4 , 𝑥3 , 𝑥2 − 𝑓 𝑥3 , 𝑥2 , 𝑥1 − − −4 15
𝑓 𝑥4 , 𝑥3 , 𝑥2 , 𝑥1 = = 7 =
𝑥4 − 𝑥1 3.2 − 4 7
21
f) Fourth finite divided difference
12/6/2021
MathEng5-M - Numerical Solutions to CE Problems
15 10
𝑓 𝑥4 ,𝑥3 ,𝑥2 ,𝑥1 −𝑓 𝑥3 ,𝑥2 ,𝑥1 ,𝑥0 7
− 9 325
𝑓 𝑥4 , 𝑥3 , 𝑥2 , 𝑥1 , 𝑥0 = = = 504
𝑥4 −𝑥1 3.2−1.6
Solving for 𝑓3 𝑥
65 10
𝑓3 𝑥 = 2 + 2.5 2.8 − 1.6 + − 2.8 − 1.6 2.8 − 4 + 2.8 − 1.6 ሺ2.8 −
9 9
4ሻ 2.8 − 2.5
373
𝑓3 𝑥 = = 𝟏𝟒. 𝟗𝟐 Answer
25
𝑅2 ≅ 𝑓 𝑥3 , 𝑥2 , 𝑥1 , 𝑥0 𝑥 − 𝑥0 𝑥 − 𝑥1 𝑥 − 𝑥2
325
𝑅2 ≅ 504 2.8 − 1.6 2.8 − 4 2.8 − 2.5 2.8 − 4.5 = 𝟎. 𝟒𝟕𝟑𝟔% Answer
22
Inverse Interpolation
12/6/2021
MathEng5-M - Numerical Solutions to CE Problems
Shown in the table below are the values of 𝑥 and the corresponding values of the
function 𝑓ሺ𝑥ሻ such that 𝑓 𝑥 = 1Τ𝑥. Note that the values of the 𝑥’𝑠 are uniformly
spaced.
𝒙 1 2 3 4 5 6 7
𝒇 𝒙 1 0.5 0.3333 0.25 0.2 0.1667 0.1429
Suppose that you are given the same data, but you are given a value for 𝑓 𝑥
and must determine the corresponding value of 𝑥. Example: for the data above,
find the value of 𝑥 that correspond to 𝑓ሺ𝑥ሻ = 0.3. Because the value of the
function is available and easy to manipulate, the correct answer is 𝑥 = 1/0.3 =
3.3333. Such a problem is called inverse interpolation.
23
Inverse Interpolation
12/6/2021
MathEng5-M - Numerical Solutions to CE Problems
For this type of problem, you might be tempted to switch the 𝑓ሺ𝑥ሻ and 𝑥 values
[that is merely plot 𝑥 versus 𝑓ሺ𝑥ሻ] and use an approach like Lagrange interpolation
to determine the result. However, when you reverse the variables, there is no
guarantee that the values along the new abscissa [the 𝑓ሺ𝑥ሻ’𝑠] will be evenly
spaced. In many cases, the values will be “telescoped”. That is, they will have the
appearance of a logarithmic scale with some adjacent points bunched together
and other spread widely. Such nonuniform spacing on the abscissa often leads to
oscillations in the resulting interpolating polynomial. This can occur even for the
lower-order polynomials
12/6/2021
MathEng5-M - Numerical Solutions to CE Problems
An alternative strategy is to fit an nth-order interpolating polynomial, 𝑓𝑛 𝑥 to the
original data [that is, with 𝑓ሺ𝑥ሻ versus 𝑥].
Example:
Fit a quadratic polynomial to the three points 2, 0.5 , 3, 0.333 , 4, 0.25 to
determine 𝑥 when 𝑓ሺ𝑥ሻ = 0.3.
Answer:
𝑓2 𝑥 = 1.08333 − 0.375𝑥 + 0.41667𝑥 2 → 0.3 = 1.08333 − 0.375𝑥 + 0.41667𝑥 2
Using quadratic formula, 𝑥1 = 5.704158, 𝑥2 = 3.296842
The second root is a good approximation of the true value of 3.333