Loading [MathJax]/jax/output/HTML-CSS/jax.js
Skip to main content
Library homepage
 

Text Color

Text Size

 

Margin Size

 

Font Type

Enable Dyslexic Font
Mathematics LibreTexts

8: Interpolation

( \newcommand{\kernel}{\mathrm{null}\,}\)

Consider the following problem: Given the values of a known function y=f(x) at a sequence of ordered points x0,x1,,xn, find f(x) for arbitrary x. When x0xxn, the problem is called interpolation. When x<x0 or x>xn, the problem is called extrapolation.

With yi=f(xi), the problem of interpolation is basically one of drawing a smooth curve through the known points (x0,y0),(x1,y1),,(xn,yn). This is not the same problem as drawing a smooth curve that approximates a set of data points that have experimental error. This latter problem is called least-squares approximation, which is considered in the next chapter.

It is possible to interpolate the n+1 known points by a unique polynomial of degree n. When n=1, the polynomial is a linear function; when n=2, the polynomial is a quadratic function. Although low order polynomials are sometimes used when the number of points are few, higher-order polynomial interpolates tend to be unstable, and are not of much practical use.

Here, we will consider the more useful piece-wise polynomial interpolation. The two most used are piecewise linear interpolation, and cubic spline interpolation. The first makes use of linear polynomials, and the second cubic polynomials.

Piecewise linear interpolation

Here, we use linear polynomials. This is the default interpolation typically used when plotting data.

Suppose the interpolating function is y=g(x), and as previously, there are n+1 points to interpolate. We construct the function g(x) out of n local linear polynomials. We write

g(x)=gi(x), for xixxi+1,

where

gi(x)=ai(xxi)+bi

and i=0,1,,n1

We now require y=gi(x) to pass through the endpoints (xi,yi) and (xi+1,yi+1). We have

yi=biyi+1=ai(xi+1xi)+bi

Therefore, the coefficients of gi(x) are determined to be

ai=yi+1yixi+1xi,bi=yi

Although piecewise linear interpolation is widely used, particularly in plotting routines, it suffers from a discontinuity in the derivative at each point. This results in a function which may not look smooth if the points are too widely spaced. We next consider a more challenging algorithm that uses cubic polynomials.

Cubic spline interpolation

The n+1 points to be interpolated are again

(x0,y0),(x1,y1),(xn,yn).

Here, we use n piecewise cubic polynomials for interpolation,

gi(x)=ai(xxi)3+bi(xxi)2+ci(xxi)+di,i=0,1,,n1,

with the global interpolation function written as

g(x)=gi(x), for xixxi+1.

To achieve a smooth interpolation we impose that g(x) and its first and second derivatives are continuous. The requirement that g(x) is continuous (and goes through all n+1 points) results in the two constraints

gi(xi)=yi,i=0 to n1gi(xi+1)=yi+1,i=0 to n1

The requirement that g(x) is continuous results in

gi(xi+1)=gi+1(xi+1),i=0 to n2

And the requirement that g(x) is continuous results in

gi(xi+1)=gi+1(xi+1),i=0 to n2.

There are n cubic polynomials gi(x) and each cubic polynomial has four free coefficients; there are therefore a total of 4n unknown coefficients. The number of constraining equations from (8.7)-(8.10) is 2n+2(n1)=4n2. With 4n2 constraints and 4n unknowns, two more conditions are required for a unique solution. These are usually chosen to be extra conditions on the first g0(x) and last gn1(x) polynomials. We will discuss these extra conditions later.

We now proceed to determine equations for the unknown coefficients of the cubic polynomials. The polynomials and their first two derivatives are given by

gi(x)=ai(xxi)3+bi(xxi)2+ci(xxi)+digi(x)=3ai(xxi)2+2bi(xxi)+cigi(x)=6ai(xxi)+2bi

We will consider the four conditions (8.7)-(8.10) in turn. From (8.7) and (8.11), we have

di=yi,i=0 to n1,

which directly solves for all of the d-coefficients.

To satisfy (8.8), we first define

hi=xi+1xi,

and

fi=yi+1yi.

Now, from (8.8) and (8.11), using (8.14), we obtain the n equations

aih3i+bih2i+cihi=fi,i=0 to n1.

From (8.9) and (8.12) we obtain the n1 equations

3aih2i+2bihi+ci=ci+1,i=0 to n2

From (8.10) and (8.13) we obtain the n1 equations

3aihi+bi=bi+1i=0 to n2

It will be useful to include a definition of the coefficient bn, which is now missing. (The index of the cubic polynomial coefficients only go up to n1.) We simply extend (8.19) up to i=n1 and so write

3an1hn1+bn1=bn,

which can be viewed as a definition of bn.

