$30
MATH 340
LAB 7 Assignment
Interpolation using Cubic Clamped Splines
We want to best approximate a given function f(x) on an interval [a, b]. In class you
have seen how cubic splines are derived. We will find a cubic spline interpolating
polynomial PS(x), clamped at the boundary of the domain. This means that we
enforce a particular value for the slope (first derivative) at the endpoints of the
domain, namely vl and vr, respectively given by:
f
0
(a) = vl f
0
(b) = vr (1)
Problem 1)
Interpolate the function f(x) = 1
1+25x2 on [−1, 1] with 11 equi-spaced points, using
the built-in Matlab spline function. To use this command, you want to first define
the set of discrete data points Xi, find the corresponding y-values Yi=f(Xi), and
find the values vl
, vr by differentiating the function f(x). Use the diff command
that we have learnt in Matlab, do not calculate this by hand. Find the coefficients
for the splines via the command cs = spline(Xi,[vl Yi vr]). Then, define a
domain of points, e. g. using domain = linspace(a,b,101);, and finally find
the interpolating polynomial with the command P=ppval(cs,domain);
After you have found your interpolating polynomial via the cubic splines, PS(x),
plot it against the domain, and in the same figure plot also the actual function
f(x) and the discrete points (xi
, yi). Also, plot in the same figure the 10th-degree
polynomial PL(x) found with equi-spaced Lagrange interpolation, and PC(x) found
with the Chebyshev nodes.
To compare the performance of all the three methods, calculate for each of
1
them the error by
ErrS = max
x∈[a,b]
|f(x) − PS(x)| (2)
ErrL = max
x∈[a,b]
|f(x) − PL(x)| (3)
ErrC = max
x∈[a,b]
|f(x) − PC(x)| (4)
Rank the method performances from best to worst and comment on your results.
2