Skip to content
PostNumerical Computation / Lecture

Numerical Computation Interpolation

2025-12-25
Back to Blog

Numerical Computation Interpolation

Data and interpolating functions

DEFINITION: The function y=P(x) interpolates the data points (x1,y1),,(xn,yn) if P(xi)=yi, for each 1in.

In polynomial interpolation, we find a polynomial (or set of polynomials) that passes through each data point.

Lagrange Interpolation

Given two (different) data points (x0,y0) and (x1,y1), there is a unique line through these points. The equation of the line through (x0,y0) and (x1,y1) is

yy0=y1y0x1x0(xx0).

NOTE: Consider the function

p(x)=y1xx0x1x0+y0xx1x0x1.

Clearly, p(x0)=y0 and p(x1)=y1. Also, p(x) is linear (degree = 1). Thus, p(x) must also be the equation of the line through (x0,y0) and (x1,y1). The terms in p(x) are called Lagrange Polynomials.

DEFINITION: For a given set of n+1 nodes xi, the Lagrange polynomials are the n+1 polynomials Li defined by

Li(x)=j=0,jinxxjxixj

DEFINITION: We define a Lagrange Interpolating polynomial pn(x) by

pn(x)=i=0nyiLi(x)

EXAMPLE

Find an interpolating polynomial for the data points (0,1), (2,2) and (3,4).

SOLUTION:

P2(x)=1(x2)(x3)(02)(03)+2(x0)(x3)(20)(23)+4(x0)(x2)(30)(32)=16(x25x+6)+2(12)(x23x)+4(13)(x22x)=12x212x+1.

THEOREM:
Let (x1,y1),,(xn,yn) be n points in the plane with distinct xi. Then there exists one and only one polynomial P of degree n1 or less that satisfies P(xi)=yi for i=1,,n.

PROOF:
The existence is proved by the explicit formula for Lagrange interpolation.

To show there is only one, assume for the sake of argument that there are two, say, P(x) and Q(x), that have degree at most n1 and that both interpolate all n points. That is, we are assuming that P(x1)=Q(x1)=y1, P(x2)=Q(x2)=y2, , P(xn)=Q(xn)=yn. Now define the new polynomial H(x)=P(x)Q(x). Clearly, the degree of H is also at most n1, and note that 0=H(x1)=H(x2)==H(xn); that is, H has n distinct zeros (roots). According to the Fundamental Theorem of Algebra, a degree d polynomial can have at most d zeros, unless it is the identically zero polynomial. Therefore, H is the identically zero polynomial, and P(x)Q(x). We conclude that there is a unique P(x) of degree n1 interpolating the n points (xi,yi).

Newton Interpolation

In Newton’s method, we create a polynomial p(x) for data (xi,yi) such that p(xi)=yi (Just as we did in the Lagrange Method).
The difference is that we construct p(x) iteratively.
That is we construct a sequence of polynomials p0(x),p1(x),,pn(x) such that pn(x) is the desired interpolating polynomial.

Algorithm:

  1. Let p0(x)=y0 (p0(x) matches data at x0)
  2. Suppose we have calculated pk(x) then, setpk+1(x)=pk(x)+c(xx0)(xx1)(xxk)for some constant c.

NOTE:
pk+1(xi)=pk(xi) for i=0,1,,k. So, pk+1(xi) correctly interpolates all data up to xk. To make it match at xk+1 we set

yk+1=pk(xk+1)+c(xk+1x0)(xk+1x1)(xk+1xk)

and solve for c.

EXAMPLE
Find an interpolating polynomial for the data points (0,1), (2,2) and (3,4) using Newton interpolating method.

p1(x)=c1

Let 1=p1(0)=c1c1=1

p2(x)=p1(x)+c2(x0)=1+c2(x0)

Let 2=p2(2)=1+2c2c2=12

p3(x)=p2(x)+c3(x0)(x2)=1+12x+c3x(x2)

Let 4=p3(3)=1+32+3c3c3=12

Hence,

p(x)=p3(x)=12x212x+1

which is the same as the result we found by Lagrange interpolating method.

Newton’s Nested formula

Newton’s Method vs Lagrange:

  • Both methods produce the same polynomial.
  • Newton’s Method is more flexible. It is easy to add new data points and get a new interpolating polynomial.
  • The coefficients in Newton’s Method (determined by solving for the constants c) can be calculated very efficiently. (Newton divide difference)

From previous example, without calculating the coefficient, we can write