We now proceed to eliminate the sets of a - and c-coefficients (with the d-coefficients already eliminated in (8.14)) to find a system of linear equations for the b-coefficients. From (8.19) and (8.20), we can solve for the na-coefficients to find

ai=13hi(bi+1bi),i=0 to n1.

From (8.17), we can solve for the n c-coefficients as follows:

ci=1hi(fiaih3ibih2i)=1hi(fi13hi(bi+1bi)h3ibih2i)=fihi13hi(bi+1+2bi),i=0 to n1

We can now find an equation for the b-coefficients by substituting (8.21) and (8.22) into (8.18) :

3(13hi(bi+1bi))h2i+2bihi+(fihi13hi(bi+1+2bi))=(fi+1hi+113hi+1(bi+2+2bi+1)),

which simplifies to

13hibi+23(hi+hi+1)bi+1+13hi+1bi+2=fi+1hi+1fihi

an equation that is valid for i=0 to n2. Therefore, (8.23) represent n1 equations for the n+1 unknown b-coefficients. Accordingly, we write the matrix equation for the b-coefficients, leaving the first and last row absent, as

( missing 13h023(h0+h1)13h100000013hn223(hn2+hn1)13hn1 missing )(b0b1bn1bn)( missing f1h1f0h0fn1hn1fn2hn2 missing ).

Once the missing first and last equations are specified, the matrix equation for the b-coefficients can be solved by Gaussian elimination. And once the b-coefficients are determined, the a - and c-coefficients can also be determined from (8.21) and (8.22), with the d-coefficients already known from (8.14). The piecewise cubic polynomials, then, are known and g(x) can be used for interpolation to any value x satisfying x0xxn.

The missing first and last equations can be specified in several ways, and here we show the two ways that are allowed by the MATLAB function spline.m. The first way should be used when the derivative g(x) is known at the endpoints x0 and xn; that is, suppose we know the values of α and β such that

g0(x0)=α,gn1(xn)=β.

From the known value of α, and using (8.12) and (8.22), we have

α=c0=f0h013h0(b1+2b0)

Therefore, the missing first equation is determined to be

23h0b0+13h0b1=f0h0α

From the known value of β, and using (8.12),(8.21), and (8.22), we have

β=3an1h2n1+2bn1hn1+cn1=3(13hn1(bnbn1))h2n1+2bn1hn1+(fn1hn113hn1(bn+2bn1)),

which simplifies to

13hn1bn1+23hn1bn=βfn1hn1

to be used as the missing last equation.

The second way of specifying the missing first and last equations is called the not-a-knot condition, which assumes that

g0(x)=g1(x),gn2(x)=gn1(x)

Considering the first of these equations, from (8.11) we have

a0(xx0)3+b0(xx0)2+c0(xx0)+d0

=a1(xx1)3+b1(xx1)2+c1(xx1)+d1.

Now two cubic polynomials can be proven to be identical if at some value of x, the polynomials and their first three derivatives are identical. Our conditions of continuity at x=x1 already require that at this value of x these two polynomials and their first two derivatives are identical. The polynomials themselves will be identical, then, if their third derivatives are also identical at x=x1, or if

a0=a1.

From (8.21), we have

13h0(b1b0)=13h1(b2b1),

or after simplification

h1b0(h0+h1)b1+h0b2=0,

which provides us our missing first equation. A similar argument at x=xn1 also provides us with our last equation,

hn1bn2(hn2+hn1)bn1+hn2bn=0.

The MATLAB subroutines spline.m and ppval.m can be used for cubic spline interpolation (see also interp1.m). I will illustrate these routines in class and post sample code on the course web site.

Multidimensional interpolation

Suppose we are interpolating the value of a function of two variables,

z=f(x,y).

The known values are given by

zij=f(xi,yj),

with i=0,1,,n and j=0,1,,n. Note that the (x,y) points at which f(x,y) are known lie on a grid in the xy plane.

Let z=g(x,y) be the interpolating function, satisfying zij=g(xi,yj). A two-dimensional interpolation to find the value of g at the point (x,y) may be done by first performing n+1 one-dimensional interpolations in y to find the value of g at the n+1 points (x0,y),(x1,y),, (xn,y), followed by a single one-dimensional interpolation in x to find the value of g at (x,y).

In other words, two-dimensional interpolation on a grid of dimension (n+1)×(n+1) is done by first performing n+1 one-dimensional interpolations to the value y followed by a single one-dimensional interpolation to the value x. Two-dimensional interpolation can be generalized to higher dimensions. The MATLAB functions to perform two-and three-dimensional interpolation are interp2.m and interp3.m.


This page titled 8: Interpolation is shared under a CC BY 3.0 license and was authored, remixed, and/or curated by Jeffrey R. Chasnov via source content that was edited to the style and standards of the LibreTexts platform.

Support Center

How can we help?