Interpolation
Temperature Profile in a Rod
A metal rod of length L = 10 cm has its temperature measured at discrete points along its
length as follows:
Position x (cm) 0 2 4 6 8 10
Temperature T (x) (°C) 100 90 60 65 80 70
Our goal is to reconstruct the temperature T (x) everywhere along the rod based on these
discrete measurements.
Problem: Given these discrete points, estimate T (x) for any x ∈ [0, 10] by exploring various
interpolation methods.
1 Introduction to Interpolation
Interpolation is the process of estimating unknown values of a function from known data
points. We assume a smooth underlying function and attempt to reconstruct it using a
mathematical formula that passes through all given points.
1.1 Why Interpolation?
• In physics, measurements are often taken at discrete points.
• To analyze, predict, or visualize behavior between measured points, interpolation is
necessary.
• Different interpolation methods offer different trade-offs in accuracy, smoothness, and
computational complexity.
2 Single Polynomial Interpolation
2.1 Concept
Given n + 1 data points {(xi , Ti )}ni=0 , there exists a unique polynomial P (x) of degree at
most n passing through all points:
P (xi ) = Ti , i = 0, 1, . . . , n.
1
2.2 Lagrange Interpolation Formula
The polynomial can be expressed as:
n
X
P (x) = Ti Li (x),
i=0
where the Lagrange basis polynomials Li (x) are defined by
n
Y x − xj
Li (x) = .
x − xj
j=0 i
j̸=i
Each Li (x) satisfies Li (xj ) = δij .
2.3 Application to Our Data
Using the six points given, construct a degree 5 polynomial P (x) passing through all data.
Tasks:
• Compute P (5) — estimate the temperature at x = 5 cm.
• Plot P (x) for x ∈ [0, 10].
• Observe and discuss any oscillations, particularly near the edges (Runge’s phenomenon).
2.4 Discussion: Limitations of Single High-Degree Polynomials
- High-degree polynomials can oscillate wildly between points. - Sensitive to data spacing
and noise. - Computationally expensive and numerically unstable for large n.
3 Piecewise Linear Interpolation
3.1 Concept
Instead of a single polynomial over the entire interval, approximate T (x) on each interval
[xi , xi+1 ] by a linear function connecting the two points.
3.2 Formula
For x ∈ [xi , xi+1 ],
Ti+1 − Ti
T (x) = Ti + (x − xi ).
xi+1 − xi
2
3.3 Application
Tasks:
• Plot the piecewise linear interpolation over [0, 10].
• Compare to the single polynomial interpolation.
• Discuss the lack of smoothness at the nodes.
4 Piecewise Cubic Spline Interpolation
4.1 Concept
Piecewise cubic splines consist of cubic polynomials on each interval joined smoothly so that
the entire function is continuous with continuous first and second derivatives.
4.2 Spline Conditions
For n intervals and splines Si (x) defined on [xi , xi+1 ]:
Si (xi ) = Ti , Si (xi+1 ) = Ti+1 , i = 0, . . . , n − 1,
Si′ (xi+1 ) = Si+1
′
(xi+1 ), Si′′ (xi+1 ) = Si+1
′′
(xi+1 ), i = 0, . . . , n − 2.
Additionally, natural spline boundary conditions:
S0′′ (x0 ) = 0, ′′
Sn−1 (xn ) = 0.
4.3 Formulating the System
The spline coefficients satisfy a linear system derived from the above conditions. This system
can be efficiently solved using numerical linear algebra methods.
4.4 Tasks:
• Formulate and solve the system for our data.
• Plot the cubic spline interpolation.
• Calculate T (5) using the spline.
• Compare smoothness and accuracy with previous methods.
3
5 Summary and Discussion
• Single polynomial interpolation can approximate well for small n but suffers from
oscillations at higher degrees.
• Piecewise linear interpolation is simple and avoids oscillations but lacks smooth-
ness.
• Cubic splines combine the advantages — smooth, stable, and accurate interpolation.
• Why piecewise? Complex or noisy data often cannot be well-approximated globally;
piecewise methods balance flexibility and smoothness.
6 Further Extensions
• Hermite interpolation if derivatives at points are known.
• Least squares polynomial fitting for noisy data.
• Chebyshev nodes to mitigate Runge’s phenomenon.
Lagrange Basis Polynomials
Lagrange basis polynomials provide a foundation for constructing interpolating polynomials
from a given set of data points. In this document, we present a detailed discussion on the
structure, purpose, and application of Lagrange basis polynomials.
Suppose we are given n + 1 distinct data points:
(x0 , y0 ), (x1 , y1 ), . . . , (xn , yn )
Our goal is to find a polynomial P (x) of degree at most n such that:
P (xi ) = yi for all i = 0, 1, . . . , n.
Lagrange Interpolation Formula
The interpolating polynomial is constructed as:
n
X
P (x) = yi · Li (x)
i=0
where Li (x) is the Lagrange basis polynomial, defined as:
n
Y x − xj
Li (x) =
x − xj
j=0 i
j̸=i
4
Key Properties of Li (x):
• Li (xi ) = 1
• Li (xj ) = 0 for all j ̸= i
This means that each Li (x) is designed to be 1 at xi and 0 at all other xj , ensuring that
P (x) passes through each data point exactly.
Example with 3 Points
Let:
(x0 , y0 ) = (1, 2), (x1 , y1 ) = (2, 3), (x2 , y2 ) = (4, 1)
Then the basis polynomials are:
(x − x1 )(x − x2 ) (x − 2)(x − 4) (x − 2)(x − 4)
L0 (x) = = =
(x0 − x1 )(x0 − x2 ) (1 − 2)(1 − 4) 3
(x − x0 )(x − x2 ) (x − 1)(x − 4) (x − 1)(x − 4)
L1 (x) = = =−
(x1 − x0 )(x1 − x2 ) (2 − 1)(2 − 4) 2
(x − x0 )(x − x1 ) (x − 1)(x − 2) (x − 1)(x − 2)
L2 (x) = = =
(x2 − x0 )(x2 − x1 ) (4 − 1)(4 − 2) 6
Then the interpolating polynomial is:
P (x) = y0 L0 (x) + y1 L1 (x) + y2 L2 (x) = 2L0 (x) + 3L1 (x) + 1L2 (x)
Insights
1. Basis Function Behavior
Each Li (x) acts as a “selector”:
• It equals 1 at xi , so the term yi · Li (x) contributes exactly yi to P (xi ).
• It equals 0 at all other xj , ensuring no unwanted contributions at other nodes.
2. Polynomial Space
Each Li (x) is a degree-n polynomial. The set {L0 (x), L1 (x), . . . , Ln (x)} forms a basis for the
vector space of all polynomials of degree at most n, denoted Pn .
5
3. Reusability
Once the xi ’s are fixed, the Li (x)’s do not depend on the yi ’s. This makes them reusable for
multiple datasets with the same xi but different yi .
Advantages
• Simple and explicit formula
• No need to solve a system of equations
• Intuitive construction
Disadvantages
• Computationally expensive for large n
• Global: changing one data point affects the whole polynomial
• Sensitive to numerical errors and oscillations (Runge’s phenomenon)
Conclusion
Lagrange basis polynomials provide an elegant way to construct interpolating polynomials.
They offer deep insight into polynomial interpolation theory and are excellent for under-
standing foundational concepts, even though they may not be ideal for large-scale numerical
applications.
The Runge Phenomenon
The Runge Phenomenon is a classic example of failure in polynomial interpolation. It
demonstrates how using high-degree interpolating polynomials at equally spaced points can
lead to large oscillations near the endpoints of the interpolation interval, even when the
underlying function is smooth.
Runge’s Function
Consider the function introduced by Carl Runge:
1
f (x) =
1 + 25x2
This function is:
• Smooth and infinitely differentiable.
6
• Symmetric about x = 0.
• Bounded over any finite interval.
Interpolation Problem
Let us interpolate f (x) on the interval [−1, 1] using n + 1 equally spaced points:
2i
xi = −1 + , i = 0, 1, 2, . . . , n
n
At these nodes, define the polynomial Pn (x) such that:
Pn (xi ) = f (xi )
We can construct Pn (x) using Lagrange interpolation or any other interpolation tech-
nique.
Observed Behavior
As n increases:
• Pn (x) begins to oscillate significantly near the endpoints x = −1 and x = 1.
• The interpolating polynomial does not converge uniformly to f (x).
• The interpolation error increases with n, especially at the edges.
This undesirable behavior is called the Runge Phenomenon.
Why It Happens
1. Equally spaced nodes lead to poor conditioning in polynomial interpolation, espe-
cially near boundaries.
2. The Lagrange basis polynomials become large in magnitude near the endpoints,
amplifying numerical errors.
3. The polynomial tries to fit the entire interval globally, leading to overfitting at the
edges.
Example
For n = 5, 10, 15, 20, construct interpolating polynomials Pn (x). As n increases, plots of
Pn (x) will show increasing oscillations, especially near x = −1 and x = 1.
7
Remedies
1. Use Chebyshev Nodes
Choose interpolation nodes as:
2i + 1
xi = cos π , i = 0, 1, . . . , n
2(n + 1)
These nodes cluster near the endpoints and reduce oscillations.
2. Use Piecewise Interpolation
• Piecewise Linear Interpolation: Connect points with straight lines.
• Cubic Splines: Piecewise cubic polynomials that are smooth and stable.
Summary
• The Runge Phenomenon highlights a limitation of high-degree polynomial interpolation
using equally spaced points.
• Despite a smooth target function, interpolation can fail dramatically due to numerical
instability.
• Solutions include using better node distributions (like Chebyshev nodes) or adopting
piecewise interpolation techniques such as splines.
Newton’s Divided Difference Interpolation
Newton’s Divided Difference method is a popular and efficient technique to construct an
interpolating polynomial for a given set of data points. It builds the polynomial incrementally
and provides an easy way to add new data points without recalculating the entire polynomial.
Problem Setup
Given n + 1 distinct data points:
(x0 , y0 ), (x1 , y1 ), . . . , (xn , yn )
we want to find a polynomial Pn (x) of degree at most n such that
Pn (xi ) = yi , i = 0, 1, . . . , n.
8
Newton’s Divided Difference Polynomial
The interpolating polynomial can be written as:
Pn (x) = f [x0 ]+f [x0 , x1 ](x−x0 )+f [x0 , x1 , x2 ](x−x0 )(x−x1 )+· · ·+f [x0 , x1 , . . . , xn ](x−x0 )(x−x1 ) · · · (x−xn−1
where f [xi , xi+1 , . . . , xj ] are the divided differences defined recursively.
Divided Differences
Zero Order Divided Differences
The zero order divided differences are simply the function values at the data points:
f [xi ] = yi
Higher Order Divided Differences
For j > i, the divided differences are defined recursively by:
f [xi+1 , . . . , xj ] − f [xi , . . . , xj−1 ]
f [xi , xi+1 , . . . , xj ] =
xj − xi
Interpretation: The divided difference f [xi , . . . , xj ] represents the slope of the polyno-
mial passing through the points (xi , yi ), . . . , (xj , yj ).
Example
Consider three points:
(x0 , y0 ) = (1, 2), (x1 , y1 ) = (2, 3), (x2 , y2 ) = (4, 1)
Calculate the divided differences:
f [x0 ] = 2, f [x1 ] = 3, f [x2 ] = 1
First order divided differences:
f [x1 ] − f [x0 ] 3−2
f [x0 , x1 ] = = =1
x1 − x0 2−1
f [x2 ] − f [x1 ] 1−3
f [x1 , x2 ] = = = −1
x2 − x1 4−2
Second order divided difference:
f [x1 , x2 ] − f [x0 , x1 ] −1 − 1 −2 2
f [x0 , x1 , x2 ] = = = =−
x2 − x0 4−1 3 3
9
Thus, the interpolating polynomial is:
2
P2 (x) = 2 + 1(x − 1) − (x − 1)(x − 2)
3
Advantages of Newton’s Form
• Efficient for adding new data points without recomputing all coefficients.
• Divided difference table provides an organized method for computation.
• Numerically stable compared to high-degree Lagrange interpolation.
Summary
Newton’s Divided Difference interpolation provides a systematic way to construct interpo-
lating polynomials using recursive divided differences. The resulting polynomial is easy to
evaluate and extend, making it practical for numerical applications.
Spline Conditions in Interpolation
Spline interpolation fits piecewise polynomials, usually cubic, between given data points such
that the overall function is smooth and continuous.
Given data points:
(x0 , y0 ), (x1 , y1 ), . . . , (xn , yn )
we want to find cubic polynomials Si (x) defined on intervals [xi , xi+1 ], for i = 0, 1, . . . , n − 1,
of the form:
Si (x) = ai + bi (x − xi ) + ci (x − xi )2 + di (x − xi )3
Spline Conditions
To determine the coefficients ai , bi , ci , di , the following conditions are applied:
1. Interpolation condition (function matches data points):
Si (xi ) = yi , Si (xi+1 ) = yi+1 , i = 0, . . . , n − 1
2. Continuity of first derivative:
Si′ (xi+1 ) = Si+1
′
(xi+1 ), i = 0, . . . , n − 2
3. Continuity of second derivative:
Si′′ (xi+1 ) = Si+1
′′
(xi+1 ), i = 0, . . . , n − 2
10
4. Boundary conditions: To uniquely determine the spline, two additional conditions
are needed, common ones are:
• Natural spline:
S0′′ (x0 ) = 0, ′′
Sn−1 (xn ) = 0
• Clamped spline:
S0′ (x0 ) = f ′ (x0 ), ′
Sn−1 (xn ) = f ′ (xn )
Derivatives
The first and second derivatives of Si (x) are:
Si′ (x) = bi + 2ci (x − xi ) + 3di (x − xi )2
Si′′ (x) = 2ci + 6di (x − xi )
Step-by-step setup
Define the interval length:
hi = xi+1 − xi
Using interpolation conditions at xi and xi+1 :
Si (xi ) = ai = yi
Si (xi+1 ) = ai + bi hi + ci h2i + di h3i = yi+1
First derivative continuity at internal nodes:
bi + 2ci hi + 3di h2i = bi+1
Second derivative continuity at internal nodes:
2ci + 6di hi = 2ci+1
Boundary conditions (natural spline example):
c0 = 0, 2cn−1 + 6dn−1 hn−1 = 0
Example
Given points:
(1, 1), (2, 4), (3, 9)
Number of intervals: n = 2, with
h0 = 2 − 1 = 1, h1 = 3 − 2 = 1
Set:
a0 = y0 = 1, a1 = y1 = 4
11
From interpolation conditions:
S0 (2) = a0 + b0 h0 + c0 h20 + d0 h30 = 4 =⇒ 1 + b0 + c0 + d0 = 4
b0 + c0 + d0 = 3
S1 (3) = a1 + b1 h1 + c1 h21 + d1 h31 = 9 =⇒ 4 + b1 + c1 + d1 = 9
b1 + c 1 + d 1 = 5
First derivative continuity at x = 2:
b0 + 2c0 h0 + 3d0 h20 = b1 =⇒ b0 + 2c0 + 3d0 = b1
Second derivative continuity at x = 2:
2c0 + 6d0 h0 = 2c1 =⇒ 2c0 + 6d0 = 2c1
Natural spline boundary conditions:
c0 = 0, 2c1 + 6d1 h1 = 0 =⇒ 2c1 + 6d1 = 0
These equations can be solved to find all the coefficients bi , ci , di .
Problem Statement
A mechanical engineer measures the displacement y (in millimeters) of a vibrating beam at
specific time points t (in seconds). The data recorded is:
Time t (s) Displacement y (mm)
0 0
1 1.5
2 3.0
3 2.5
4 0.5
Tasks
1. Single Polynomial Interpolation:
Find the single polynomial P (t) of degree 4 that passes through all five points using
both:
• Lagrange interpolation formula
• Newton’s divided difference formula
2. Piecewise Cubic Spline Interpolation:
Construct a cubic spline interpolation function S(t) that passes through all the points
and has continuous first and second derivatives.
12
3. Evaluation:
Using the above interpolation functions, estimate the displacement at:
t = 2.5 seconds, t = 3.5 seconds
4. Comparison:
Compare the estimated displacement values obtained from the single polynomial in-
terpolation and the spline interpolation at the above points. Discuss which method is
more reliable for this mechanical vibration data.
Notes
• The displacement values are non-monotonic, showing that the beam rises and falls
during vibration.
• Single polynomial interpolation of degree 4 will produce one polynomial passing through
all points.
• Cubic spline interpolation uses piecewise cubic polynomials to ensure smoothness.
HW : Interpolating Potential Energy in Classical Me-
chanics
Context:
A particle moves in a one-dimensional conservative force field. The potential energy U (x) is
known only at a few discrete positions (e.g., obtained from experiments or simulations). You
are required to estimate the potential and force at arbitrary positions using interpolation
techniques.
Given: Potential energy values of a particle along the x-axis:
x (m) 0.0 0.5 1.0 1.5 2.0
U (x) (J) 0.0 -1.2 -1.8 -1.3 0.0
(a) Use cubic spline interpolation to estimate the potential energy U (x) at x = 1.25 m.
(b) Use the derivative of the spline to estimate the force F (x) = − dU
dx
at x = 1.25 m.
(c) Comment on why interpolation of potential energy is often preferred over direct force
interpolation in numerical mechanics simulations (such as molecular dynamics).
13
HW: Interpolating the Partition Function in Statistical
Mechanics
Context:
In statistical mechanics, the canonical partition function Z(T ) is essential for calculating
thermodynamic properties. It is often computed numerically at discrete temperature values.
Accurate interpolation of ln Z(T ) is important for computing quantities like internal energy
and heat capacity.
Given: Natural logarithm of the partition function values for a quantum system:
T (K) 100 200 300 400 500
ln Z(T ) 2.5 3.2 3.8 4.1 4.3
(a) Fit a Lagrange interpolation polynomial to estimate ln Z(T ) at T = 350 K.
(b) Estimate the internal energy using
d d
U (T ) = − ln Z = kB T 2 ln Z(T ),
dβ dT
assuming kB = 1, by numerically differentiating your interpolated polynomial at T =
350 K.
(c) Discuss the pros and cons of polynomial interpolation vs. spline interpolation when
applied to thermodynamic functions like ln Z(T ), U (T ), or CV (T ).
14