p(x)=c1+c2(x0)+c3(x0)(x2).

It can be rewritten as

p(x)=c1+(x0)[c2+c3(x2)].

In general,

pn(x)=c1+[c2(xx1)]++[cn(xx1)(xx1)(xxn1)]

can be rewritten as

pn(x)=c1+(xx1)[c1+(xx2)[c3+(xx3)[]]]

called Newton’s nested formula.

pn(x)=c1+(xx1)[c2+(xx2)[c3+(xx3)[]]]

allows a better way of calculating pn(t) for a value t (or x):

v1=cnv2=cn1+(txn1)v1v3=cn2+(txn2)v2vn=c1+(tx1)vn1

Then, vn=pn(t) Newton’s Nested formula requires 2(n1) additions and n1 multiplications. 3(n1)O(n) Lagrange Interpolation requires at least n2 operations O(n2)

p(x)=k(jknxxjxkxj)yk

Following we will introduce an efficient way to calculate the coefficient ck.

DEFINITION:

For a given collection of data {(xi,f(xi))} a kth order divided difference is a function of k+1 (not necessarily distinct) data values written as f[xi,xi+1,...,xi+k].

1st Order: f[xi]=f(xi)=yikth Order:

f[xi,xi+1,...,xi+k1,xi+k]=f[xi+1,xi+2,...,xi+k]f[xi,xi+1,...,xi+k1]xi+kxi

THEOREM

For Newton’s Interpolation formula

pn(x)=c1+[c2(xx1)]++[cn(xx1)(xx1)(xxn1)]

the coefficients ck can be calculated as

ck=f[x1,x2,...,xk]

The recursive definition of the Newton’s divided differences allows arrangement into a convenient table. For three points the table has the form

x1f[x1]c1f[x1 x2]c2x2f[x2]f[x1 x2 x3]c3f[x2 x3]x3f[x3]

The coefficients of the Newton’s Interpolation formula can be read from the top edge of the triangle.

EXAMPLE

Use divided differences to find the interpolating polynomial passing through the points (0,1), (2,2) and (3,4).

SOLUTION

The divided differences are calculated as follows:

2120=124232=221230=12

The coefficients of the polynomial 1, 1/2, 1/2 can be read from the top edge of the table. The interpolating polynomial can be written as

p(x)=1+12(x0)+12(x0)(x2),

or, in nested form

p(x)=1+(x0)(12+12(x2)).

Approximating Polynomials and Interpolation Error

A major use of polynomial interpolation is to replace evaluation of a complicated function by evaluation of a polynomial, which involves only elementary computer operations like addition, subtraction, and multiplication.

EXAMPLE:

Interpolate the function f(x)=sinx at 4 equally spaced points on [0,π/2].

SOLUTION

p(x)=0+x(0.9549+(xπ6)(0.2443+(xπ3)(0.1139))).00.00000.9549π/60.50000.24430.69900.11392π/60.86600.42320.25593π/61.0000

We can repeat the process on the interval [π2,π],[π,3π2],... based on sinx symmetry and antisymmetric.

The error for degree 3 interpolation of sinx is shown below.

In order to get enough correct digits to fill the calculator readout, we’ll need to know a little more about interpolation error.

[A graph is shown here with the function y=sin(x) and its interpolation, along with a table of values and errors]

xsinxsin1(x)error
10.84150.84110.0004
20.90930.91020.0009
30.14110.14280.0017
40.75680.75570.0011
140.99060.99280.0022
10000.82690.82630.0006

THEOREM

Assume that P(x) is the (degree n1 or less) interpolating polynomial fitting the n points (x1,y1),...,(xn,yn). The interpolation error is

f(x)P(x)=(xx1)(xx2)...(xxn)n!f(n)(c)

where c lies between the smallest and largest of the number x,x1,...,xn.

PROOF

Consider adding one more point x to the set of interpolation points. The new interpolation polynomial would be

Pn(t)=Pn1(t)+f[x1,x2,...,xn,x](tx1)(txn).

At the point x, Pn(x)=f(x), so

f(x)=Pn1(x)+f[x1,x2,...,xn,x](xx1)(xxn).

Now define

h(t)=f(t)Pn1(t)f[x1,x2,...,xn,x](tx1)(txn).

Note that h(x)=0=h(x1)==h(xn).

By Rolle’s theorem, there are n points between each neighboring pair of n+1 points x1,x2,...,xn,x that h=0.

