Interpolation
Walter
Mudzimbabwe
Chapter 5
Interpolation
Walter Mudzimbabwe
Interpolation
Interpolation
Walter
Mudzimbabwe
Chapter 5
Motivation:
ti , time 1 1.3 1.6 1.9 2.2
V (ti ), Volume 0.7652 0.6201 0.4554 0.2818 0.1104
Question: What is V (1.7)?
Interpolation
Interpolation
Walter
Mudzimbabwe
Chapter 5
Linear interpolation
Interpolation Given only 2 points (x0 , f (x0 )) and (x1 , f (x1 )) the interpolating
Walter function is a straight line passing through them.
Mudzimbabwe
Let P1 (x) = a0 + a1 x = f (x).
Chapter 5
The polynomial has to pass through these two points so
P1 (x0 ) = a0 + a1 x0 = f (x0 )
P1 (x1 ) = a0 + a1 x1 = f (x1 )
Therefore
f (x0 )x1 − f (x1 )x0 f (x1 ) − f (x0 )
a0 = , a1 =
x1 − x0 x1 − x0
Therefore:
f (x1 ) − f (x0 )
P1 (x) = f (x0 ) + (x − x0 )
x1 − x0
which is a linear interpolating formula.
Example
Interpolation
Walter
Mudzimbabwe Question: Estimate ln(2) using linear interpolation given
Chapter 5
x0 = 1 and x1 = 6.
Solution: Data: (x0 , f (x0 )) = (1, ln(1)) and
(x1 , f (x1 )) = (6, ln(6)).
So
f (x1 ) − f (x0 )
P1 (x) = f (x0 ) + (x − x0 )
x1 − x0
ln 6 − ln 1
ln(2) = P1 (2) = ln 1 + (2 − 1)
6−1
= 0.3583519.
From calculator ln(2) = 0.6931472.
Quadratic interpolation
Interpolation
Walter Given 3 points (x0 , f (x0 )), (x1 , f (x1 )) and (x2 , f (x2 )), a
Mudzimbabwe
parabola
Chapter 5
P2 (x) = a0 + a1 (x − x0 ) + a2 (x − x0 )(x − x1 )
can be used which passes through them.
How do we find a0 , a1 , a2 ?
The polynomial has to pass through the 3 points.
Substituting x = x0 in P2 (x) results in P2 (x0 ) = a0 = f (x0 ).
Substituting x = x1 in P2 (x) results in
P2 (x1 ) = a0 + a1 (x1 − x0 ) = f (x0 ) + a1 (x1 − x0 ) = f (x1 ).
Therefore
f (x1 ) − f (x0 )
a1 = .
x1 − x0
What is a2 ?
Interpolation
Walter
Substituting x = x2 in P2 (x) results in
Mudzimbabwe
Chapter 5
P2 (x2 ) = f (x2 ) = a0 + a1 (x2 − x0 ) + a2 (x2 − x0 )(x2 − x1 )
f (x1 ) − f (x0 )
= f (x0 ) + (x2 − x0 ) + a2 (x2 − x0 )(x2 − x1 )
x1 − x0
..
.
..
.
..
.
Finally,
f (x2 )−f (x1 ) f (x1 )−f (x0 )
x2 −x1 − x1 −x0
a2 = .
x2 − x0
Example
Interpolation Question: Estimate ln(2) using quadratic interpolation given
Walter x0 = 1, x1 = 4 and x2 = 6.
Mudzimbabwe
Solution: Data: (x0 , f (x0 )) = (1, ln(1)),
Chapter 5
(x1 , f (x1 )) = (4, ln(4)) and (x2 , f (x2 )) = (6, ln(6)).
So P2 (x)
= a0 + a1 (x − x0 ) + a2 (x − x0 )(x − x1 )
f (x1 ) − f (x0 )
= f (x0 ) + (x − x0 )
x1 − x0
f (x2 )−f (x1 ) f (x1 )−f (x0 )
x2 −x1 − x1 −x0
+ (x − x0 )(x − x1 )
x2 − x0
ln 4 − ln 1
= ln 1 + (x − 1)
4−1
ln 6−ln 4 ln 4−ln 1
6−4 − 4−1
+ (x − 1)(x − 4)
6−1
Example Cont’d
Interpolation
Walter
Mudzimbabwe
Chapter 5
Therefore P2 (x) = 0 + 0.4621(x − 1) − 0.0519(x − 1)(x − 4)
So ln(2) is approximate by
P2 (2) = 0 + 0.4621(2 − 1) − 0.0519(2 − 1)(2 − 4) = 0.5658.
linear interpolation gives 0.3583519.
Exact value is ln(2) = 0.6931472.
Lagrange Interpolating Polynomials
Interpolation
Walter
Mudzimbabwe Suppose we want to determine a first degree polynomial that
Chapter 5
passes through two points (x0 , y0 ) and (x1 , y1 ). Let such a
polynomial have the form:
(x − x1 ) (x − x0 )
P(x) = y0 + y1
(x0 − x1 ) (x1 − x0 )
= L0 (x)y0 + L1 (x)y1 .
Note that
1. P(x0 ) = y0 and P(x1 ) = y1 .
2. When x = x0 , L0 (x0 ) = 1 and L1 (x0 ) = 0.
3. When x = x1 , L0 (x1 ) = 0 and L1 (x1 ) = 1.
Lagrange Interpolating Polynomials
Interpolation In general, to construct a polynomial of degree at most Pn (x)
Walter that passes through the n + 1 points
Mudzimbabwe
(x0 , f (x0 )), (x1 , f (x1 )), . . . , (xn , f (xn )), we need to construct
Chapter 5
for k = 0, 1, . . . , n,
1. Ln,k (xi ) = 0 when i ̸= k.
2. Ln,k (xk ) = 1.
Therefore, for Condition 1. to hold,
(x − x0 ) · · · (x − xk−1 )(x − xk+1 ) · · · (x − xn )
Ln,k (x) =
···
Finally for 2. to hold,
(x − x0 ) · · · (x − xk−1 )(x − xk+1 ) · · · (x − xn )
Ln,k (x) =
(xk − x0 ) · · · (xk − xk−1 )(xk − xk+1 ) · · · (xk − xn )
n
Y (x − xi )
= . (1)
(xk − xi )
i=0,i̸=k
Example
Interpolation
Walter
Mudzimbabwe
The lagrange interpolating polynomial is thus
Chapter 5
P(x) = Ln,0 (x)f (x0 ) + Ln,1 (x)f (x1 ) + . . . + Ln,n (x)f (xn )
We write Lk instead of Ln,k . Question: Use a Lagrange
interpolating polynomial of the first and second order to
evaluate f (2) on the basis of the data
(1, 0), (4, 1.386294), (6, 1.791760).
Solution:
n
Y x − xi
Lk (x) =
xk − xi
i=0,i̸=k
Example
Interpolation For n = 1:
(x−x1 ) (x−x0 )
Walter P1 (x) we have L0 (x) = (x0 −x1 ) and L1 (x) = (x1 −x0 )
Mudzimbabwe
Chapter 5 P1 (x) = L0 (x)f (x0 ) + L1 (x)f (x1 ).
2−4 2−1
So P1 (2) = (0) + (1.386294) = 0.4620981.
1−4 4−1
For n = 2:
P2 (x) we have L0 (x) = (x(x−x 1 )(x−x2 )
0 −x1 )(x0 −x2 )
,
(x−x0 )(x−x2 ) (x−x0 )(x−x1 )
L1 (x) = (x1 −x0 )(x1 −x2 ) , L2 (x) = (x2 −x0 )(x2 −x1 )
P2 (x) = L0 (x)f (x0 ) + L1 (x)f (x1 ) + L2 (x)f (x2 ).
(2 − 4)(2 − 6) (2 − 1)(2 − 6)
So P2 (2) = (0) + (1.386294)
(1 − 4)(1 − 6) (4 − 1)(4 − 6)
(2 − 1)(2 − 4)
+ (1.791760) = 0.565844.
(6 − 1)(6 − 4)
Example 2
Interpolation Use the following data to approximate f (1.5) using the
Walter Lagrange interpolating polynomial for n = 4.
Mudzimbabwe
Chapter 5
xi 1 1.3 1.6 1.9 2.2
f (xi ) 0.765198 0.620086 0.455402 0.281819 0.110362
Here L0 (x) = (x(x−x 1 )(x−x2 )(x−x3 )(x−x4 )
0 −x1 )(x0 −x2 )(x0 −x3 )(x0 −x4 )
etc.
Clearly we need code to do such tasks.
Finally,
P4 (x) = (((0.0018251x + 0.0552928)x − 0.343047)
x + 0.0733913)x + 0.977735,
which gives,
P4 (1.5) = 0.508939.
Newton’s Divided Differences
Interpolation
0. The zeroth divided difference of f w.r.t. xi is
Walter
Mudzimbabwe
f [xi ] = f (xi ) = fi .
1. The first divided difference of f w.r.t. xi and xi+1 is:
Chapter 5
f [xi+1 ] − f [xi ] fi+1 − fi
f [xi , xi+1 ] = =
xi+1 − xi xi+1 − xi
2. The Second divided difference of f w.r.t. xi , xi+1 and xi+2
is:
f [xi+1 , xi+2 ] − f [xi , xi+1 ]
f [xi , xi+1 , xi+2 ] =
xi+2 − xi
3. The k th divided difference of f w.r.t. xi , xi+1 , · · · , xi+k is:
f [xi , xi+1 , · · · , xi+k−1 , xi+k ] =
f [xi+1 , xi+2 , · · · , xi+k ] − f [xi , xi+1 , · · · , xi+k−1 ]
xi+k − xi
The polynomial
Interpolation
We fit a Pn (x) to the n + 1 data points
Walter
Mudzimbabwe (xi , f (xi )), i = 0, 1, · · · , n in the form:
Chapter 5
Pn (x) = a0 + a1 (x − x0 ) + a2 (x − x0 )(x − x1 ) + · · ·
+ an (x − x0 )(x − x1 ) · · · (x − xn−1 )
Since the polynomial must pass through the points (xi , fi ) we
have:
x = x0 , Pn (x0 ) = f (x0 ) so, a0 = f (x0 ) = f [x0 ].
x = x1 , Pn (x1 ) = f (x1 ) so, f [x0 ] + a1 (x1 − x0 ) =
f [x1 ] ⇒ a1 = f [xx11]−f
−x0
[x0 ]
= f [x0 , x1 ].
x = x2 , Pn (x2 ) = f (x2 ). ...... a2 = f [x0 , x1 , x2 ].
In general:
ak = f [x0 , x1 , · · · , xk ]
“Tree”
Interpolation Suppose:
Walter
Mudzimbabwe P3 (x) = a0 + a1 (x − x0 ) + a2 (x − x0 )(x − x1 )
Chapter 5 + a3 (x − x0 )(x − x1 )(x − x2 ).
We know that a0 = f [x0 ], a1 = f [x0 , x1 ], a2 = f [x0 , x1 , x2 ] and
a3 = f [x0 , x1 , x2 , x3 ]
xi f [xi ] f [xi , xi+1 ] f [xi , xi+1 , xi+2 ] f [xi , xi+1 , xi+2 , xi+3 ]
x0 f [x0 ]
f [x0 , x1 ]
x1 f [x1 ] f [x0 , x1 , x2 ]
f [x1 , x2 ] f [x0 , x1 , x2 , x3 ]
x2 f [x2 ] f [x1 , x2 , x3 ]
f [x2 , x3 ]
x3 f [x3 ]
Example
Interpolation Find a polynomial satisfied by (−4, 1245), (−1, 33), (0, 5), (2, 9)
Walter
Mudzimbabwe
Chapter 5
xi f [xi ] f [xi , xi+1 ] f [xi , xi+1 , xi+2 ] f [xi , xi+1 , xi+2 , xi+3 ]
-4 1245
-404
-1 33 94
-28 -14
0 5 10
2
2 9
∴ P3 (x) = 1245 − 404(x + 4) + 94(x + 4)(x + 1)
− 14(x + 4)(x + 1)x
= −14x 3 + 24x 2 + 52x + 5.