CAAM 553
Homework 4
Due Sept. 21
(1) (25 points) Divided differences and verifying error bounds.
i. (10 points) Given x0 = −0.2, x1 = 0 and x2 = 0.2 construct a second degree polynomial to approximate f (x) = ex via Newton’s divided differences.
ii. (10 points) Derive a pointwise and a global error bound for p2 (x) when x ∈ [−0.2, 0.2].
iii. (5 points) Compute the error E(0.1) = f (0.1)−p2 (0.1). How does this compare with
the error bound?
(2) (25 points) This problem is pledged! You may not discuss this with anyone but your
instructor. You may not consult any source other than NA, NLA, Prof. Embree’s lecture
notes or your in-class notes to help you with the problem.
i.(15 points) Show there is a unique cubic polynomial p(x) for which
p(x0 ) = f (x0 )
p(x2 ) = f (x2 )
0
0
p (x1 ) = f (x1 )
p00 (x1 ) = f 00 (x1 ),
where f (x) is a given function and x0 6= x2 . Derive a formula p(x).
ii. (10 points) Let x0 = −1, x1 = 0 and x2 = 1. Assuming f (x) ∈ C 4 ([−1, 1]), show
that for −1 ≤ x ≤ 1,
f (x) − p(x) =
x4 − 1 4
f (ηx )
4!
for some ηx ∈ [−1, 1].
(3) (25 points) Suppose we have m data points {(ti , yi )}m
i=1 , where the t-values all occur in some interval [x0 , xn ]. We subdivide the interval [x0 , xn ] into n subintervals
{[xk , xk+1 ]}n−1
k=0 of equal length “h” and attempt to choose a spline function s(x) with
nodes at {xk }nk=0 in such a way so that
m
X
|yi − s(ti )|2
i=1
is minimized.
This can be formulated as a linear least squares problem with a coefficient matrix that
has a banded structure:
1
2
The key to the structure of the data matrix for spline data fitting is the fact that
cubic splines may be represented as linear combinations of “B-splines” which have only
local support on the interval:
Bn−1 Bn
B0 B1 B2 B3 B4 B5
· · ·
x0 x1 x2 x3 x4
· · ·
···
···
xn
Note that B−1 (t) and Bn+1 (t) are not shown, but they need to be included. So, written
in terms of the {Bi (t)}, the cubic spline s(t) appears as
s(t) =
n
X
αi Bi (t)
i=0
with
(t − xi−2 )3
3
2
2
3
h + 3h (t − xi−1 ) + 3h(t − xi−1 ) − 3(t − xi−1 )
h3 Bi (t) = h3 + 3h2 (xi+1 − t) + 3h(xi+1 − t)2 − 3(xi+1 − t)3
(xi+2 − t)3
0
for
for
for
for
for
t ∈ [xi−2 , xi−1 ]
t ∈ [xi−1 , xi ]
t ∈ [xi , xi+1 ]
t ∈ [xi+1 , xi+2 ]
any other t
Bi
xi−2
Note that if tk ∈ [xi , xi+1 ] then
s(tk ) =
n
X
xi−1
xi
xi+1
xi+2
ci Bi (tk ) = ci−1 Bi−1 (tk ) + ci Bi (tk ) + ci+1 Bi+1 (tk ) + ci+2 Bi+2 (tk )
i=0
The data matrix will never have more than four nonzero entries per row !!
The indexing of the Bi (t) is different than the indexing given in Prof. Embree’s notes.
However, this will give the same results. Also note that Bn+2 (t) will not be needed since
it vanishes for any t ∈ [x0 , xn ].
Acknowledgement: This problem is suggested by Prof. Chris Beattie, VA Tech. Prof.
i. (10 points) Write a program that given an interval [a, b] will construct n equally spaced
grid points a = x0 < x1 < x2 < . . . < xn = b and data points {(ti , fi ) : i = 1 : m}
with ti ∈ [a, b] and with fi = f (ti ) for some given function f . The routine should
then set up the matrix A of coefficients and the right hand side b with b(i) = fi .
Note: Your A should be an m × (n + 3) matrix with m > n + 3, where m is the
number of data points and n is the number of intervals [xj , xj+1 ). It is probably
best if you take the points ti to be equally spaced in the interval (x0 , xn ) but with a
much smaller spacing and then process these points in increasing order to construct
the rows of A as you need them.
The code should then solve the least squares problem
3
min kb − Ac k2 .
c
You may use Matlab’s qr and “backslash” for this. The entries of c will be the
coefficients {ci : i = −1 : n + 1}.
The input to the code should be the interval [a, b] (i.e. the values a and b ), the
number of intervals n ( to specify [xi−1 , xi ), i = 1 : n ) and a function handle f
for a code to evaluate f (t) where f is the function you wish to approximate (see
documentation for Matlab’s fzero for an example if you have forgotten how to do
this).
The output of the code should be the coefficients c and the vector x of grid points
xi .
ii. (10 points) Test your routine on data points generated from a variety of functions of
a single variable plus “noise” (small random perturbations). Include the following
example.
Example: h1 = a stepsize smaller than x(j) - x(j-1)
t = [0:h1:2*pi];
y = sin(t)’;
m = length(y);
b = y + (.05)*randn(m,1);
Turn in the plots for this sine function and also select two additional interesting
ones to turn in. Plot the spline fit with the data points and the original (noiseless)
function. (legends, title, x and y axis labels please)
You will need to write a routine to evaluate the spline at any argument t ∈ [a, b] to
make these plots.
iii.(5 points) Show a spy plot of the matrix A and also for the matrix AT A. Notice
the structure. We shall learn later in the course about how to take advantage of
this structure (do help spy in Matlab to see how to use spy).
© Copyright 2026 Paperzz