Furthermore, there are n1 points between each neighboring pair of those n points found above that h=0.

Continuing in this way, there must be one point c for which h(n)=0, where c lies between the smallest and largest of the number x,x1,...,xn.

Takes nth order derivative for above equation, we got

h(n)(t)=f(n)(t)n!f[x1,x2,...,xn,x].

because the nth order derivative of Pn1(t) is zero. Substituting c gives

f[x1,x2,...,xn,x]=f(n)(c)n!,

which leads to

f(x)=Pn1(x)+f(n)(c)n!(xx1)(xxn).

EXAMPLE

Find an upper bound for the difference at x=0.25 and x=0.75 between f(x)=ex and the polynomial that interpolates it at the points 1,0.5,0,0.5,1.

SOLUTION

f(x)P4(x)=(x+1)(x+12)x(x12)(x1)5!f(5)(c),

which 1<c<1. So f(5)(c)=ece.

At x=0.25,

|e0.25P4(0.25)||(1.25)(0.75)(0.25)(0.25)(0.75)5!e|0.000995.

At x=0.75,

|e0.75P4(0.75)||(1.75)(1.25)(0.75)(0.25)(0.25)5!e|0.002323.

Cubic Splines

A spline curve is a curve that is made of a set of simple curves (lines, quadratics, cubic) that are joined together. A spline is piece-wise defined. That is, it is defined over a set of sub-intervals of a given interval. This set is called a partition.

DEFINITION: A partition of an interval [a,b] is a sequence {ti}i=1n of points between a and b such that

a=t1<t2<<tn=b

The numbers ti (i=2 to n1) are called knots.

DEFINITION: A function S is a linear spline on [a,b] if

  • The domain of S is [a,b]
  • S is continuous on [a,b]
  • There is a partition {ti}i=1n of points on [a,b] such that S is a linear function on each sub-interval [ti,ti+1]

A linear spline is defined by its values at the set of knots. Given the table of values there is a unique linear spline with those values.

tt1t2tn
yy1y2yn

On each sub-interval, [ti,ti+1], the linear spline is defined by

Si(x)=yi+yi+1yiti+1ti(xti)

Then, Si(ti)=yi and Si(ti+1)=yi+1

EXAMPLE:

t0.00.10.40.50.751.0
y1.34.52.02.15.03.0

[A graph of a linear spline connecting the points from the table is shown here]


Quadratic Spline

DEFINITION: A function Q is a quadratic spline on [a,b] if

  • The domain of Q is [a,b]
  • Q is continuous on [a,b]
  • Q is continuous on [a,b]
  • There is a partition {ti}i=1n of points on [a,b] such that Q is a polynomial of degree 2 on each sub-interval [ti,ti+1]
Q(x)=a1+b1(xt1)+c1(xt1)2,t1xt2=a2+b2(xt2)+c2(xt2)2,t2xt3==an1+bn1(xtn1)+cn1(xtn1)2,tn1xtn

Thus, we need to determine 3(n1) different constants.


We know that:

Qi(ti)=yiQi(ti+1)=yi+1Qi(ti+1)=Qi+1(ti+1)(Q is continuous at knots)

This gives (n1)+(n1)+(n2)=3(n1)1 equations for 3(n1) unknown!

Need one more condition on Q. Could use one of these

c1=0(Q1 is a line)Q(t1)=z(slope at start)Q(t1)=w(curvature at start)

EXAMPLE Data x=[0 1 4], y=[1 2 1]. Find Q1(x) and Q2(x) when Q1(0)=0. SOLUTION Define

Q1(x)=a1+b1(x0)+c1(x0)2,0x1Q2(x)=a2+b2(x1)+c2(x1)2,1x4Q1(x)=b1+2c1xQ2(x)=b2+2c2(x1)

By quadratic spline definition,

Q1(0)=0b1=0;Q1(0)=1a1=1;Q2(1)=2a2=2Q1(1)=2c1+1=2c1=3Q1(1)=Q2(1)b2=6Q2(4)=19c2+3b2+a2=1c2=73.

Hence

Q1(x)=3x2+1Q2(x)=73(x1)26(x1)2
  • 计算步长: δi=xi+1xi
  • 利用插值条件: 直接得出 ai=yi
  • 利用连续性: 列出关于 bici 的递归关系。
  • 利用一阶导数连续: 得到 bi+1=bi+2ciδi
  • 代入边界条件: 假设 c0=0,然后从左到右依次解出所有的 bici

