-
Interpolation order and local stencil size
Sample
f(x) = e−x cos(4x),
0 ≤ x ≤ 3
at 11 equally spaced points. Using the companion polynomial interpolation
routine, compare polynomial degrees 1 through 5. For degree d, use the
d + 1 data points nearest the evaluation point. Evaluate the
interpolant on a fine grid of at least 500 points and record the maximum
absolute error for each degree.
Repeat with 21 base points. Does increasing the local polynomial degree always
improve the result? Use direct evaluation of f(x) as the reference solution.
-
Unequally spaced data
Begin with 15 equally spaced points for
f(x) = 1/(1 + x2),
0 ≤ x ≤ 4.
Let Δx denote the original spacing. Move each interior point by a random
amount chosen uniformly between −0.15Δx and 0.15Δx, leaving
the two endpoints fixed. These perturbations are too small to reverse the
ordering of neighboring points. Compare linear, cubic local
polynomial, and cubic spline interpolation on the regular and irregular grids.
Repeat for several random grids and compare the maximum interpolation errors
with the exact function. Does irregular spacing affect all methods in the same
way?
-
Where is the interpolation error largest?
Tabulate
f(x) = tanh(3x),
−1 ≤ x ≤ 1
at 13 equally spaced points. Compare local linear, quadratic, cubic, and cubic
spline interpolation. Plot the pointwise error rather than only a single
average error, and identify where the maximum error occurs.
Relate the error distribution to the regions in which the function changes
most rapidly. Use direct evaluation of tanh(3x) as the reference.
-
Chebyshev nodes beyond the standard Runge example
Compare equally spaced and Chebyshev nodes for
f(x) = |x|,
−1 ≤ x ≤ 1.
Construct global interpolating polynomials using 9, 17, and 33 nodes. Plot the
interpolants and the pointwise errors on a fine grid. Use the Chebyshev extrema
xj = cos[jπ/(n − 1)], j = 0, …, n − 1. When
available, use barycentric evaluation to avoid instability in the polynomial
evaluation itself. Chebyshev spacing reduces the endpoint oscillations
associated with equally spaced nodes, but f(x) is not differentiable at x = 0.
Determine which difficulty remains even after the node distribution has been
improved, and compare how the maximum error changes as the number of nodes
increases. Estimate the convergence rate from a log–log plot of maximum
error versus the number of nodes.
-
Spline boundary conditions
Interpolate
f(x) = ex/2,
0 ≤ x ≤ 4
using 9 equally spaced data points. Compare natural, not-a-knot, clamped, and
the Forsythe–Malcolm–Moler (FMM)-type endpoint conditions used by the
companion spline program. For the clamped spline use the exact endpoint derivatives
f′(x) = (1/2)ex/2.
Plot the interpolation error near both ends of the interval and in the
interior. Which boundary condition is most accurate for this particular
function, and why?
-
Shape preservation and spline overshoot
Consider the monotonic tabulated data
x = [0, 1, 2, 3, 4, 5],
y = [0, 0.02, 0.10, 0.85, 0.97, 0.99].
Compare a standard cubic spline with a shape-preserving method such as PCHIP,
Steffen interpolation, or another monotonic piecewise cubic interpolant
available in your language.
Check whether either interpolant introduces artificial extrema or values
outside the data range 0 ≤ y ≤ 0.99. Plot both curves together with the
original data points.
-
Interpolation versus noisy data
Generate 21 exact values from
f(x) = e−x/2,
0 ≤ x ≤ 6,
and add independent, normally distributed zero-mean random perturbations
with standard deviations 0.01 and 0.05 to create two synthetic measurement
sets. Use a fixed random
seed so that your calculation can be reproduced.
Interpolate each noisy data set exactly with a cubic spline and compare the
result with the underlying exact function. The purpose is not to introduce
curve fitting, which is treated later in the book, but to demonstrate why
exact interpolation is inappropriate when the data themselves are uncertain.
Note that f(6) = e−3 ≈ 0.05, so the larger noise
standard deviation is about as large as the signal at the end of the interval.
As an optional extension, differentiate the interpolating spline and compare
its derivative with the exact derivative. This provides a direct link to the
noise-amplification problem discussed in Chapter 6.
-
Interpolation is not extrapolation
Tabulate
f(x) = ln(1 + x),
0 ≤ x ≤ 4
at 9 equally spaced points and construct several interpolants. First test them
only between known data points. Then evaluate them at x = 4.5, 5, and 6.
Compare the extrapolated values with the exact values
ln(5.5), ln(6), and ln(7).
How quickly does the error grow outside the sampled interval? Does a method
that interpolates well inside the data range necessarily extrapolate well?
-
Companion implementation versus a library routine
Choose either polynomial or cubic spline interpolation and compare the Chapter 5
companion implementation with a standard routine in your preferred language:
MATLAB interp1 or spline, SciPy interpolation
routines, GSL interpolation, or one of the specific Fortran options listed on
the Chapter 5 resources page.
Use one smooth test problem and one more demanding problem from the exercises
above. Compare accuracy, behavior near the boundaries, extrapolation policy,
ease of use, and any available endpoint options. Explain when a transparent
implementation helps you understand the algorithm and when a library routine
is the better practical choice.