Professional Documents
Culture Documents
ECM6Lecture14aVietnam 2014
ECM6Lecture14aVietnam 2014
Slide 1 of 10
Lecture 14a
Lagrange Interpolation
Brian G. Higgins
Department of Chemical Engineering & Materials Science
University of California, Davis
April 2014, Hanoi, Vietnam
ECM6Lecture14aVietnam_2014.nb
Concept of Interpolation
In a previous lecture we were given a set of data points
88x0 , y0 <, 8x1 , y1 <, 8x2 , y2 <, 8x3 , y3 <, , 8xM , yM <<
and our goal was to find a polynomial that was a best fit of the data in the least squares sense. That
is, we selected the coefficients ai of the polynomial
P HxL = a0 + a1 x + a2 x2 + a3 x3 + + an xn
such that square of the error
M
E2 HPL = HP Hxi L - yi L2
i=1
was minimized. This was called linear regression. An alternative approach is to find a polynomial PHxL
such that
P Hxi L = yi , i = 0, 1, 2, , M
Thus we want to find the polynomial that passes through each data point.
In other words we require that the error at each xi be zero. This is the concept of polynomial interpolation.
We will see later in this lecture that interpolation is the corner stone for constructing algorithms for
implementing numerical integration.
ECM6Lecture14aVietnam_2014.nb
P1 HxL = a0 + a1 x
such that
P1 Hx0 L = a0 + a1 x0 = y0
P1 Hx1 L = a0 + a1 x1 = y1
Thus we have two equations for the two unknowns a0 and a1 . Solving this system of linear equations
gives
a1 =
y1 - y0
x1 - x0
a0 =
x1 y0 - x0 y1
x1 - x0
P1 HxL =
x1 y0 - x0 y1
x1 - x0
y1 - y0
x1 - x0
P1 HxL =
Hx - x1 L
Hx0 - x1 L
y0 +
Hx - x0 L
Hx1 - x0 L
x0 x x1
y1 ,
This formula is a linear interpolation of y between x0 and x1 . Linear interpolation is widely used to
interpolate thermodynamic tables, as illustrated in the following example.
Example 1
Thermodynamic steam tables give the enthalpy of steam at 20 MPa as a function of temperature
T (C)
70
80
h (kJ/kg)
309.26
350.78
We will use linear interpolation to determine the enthalpy h at temperatures between 70 and 80 C .
Substituting the above data points into Eq. (10) gives
h HTL =
HT - 80L
H70 - 80L
309.26 +
HT - 70L
H80 - 70L
350.78
ECM6Lecture14aVietnam_2014.nb
If we have more that two data points then it is possible to determine a higher order polynomial. In short
if we have n+1 data points we can find n+1 interpolating conditions given by Eq. (4) to determine n+1
polynomial conditions. We discuss this next
ECM6Lecture14aVietnam_2014.nb
88x0 , y0 <, 8x1 , y1 <, 8x2 , y2 <, 8x3 , y3 <, , 8xn , yn <<
and we want to determine a polynomial of degree n or less which passes through those points. We
begin our discussion by considering following polynomial
P HxL = c0 Hx - x1 L Hx - x2 L Hx - x3 L Hx - xn L
+ c1 Hx - x0 L Hx - x2 L Hx - x3 L Hx - xn L
+ c2 Hx - x0 L Hx - x1 L Hx - x3 L Hx - xn L
+
+ cn Hx - x0 L Hx - x1 L Hx - x2 L Hx - xn-1 L
Note that each term in the above expression is a polynomial of degree n. Thus the degree of P(x) is
also n.
c0 =
y0
Hx0 - x1 L Hx0 - x2 L Hx0 - x3 L Hx0 - xn L
y2
Hx2 - x0 L Hx2 - x1 L Hx2 - x3 L Hx2 - xn L
yn
Hxn - x0 L Hxn - x1 L Hxn - x2 L Hxn - xn-1 L
ECM6Lecture14aVietnam_2014.nb
P HxL = Pj HxL
j=0
Pj HxL = yj
k=0
x - xk
xj - xk
kj
Note we have color coded the indices to emphasize how the product sum is formed. If we write out the
interpolating polynomial explicitly we get
Hx - x1 L Hx - x2 L Hx - x3 L Hx - xn L
P HxL =
y0
Hx - x0 L Hx - x2 L Hx - x3 L Hx - xn L
y1
+
+
Hx - x0 L Hx - x1 L Hx - x2 L Hx - xn-1 L
Hxn - x0 L Hxn - x1 L Hxn - x2 L Hxn - xn-1 L
yn
Thus if you select one of the interpolating points x j , then all P j HxL terms vanish except the Pi HxL for the
given point of interest. It is sometimes more convenient to express the functions as
Pj HxL = yj fj ,
N
where
fj =
k=0
x - xk
xj - xk
kj
so that
N
f0 =
k=0
x - xk
x0 - xk
x - x1
x - x2
x - x3
x0 - x1 x0 - x2 x0 - x3
x - xN
x0 - xN
k0
f1 =
k=0
x - xk
x0 - xk
x - x0
x - x2
x - x3
x1 - x0 x1 - x2 x1 - x3
x - xN
x1 - xN
k1
etc
The set of f j 's can be thought of as set of basis functions, and y j the interpolation points. Note further
that since kj, the denominator in the product sum can never be zero.
ECM6Lecture14aVietnam_2014.nb
The set of f j 's can be thought of as set of basis functions, and y j the interpolation points. Note further
that since kj, the denominator in the product sum can never be zero.
ECM6Lecture14aVietnam_2014.nb
{{0,-3},{1,0},{3,30},{5,132}}
Substituting these values into our interpolating polynomial (19) gives
P HxL =
H-3L
Hx-3L Hx-5L
+ Hx-0L
H0L
H1-0L H1-3L H1-5L
H30L
H132L
Note that since y1 = 0 , the second term in the expression vanishes. Expanding the above polynomial
gives
P HxL = x2 + 2 x - 3
Here is a plot of the data and the polynomial
ECM6Lecture14aVietnam_2014.nb
PHxL
80
60
40
20
0
0
10
ECM6Lecture14aVietnam_2014.nb
Example 1
In this example we are given the following data points
{{1,4},{2,8},{3,4},{5,-2}}
And we want to find the interpolating polynomial that passes through the points
P3 = InterpolatingPolynomial@881, 4<, 82, 8<, 83, 4<, 85, - 2<<, xD
4 + 4 + -4 +
13
12
H- 3 + xL H- 2 + xL H- 1 + xL
1
12
H- 1 + xL I222 - 113 x + 13 x2 M
ECM6Lecture14aVietnam_2014.nb
PHxL
-5
-10
f0 HxL =
f1 HxL =
f2 HxL =
f3 HxL =
Hx - 2L Hx - 3L Hx - 5L
H1 - 2L H1 - 3L H1 - 5L
Hx - 1L Hx - 3L Hx - 5L
H2 - 1L H2 - 3L H2 - 5L
Hx - 1L Hx - 2L Hx - 5L
H3 - 1L H3 - 2L H3 - 5L
Hx - 1L Hx - 2L Hx - 3L
H5 - 1L H5 - 2L H5 - 3L
Hx - 2L Hx - 3L Hx - 5L
H1 - 2L H1 - 3L H1 - 5L
Hx - 1L Hx - 3L Hx - 5L
H2 - 1L H2 - 3L H2 - 5L
Hx - 1L Hx - 2L Hx - 5L
H3 - 1L H3 - 2L H3 - 5L
Hx - 1L Hx - 2L Hx - 3L
H5 - 1L H5 - 2L H5 - 3L
;
;
;
;
11
ECM6Lecture14aVietnam_2014.nb
PHxL
-5
-10
x
Now if we expand a function in terms of these polynomials in terms of a basis set of nth order, then we
must have n+1 terms
n
y HxL = yj fj HxL
j =0
where y j is the value of the function at the interpolation points. Here is plot of the individual basis
functions
Plot@8f0 , f1 , f2 , f3 <, 8x, 0, 6<,
PlotStyle 88Thick, Blue<, 8Red, Thick<, 8Magenta, Thick<, 8Thick, Orange<<,
Frame True, FrameLabel 8Style@"x", 16D, Style@"fi ", 16D<D
3
fi
12
-1
-2
0
x
Recall that the data used to generate these basis functions had values xo = 1, x1 = 2, x2 = 3, x3 = 5. This
plot illustrates that the basis function satisfy
fi Ixj M = 0, i j
ECM6Lecture14aVietnam_2014.nb
13
fi Ixj M = 0, i j
fi Ixj M = 1, i = j
0.5
0.5
1.0
1.5
2.0
-0.5
-1.0
Although the interpolating function is continuous at the data points, the derivatives are not continuous
Plot@myfunc '@xD, 8x, 0, 1<, PlotStyle Thick, Frame TrueD
3
-1
-2
-3
0.0
0.2
0.4
0.6
0.8
1.0
14
ECM6Lecture14aVietnam_2014.nb
-2
-3
-4
-5
-6
-7
-8
0.0
0.2
0.4
0.6
0.8
1.0
ECM6Lecture14aVietnam_2014.nb
f HxL x
a
An interpolating polynomial of the function f(x) that goes through the points a and b is
f HxL = f HaL f1 HxL + f HbL f2 HxL
where the interpolating polynomials are
f1 HxL =
Hx - bL
Ha - bL
, f2 HxL =
Hx - aL
Hb - aL
Since we have two interpolating points, the interpolating polynomial is linear. Hence our integral then
becomes
b
f HxL x :f HaL
Hx - bL2 - b2
1
2
2 Ha - bL
+ f HbL
Hx - aL2 - a2
2 Hb - aL
Hb - aL
2
8f HaL + f HbL<
Graphical Representation
This is called the trapezoidal rule. Here is a graphical interpretation
>
b
a
15
16
ECM6Lecture14aVietnam_2014.nb
1
2
Hb - aL Hf HaL - f HbLL
f HaL
= Hb - aL f HbL + Hb - aL
= Hb - aL :f HbL -
Hb - aL
2
f HbL
2
8f a)+f(b)}
2
+
f HaL
2
>
f HbL
2
ECM6Lecture14aVietnam_2014.nb
17
18
ECM6Lecture14aVietnam_2014.nb
References
The following textbooks were useful in preparing these notes:
B. Bradie, A Friendly Introduction to Numerical Analysis, Pearson Prentice Hall, 2006
A. J. Pettofrezzo, Introductory Numerical Analysis, Dover Publications, 1984
P. Wellin, R. Gaylord & S. Kamin, An Introduction to Programming with Mathematica, Cambridge
University Press, 2005