









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!










Numerical Computing S’09 MATH/CSCI 4800- Homework-
Due in class on Monday March 23, 2009
Illegible reports will be returned without grading. Show all work. All Matlab scripts, Matlab output and plots should be printed out and stapled to the report.
(a) Define natural, clamped and not-a-knot cubic splines. (b) Check whether the following function is a natural cubic spline. If it is not, then indicate the reason for the breakdown.
S(x) =
28 + 25x + 9x^2 + x^3 x ∈ [− 3 , −1] 26 + 19x + 3x^2 − x^3 x ∈ [− 1 , 0] 26 + 19x + 3x^2 − 2 x^3 x ∈ [0, 3] −163 + 208x − 60 x^2 + 5x^3 x ∈ [3, 4]
(a) A cubic spline is a piecewise cubic interpolant to discrete data (xi, yi), i = 1, 2 ,... n. It consists of a different cubic polynomial on each of the n − 1 subintervals and may be defined as follows.
si(x) = aix^3 + bix^2 + c 1 x + di, xi ≤ x ≤ xi+1, i = 1, 2 ,... n − 1.
The 4n − 4 coefficients appearing above are found by the following conditions. i. The n interpolation conditions,
si(xi) = yi, i = 1, 2 ,... n − 1 , sn− 1 (xn) = yn. (1)
ii. The 3(n − 2) continuity conditions at the interior nodes,
si− 1 (xi) = si(xi), s′ i− 1 (xi) = s′ i(xi), s′′ i− 1 (xi) = s′′ i (xi), i = 2, 3 ,... n − 1. (2)
iii. Two additional conditions depending upon the type of spline. The natural spline satisfies zero curvature conditions at the ends, i.e.,
s′′ 1 (x 1 ) = s′′ n− 1 (xn) = 0. (3)
The clamped spline satisfies given slopes at the ends, i.e.,
s′ 1 (x 1 ) = α, s′ n− 1 (xn) = β.
The not-a-knot spline satisfies
s′′′ 1 (x 2 ) = s′′′ 2 (x 2 ), s′′′ n− 2 (xn− 1 ) = s′′′ n− 1 (xn− 1 ).
(b) First, note that we have the cubics
s 1 (x) = 28 + 25x + 9x^2 + x^3 , x ∈ [− 3 , −1] s 2 (x) = 26 + 19x + 3x^2 − x^3 , x ∈ [− 1 , 0] s 3 (x) = 26 + 19x + 3x^2 − 2 x^3 , x ∈ [0, 3] s 4 (x) = −163 + 208x − 60 x^2 + 5x^3 , x ∈ [3, 4].
We shall also need the first two derivatives:
s′ 1 (x) = 25 + 18x + 3x^2 , x ∈ [− 3 , −1] s′ 2 (x) = 19 + 6x − 3 x^2 , x ∈ [− 1 , 0] s′ 3 (x) = 19 + 6x − 6 x^2 , x ∈ [0, 3] s′ 4 (x) = 208 − 120 x + 15x^2 , x ∈ [3, 4],
and
s′′ 1 (x) = 18 + 6x, x ∈ [− 3 , −1] s′′ 2 (x) = 6 − 6 x, x ∈ [− 1 , 0] s′′ 3 (x) = 6 − 12 x, x ∈ [0, 3] s′′ 4 (x) = −120 + 30x, x ∈ [3, 4].
Now consider the conditions (1)-(3) above which must be satisfied if S is a cubic spline. Inter- polation conditions (1) are irrelevant because we are not given any yi. Consider the continuity conditions (2) at the interior nodes; the following equations confirm that these conditions are satisfied. s 1 (−1) = 11 = s 2 (−1), s 2 (0) = 26 = s 3 (0), s 3 (3) = 56 = s 4 (3), s′ 1 (−1) = 10 = s′ 2 (−1), s′ 2 (0) = 19 = s′ 3 (0), s′ 3 (3) = −17 = s′ 4 (3), s′′ 1 (−1) = 12 = s′′ 2 (−1), s′′ 2 (0) = 6 = s′′ 3 (0), s′′ 3 (3) = −30 = s′′ 4 (3). Now consider the natural spline conditions (3):
s′′ 1 (−3) = 0, s′′ 4 (4) = 0.
As these conditions hold, S(x) is a natural cubic spline.
(a) Write down the (x, y) points that will serve as the interpolation nodes for p(x). (b) Write a Matlab script to compute p(x) and plot a graph showing both p and f on the interval [2, 6]. (You may use the Matlab commands polyfit and polyval.) Comment on the eyeball- accuracy of your result. (c) Find, analytically, the upper bound on the interpolation error | ln x − p(x)| that is valid for all x in [2, 6]. (d) Based upon the above estimate, how many digits will be correct when p(4) is used to approximate ln 4? Check your result against the exact answer and comment.
(a) The x -coordinates of the Chebyshev nodes for n = 6 and for the interval [a, b] are
xi = a + b 2
b − a 2
cos (2i − 1)π 12
, i = 1, 2 ,... 6.
When specialized to a = 2 and b = 6 we get
xi = 4 + 2 cos (2i − 1)π 12
, i = 1, 2 ,... 6.
The corresponding y -coordinates are yi = ln xi.
(c) See attached Matlab Log. It appears that the data is best represented by two straight line segments, which makes the piecewise linear interpolant the best choice. Both the polynomial interpolant and the spline interpolant lend some un-necessary curvature to the trend, making them both unsatisfactory.
(a) Solve Text Problem 2a, Exercises 4.1, page 204 by hand, using the procedure outlined in Example 4.4 on page 200. (b) (Extra Credit) Solve the above problem by hand by using the QR decomposition. This will require adding an extra column to the 4 × 3 matrix, employing Gram-Schmidt orthogonalization to generate Q and R, and then using the procedure outlined on page 222 to solve the least- squares problem. (c) Solve the problem with Matlab by using the QR decomposition. You may find the code segment given in Example 4.15 on page 223 helpful.
(a) The least-squares problem is Ax = b, i.e.,
x 1 x 2 x 3
Multiplying both sides of the above equation by AT^ leads to the following normal equations
x 1 x 2 x 3
whose solution is
x =
x 1 x 2 x 3
The residual vector is r = b − Ax, i.e.,
r =
The root mean squared error is RMSE =
rTr = 1/
(b) We follow the procedure outlined in class; see also section 4.3 and Examples 4.12-4.14 in the Text (pages 218-222). First, we need to add a fourth column to A, linearly independent of the other three columns of A, so that a QR-factorization can be performed. Thus the enhanced version of A is taken to be
We denote by vi the columns of A.ˆ The QR-factorization will be obtained via the Gram-Schmidt process. We begin by setting
y 1 = v 1 =
Then r 11 = ||y 1 || =
3 , and the first unit vector is
q 1 =
y 1 ||y 1 ||
To find the second unit vector we set
y 2 = v 2 − r 12 q 1
where
r 12 = (qT 1 v 2 ) =
Therefore,
y 2 =
With r 22 = ||y 2 || =
3 , the second unit vector is
q 2 =
y 2 ||y 2 ||
For the third unit vector we define
y 3 = v 3 − r 13 q 1 − r 23 q 2
where
r 13 = (qT 1 v 3 ) =
and
r 23 = (qT 2 v 3 ) =
Therefore,
y 3 =
With r 33 = ||y 3 || = 2 /
3 , the third unit vector is
q 3 = y 3 ||y 3 ||
The original (inconsistent) problem Ax = b can now be written as QRx = b, or Rx = Q−^1 b, or Rx = QTb since Q−^1 = QT. On substituting the entries, Rx = QTb becomes
x 1 x 2 x 3
We now ignore the last row in R and QTb and solve the resulting upper triangular system to get the least-squares solution
x =
x 1 x 2 x 3
This solution agress with that obtained in part (a) above. (c) See Matlab Log.