Chapter - 4 - Interpolation and Approximation
Chapter - 4 - Interpolation and Approximation
Chapter Four
Interpolation and Approximation
Instructor: Haftom G.
23 April, 2024
1
Chapter 4| Interpolation and Approximation Year III, Sem I
Outline
❖ Introduction
❖ Interpolation
▪ Linear interpolation
▪ N-degree polynomial interpolation
▪ Piecewise (Spline) interpolation
❖ Approximation
▪ List square fit approximation
________________________________________________________________________________________________________________________________
Chapter 4| Interpolation and Approximation Year III, Sem I 2
1. Introduction
▪ Experimental observations or computational results are usually
represented by discrete data sets
▪ These data are usually tabulated as:
▪ Interpolation and curve fitting are the two ways to relate these discrete
data sets as a function.
▪ In interpolation, we construct a curve through the data points.
▪ Curve fitting is used to find a smooth curve that approximates the
data in some sense
________________________________________________________________________________________________________________________________
Chapter 4| Interpolation and Approximation Year III, Sem I 3
Cont…
________________________________________________________________________________________________________________________________
Chapter 4| Interpolation and Approximation Year III, Sem I 4
Interpolation
◼ Used estimate intermediate values between precise data points.
◼ The simplest form of an interpolant is a polynomial.
◼ For 𝒏 + 𝟏 distinct data points, there is only one polynomial function of
order 𝒏 that passes through all points.
𝑷𝒏 𝒙 = 𝒂𝟎 + 𝒂𝟏 𝒙 + 𝒂𝟐 𝒙𝟐 + ⋯ + 𝒂𝒏 𝒙𝒏
◼ Thus, polynomial interpolation is consists of determining the unique
𝑛𝑡ℎ order polynomial that fits 𝑛 + 1 data points
◼ If 𝑓(𝑥) is continuous on a finite interval [𝑎, 𝑏], there exists polynomial
𝑃𝑛 (𝑥) of degree 𝑛, such that:
________________________________________________________________________________________________________________________________
Chapter 4| Interpolation and Approximation Year III, Sem I 6
Cont…
a. Linear interpolation
b. N-degree interpolation
_______________________________________________________________________________________________________________________________
Chapter 4| Interpolation and Approximation Year III, Sem I 7
a. Linear Interpolation
◼ It is applicable when two data points are given
◼ Consider: x0 x1
f(x0) f(x1)
f ( x0 ) − f ( x1 )
f1 ( x) = ( x − x0 ) + f ( x0 )
x0 − x1
Then using the equation for linear interpolation we can relate the data
points as
f ( x0 ) − f ( x1 )
f1 ( x) = ( x − x0 ) + f ( x0 )
x0 − x1
1− e
f 1 ( x) = ( x − 0) + 1 = (e − 1) x + 1
0 −1
Which is linear equation
________________________________________________________________________________________________________________________________
Chapter 4| Interpolation and Approximation Year III, Sem I 9
b. N-degree polynomial interpolation
◼ If we have 𝑛 + 1 data points, the 𝑛𝑡ℎ degree polynomial is given as:
Pn ( x) = a0 + a1 x + a 2 x 2 + + a n x n
a 0 + a1 x1 + a 2 x1 2 + + a n x1 n = y1
a 0 + a1 x 2 + a 2 x 2 + + a n x 2 = y 2
2 n
a + a x + a x 2 + + a x n = y
0 1 n 2 n n n n
________________________________________________________________________________________________________________________________
Chapter 4| Interpolation and Approximation Year III, Sem I 10
Cont…
◼ The linear system of equations can be expressed in matrix form as:
1 0 0 a 0 2
1 1 1 a = 3
1
1 2 4 a 2 6
▪ If we use gaussian elimination we have 𝑎0 = 2, 𝑎1 = 0 & 𝑎2 = 1
▪ Therefore, the quadratic equation which relates the data points is:
P2 ( x ) = x 2 + 2
________________________________________________________________________________________________________________________________
Chapter 4| Interpolation and Approximation Year III, Sem I 12
c. Lagrange’s Method
n x − xj
Li ( x) =
j =0 xi − x j
j i
________________________________________________________________________________________________________________________________
Chapter 4| Interpolation and Approximation Year III, Sem I 13
Cont…
◼ Example 3: Given the data’s (3, 1), (4, 2) and (5, 4) find the
interpolating function using Lagrange’s method
Solution
◼ Since we have 3 tabulated data points we can construct quadratic
polynomial function
𝑝2 𝑥 = 𝑎0 + 𝑎1 𝑥 + 𝑎2 𝑥 2
◼ Then find the constants 𝑎0 , 𝑎1 , and 𝑎2 using the Lagrange's formula as:
2
p2 ( x) = yi Li ( x) = y0 L0 + y1 L1 + y2 L2
i =0
________________________________________________________________________________________________________________________________
Chapter 4| Interpolation and Approximation Year III, Sem I 14
Cont…
◼ But first find the cardinal functions by using the product formula as:
2 x − xj
x − x1 x − x2 x −4 x −5 x 2 − 9 x + 20
L0 ( x) = =( )( )=( )( )=
j =1 x0 − x j x0 − x1 x0 − x2 3 − 4 3 − 5 2
j 0
2 x − xj x − x0 x − x2 x −3 x −5
L1 ( x) = =( )( )=( )( ) = − x 2 + 8 x − 15
j =0 x1 − x j x1 − x0 x1 − x2 4−3 4−5
j 1
2 x − xj
x − x0 x − x1 x −3 x −4 − x 2 + 7 x − 12
L2 ( x) = =( )( )=( )( )=
x
j =0 2 − x j x2 − x0 x2 − x1 5 − 3 5 − 4 2
j2
𝑥 2 − 9𝑥 + 20 2
−𝑥 2 + 7𝑥 − 12
𝑝2 𝑥 = 1 + 2 −𝑥 + 8𝑥 − 15 + 4( )
2 2
________________________________________________________________________________________________________________________________
Chapter 4| Interpolation and Approximation Year III, Sem I 15
Cont…
◼ Solving the above equation
𝑝2 𝑥 = −29 + 25.5𝑥 − 3.5𝑥 2
Therefore, the value of the constants become
𝑎0 = −29, 𝑎1 = 25.5, and 𝑎2 = −3.5
X 0 1 2 3 4
Y 2 3 6 8 12
________________________________________________________________________________________________________________________________
Chapter 4| Interpolation and Approximation Year III, Sem I 16
Cont…
▪ The spacing between the data points does not need to be equal
________________________________________________________________________________________________________________________________
Chapter 4| Interpolation and Approximation Year III, Sem I 17
d. Newton's Divided Difference (NDD)
✓ All arithmetic operations have to be repeated for any extra added point in
the data.
given as:
________________________________________________________________________________________________________________________________
Chapter 4| Interpolation and Approximation Year III, Sem I 18
Cont…
◼ The polynomial coefficients are computed using divided difference
a 0 = f ( x0 )
a = f ( x1 ) − f ( x0 )
f [ x1 , x0 ] =
1 x1 − x0
f [ x 2 , x1 ] − f [ x1 , x0 ]
a 2 = f [ x 2 , x1 , x0 ] =
x 2 − x0
a = f [ x n , x n −1 , , x1 ] − f [ x n −1 , x n − 2 , , x0 ]
n f [ x n , x n −1 , , x0 ] =
x n − x0
Where,
f ( xi ) − f ( x j )
f [ xi , x j ] =
xi − x j
________________________________________________________________________________________________________________________________
Chapter 4| Interpolation and Approximation Year III, Sem I 19
Cont…
◼ For n = 4 the graphical depiction of the recursive nature of finite
divided differences is expressed as follows
________________________________________________________________________________________________________________________________
Chapter 4| Interpolation and Approximation Year III, Sem I 20
Cont…
X 0 1 2
Y 2 3 6
P2 ( x) = a 0 + ( x − x0 )a1 + ( x − x0 )( x − x1 )a 2
________________________________________________________________________________________________________________________________
Chapter 4| Interpolation and Approximation Year III, Sem I 21
Cont…
◼ The coefficients are determine using divided difference as:
a 0 = f ( x 0 ) = 2
f ( x1 ) − f ( x0 )
a1 = f [ x1 , x0 ] = =1
x1 − x0
f [ x 2 , x1 ] − f [ x1 , x0 ] 3 − 1
a 2 = f [ x 2 , x1 , x0 ] = = =1
x 2 − x0 2
P2 ( x) = 2 + ( x − 0) + ( x − 0)( x − 1) = x 2 + 2
________________________________________________________________________________________________________________________________
Chapter 4| Interpolation and Approximation Year III, Sem I 22
Cont…
________________________________________________________________________________________________________________________________
Chapter 4| Interpolation and Approximation Year III, Sem I 23
Cont…
Exercise
◼ The set of the following five data points is given:
X 1 2 4 5 7
y 52 5 -5 -40 10
reasonably accurate
________________________________________________________________________________________________________________________________
Chapter 4| Interpolation and Approximation Year III, Sem I 25
Cont…
◼ All of the polynomials are of the same order, but the coefficients are
________________________________________________________________________________________________________________________________
Chapter 4| Interpolation and Approximation Year III, Sem I 26
Linear spline interpolation
________________________________________________________________________________________________________________________________
Chapter 4| Interpolation and Approximation Year III, Sem I 27
Cont…
◼ For example to connect the first two intervals (𝑥1 , 𝑦1 ) & (𝑥2 , 𝑦2 ) we can
use Lagrange's method as:
◼ For 𝑛 data points there are 𝑛 − 1 intervals, and the interpolation in the
𝑖 𝑡ℎ interval of data points (𝑥𝑖 , 𝑦𝑖 ) & (𝑥𝑖+1 , 𝑦𝑖+1 ) is connected using the
equation.
________________________________________________________________________________________________________________________________
Chapter 4| Interpolation and Approximation Year III, Sem I 28
Cont…
◼ Example 5: determine the linear spline for the following data points
and evaluate the interpolated value at 𝑥 = 12.7
X 8 11 15 18
Y 5 9 10 8
◼ Solution: since we have four data points there are three possible
spline intervals;
𝑓1 𝑥 𝑖𝑠 𝑏𝑒𝑡𝑤𝑒𝑒𝑛 8, 5 & (11, 9)
________________________________________________________________________________________________________________________________
Chapter 4| Interpolation and Approximation Year III, Sem I 29
Cont…
◼ Then using the equation for spline interpolation in each interval
________________________________________________________________________________________________________________________________
Chapter 4| Interpolation and Approximation Year III, Sem I 30
3. Approximation (Curve fitting)
◼ It is a procedure in which a mathematical
formula (equation) is used to best fit a given
set of data points.
◼ The objective is to find a function that fits the
data points overall.
◼ It is used to reduce the random noise that
occurred due to measurement errors of the
data.
◼ Finds a smooth curve that fits the data point
on average
◼ The most commonly used approximation is
the Least-square fit method.
_______________________________________________________________________________________________________________________________
Chapter 4| Interpolation and Approximation Year III, Sem I 31
Least-Square Fit
◼ A procedure for finding the best-fitting curve to a given set of points.
◼ It can be done by minimizing the sum of the squares of the offsets
(called residuals) of the points from the curve.
◼ The sum of the squares of the offsets is used because:
◼ Simply adding the residuals of all the points does not provide a good
measure of the overall fit.
◼ Making the overall error E equal to the sum of the absolute values of the
residuals can not have a unique solution.
________________________________________________________________________________________________________________________________
Chapter 4| Interpolation and Approximation Year III, Sem I 32
a. Least-Square Fit of straight line
________________________________________________________________________________________________________________________________
Chapter 4| Interpolation and Approximation Year III, Sem I 33
Cont…
𝑦 = 𝑎0 + 𝑎1 𝑥 + 𝑒
◼ Where, 𝑎0 and 𝑎1 are coefficients and 𝑒 is the error (residual) during fitting
◼ The error is defined as the difference between the true value of (y) and
𝑒 = 𝑦 − 𝑎0 − 𝑎1 𝑥
________________________________________________________________________________________________________________________________
Chapter 4| Interpolation and Approximation Year III, Sem I 34
Cont…
◼ One strategy for fitting a “best” line through the data would be to
minimize the sum of the residual errors for all the available data.
◼ Making sum of the offsets equals to the sum of the squares of the offsets
between the measured ‘y’ and the ‘y’ calculated with the linear model
________________________________________________________________________________________________________________________________
Chapter 4| Interpolation and Approximation Year III, Sem I 36
Cont…
◼ Now, realizing that σ 𝑎0 = 𝑛𝑎𝑜 , we can express the equations as a set of
two simultaneous linear equations as:
Then ,
________________________________________________________________________________________________________________________________
Chapter 4| Interpolation and Approximation Year III, Sem I 38
b. Least square fit of n-degree polynomial
◼ A given set of 𝑛 data points can be curve-fit with polynomials of
different order up to an order of (𝑛 − 1).
◼ The plots in the figure show that as the order of the polynomial
increases the curve passes closer to the points.
________________________________________________________________________________________________________________________________
Chapter 4| Interpolation and Approximation Year III, Sem I 39
Cont…
◼ The figure shows that the same set of data points can be curve fit with
polynomials of different order.
“Which of the polynomials gives the best fit?”
◼ It depends on the type and source of data, the engineering or science
application associated with the data, and the purpose of the curve
fitting.
◼ For example consider the two scenario:
i. When the data points lack accuracy, it isn't very logical to employ a
higher-order polynomial that tries to closely mimic these points.
ii. However, if the data points are highly precise and the goal is to accurately
represent the data, using a higher-order polynomial for curve fitting might
be more suitable
________________________________________________________________________________________________________________________________
Chapter 4| Interpolation and Approximation Year III, Sem I 40
Cont…
◼ Suppose that we need to fit second order polynomial
________________________________________________________________________________________________________________________________
Chapter 4| Interpolation and Approximation Year III, Sem I 41
Cont…
◼ These equations can be set equal to zero and rearranged to develop
the following set of linear equations:
________________________________________________________________________________________________________________________________
Chapter 4| Interpolation and Approximation Year III, Sem I 42
Cont…
◼ Consider the error that occurred due to measurement for n data points is
n
Sr = ( yi − a0 − a1 xi − a2 xi2 − − an xin ) 2
i =0
a = − 2( y i − a 0 − a1 xi − a 2 xi2 − − a n xin ) = 0
0 i =0
S n
S n
a = − 2( y
i =0
i − a 0 − a1 xi − a 2 xi2 − − a n xin )xin = 0
n
________________________________________________________________________________________________________________________________
Chapter 4| Interpolation and Approximation Year III, Sem I 43
Cont…
◼ We can express the above equation in terms of matrix as
n n n
n
n x x i
2
i x n
i a i y
i =0 i =0 i =0
0 i =1
n n n n
a1 n
xi x x i a = xi yi
2 3 n +1
i i x
i =0 i =0 i =0 i =0
2 i =1
n n n n n
x n x n +1
x n+2
i
x 2n n x n y
a
i =0 i i =0
i
i =0
i
i =0 i =1 i i
◼ Since, this is systems of linear equation we can solve using the methods
we studied in the previous chapters.
________________________________________________________________________________________________________________________________
Chapter 4| Interpolation and Approximation Year III, Sem I 44
Cont…
◼ Example 7: Fit quadratic equation from the following data points.
𝒙𝒊 0 1 2 3 4 5
𝑦𝑖 2.1 7.7 13.6 27.2 40.9 61.1
________________________________________________________________________________________________________________________________
Chapter 4| Interpolation and Approximation Year III, Sem I 45
Cont…
◼ Then, the simultaneous linear equations are given as:
________________________________________________________________________________________________________________________________
Chapter 4| Interpolation and Approximation Year III, Sem I 46
Cont…
Exercise:
1. Given the data points. Find the linear and second order least-square
fit polynomial and evaluate at x = 1.5
x 0 2 3
y 7 11 28
◼ The relationship between the current and the diameter can be modeled with an
equation of the for 𝑑 = 𝑎 + 𝑏 𝐼 . Use the data to determine the constants a and b
that best fit the data.
________________________________________________________________________________________________________________________________
Chapter 4| Interpolation and Approximation Year III, Sem I 47
End
Any question?
________________________________________________________________________________________________________________________________
Chapter 4| Interpolation and Approximation Year III, Sem I 48