Cubic Spline

DEFINITION: A function S is a cubic spline on [a,b] if

  • The domain of S is [a,b]
  • S is continuous on [a,b]
  • S is continuous on [a,b]
  • S is continuous on [a,b]
  • There is a partition {ti}i=1n of points on [a,b] such that S is a polynomial of degree 3 on each sub-interval [ti,ti+1]
S(x)=y1+b1(xt1)+c1(xt1)2+d1(xt1)3,t1xt2=y2+b2(xt2)+c2(xt2)2+d2(xt2)3,t2xt3==yn1+bn1(xtn1)+cn1(xtn1)2+dn1(xtn1)3,tn1xtn

Property 1:Si(ti)=yi and Si(ti+1)=yi+1 for i=1,...,n1.

Property 2:Si1(ti)=Si(ti) for i=2,...,n1.

Property 3:Si1(ti)=Si(ti) for i=2,...,n1.


EXERCISE Check that

S1(x)=2138(x1)+0(x1)2+58(x1)3 on [1,2]S2(x)=1+14(x2)+158(x2)258(x2)3 on [2,4]S3(x)=4+14(x4)158(x4)2+58(x4)3 on [4,5]

satisfies all cubic spline properties for the data points (1,2),(2,1),(4,4) and (5,3).


Constructing a spline from a set of data points means finding the coefficients bi,ci,di that make Properties 1-3 hold. Properties 1-3 gives n1+2(n2)=3n5 independent equations. The total number of the coefficients bi,ci,di is 3(n1)=3n3. Therefore, solving for the coefficients is a problem of solving 3n5 linear equations in 3n3 unknowns. Two extra equations needed!

Property 4 Natural splineS1(t1)=0 and Sn1(tn)=0.


Property 1: Si(ti+1)=yi+1 for i=1,...,n1. (n-1 equations)

y2=S1(t2)=y1+b1(t2t1)+c1(t2t1)2+d1(t2t1)3yn=Sn1(tn)=yn1+bn1(tntn1)+cn1(tntn1)2+dn1(tntn1)3.

Property 2: Si1(ti)=Si(ti) for i=2,...,n1. (n-2 equations)

0=S1(t2)S2(t2)=b1+2c1(t2t1)+3d1(t2t1)2b20=Sn2(tn1)Sn1(tn1)=bn2+2cn2(tn1tn2)+3dn2(tn1tn2)2bn1.

Property 3: Si1(ti)=Si(ti) for i=2,...,n1. (n-2 equations)

0=S1(t2)S2(t2)=2c1+6d1(t2t1)2c20=Sn2(tn1)Sn1(tn1)=2cn2+6dn2(tn1tn2)2cn1.

Let δi=ti+1ti and Δi=yi+1yi. If we know all ci, from property 3 we can solve

di=ci+1ci3δi

From property 1 we can solve

bi=Δiδiciδidiδi2=Δiδiciδici+1ci3δiδi2=Δiδiδi3(2ci+ci+1)

for i=1,...,n1.

Substituting di=ci+1ci3δi and bi=Δiδiδi3(2ci+ci+1) into property 2 we can solve

δici+2(δi+δi+1)ci+1+δi+1ci+2=3(Δi+1δi+1Δiδi)

for i=1,...,n2.


Property 4 Natural spline S1(t1)=0 and Sn1(tn)=0. (2 equations)

0=S1(t1)=2c10=Sn1(tn)=2cn

This gives a total of n equations in n unknowns ci, which can be written in the matrix form

[100δ12(δ1+δ2)δ20δ22(δ2+δ3)δ3δn22(δn2+δn1)δn1001][c1cn]=[03(Δ2δ2Δ1δ1)3(Δn1δn1Δn2δn2)0].

EXAMPLE

Find the natural cubic spline through (0,3),(1,2) and (2,1).

SOLUTION

δ1=10=1;δ2=21=1;Δ1=23=5;Δ2=1(2)=3

[100141001][c1c2c3]=[0240]

[c1,c2,c3]=[0,6,0].

d1=c2c13δ1=63=2;d2=c3c23δ2=63=2b1=Δ1δ1δ13(2c1+c2)=513(6)=7;b2=Δ2δ2δ23(2c2+c3)=313(12)=1

Therefore, the cubic spline is

S1(x)=37x+0x2+2x3 on [0,1]S2(x)=21(x1)+6(x1)22(x1)3 on [1,2].