7.3 Practice Problems

Problem 7.3.1. Find the natural cubic spline through \((0,0)\), \((1,1)\), \((2,0)\), and evaluate it at \(x = 0.5\).

Show solution

Solution. \(h_0 = h_1 = 1\), \(c_0 = c_2 = 0\), \(4c_1 = 3(0-1)-3(1-0) = -6\), so \(c_1 = -1.5\). Then \(b_0 = 1-\frac 13(-1.5) = 1.5\), \(d_0 = \frac {-1.5}{3} = -0.5\), and \(S_0(x) = 1.5x-0.5x^3\); by symmetry \(S_1(x) = 1-1.5(x-1)^2+0.5(x-1)^3\). At \(x = 0.5\), \(S(0.5) = 0.75-0.0625 = 0.6875\).

Problem 7.3.2. Show that a clamped cubic spline that interpolates a cubic polynomial \(f\) (with the correct end slopes) is \(f\) itself.

Show solution

Solution. The cubic \(f\) itself satisfies all the conditions of the definition: it interpolates, it is \(C^2\), and its end slopes are \(f'(a)\) and \(f'(b)\). By Theorem 7.1.2 the clamped spline is unique, so it is \(f\). (The natural spline reproduces \(f\) only if \(f''(a) = f''(b) = 0\).)

Problem 7.3.3. Fit a least-squares line to \((0,1)\), \((1,3)\), \((2,4)\), \((3,4)\) and compute the residuals.

Show solution

Solution. \(m = 4\), \(\sum x = 6\), \(\sum x^2 = 14\), \(\sum y = 12\), \(\sum xy = 23\). So \(a_1 = \frac {4(23)-6(12)}{4(14)-36} = \frac {20}{20} = 1\) and \(a_0 = \frac {12-6}{4} = 1.5\): \(y = x+1.5\). The residuals \(y_i-(x_i+1.5)\) are \(-0.5, 0.5, 0.5, -0.5\); they sum to zero, as the first normal equation guarantees, and \(E = 1\).

Problem 7.3.4. Show that the least-squares line always passes through the point \((\bar x,\bar y)\) of means.

Show solution

Solution. The first normal equation, divided by \(m\), reads \(a_0+a_1\bar x = \bar y\), where \(\bar x = \frac 1m\sum x_i\) and \(\bar y = \frac 1m\sum y_i\). So \((\bar x,\bar y)\) lies on the line.

Problem 7.3.5. Explain how to fit \(y = bx^a\) to positive data by a linear least-squares problem, and fit it to \((1,3)\), \((2,12)\), \((4,48)\).

Show solution

Solution. Taking logarithms, \(\ln y = \ln b+a\ln x\), a straight line in \((\ln x,\ln y)\). Here \((\ln x,\ln y) = (0,\ln 3)\), \((\ln 2,\ln 12)\), \((\ln 4,\ln 48)\), and \(\ln 12-\ln 3 = \ln 4 = 2\ln 2\), \(\ln 48-\ln 3 = \ln 16 = 4\ln 2\): the points lie exactly on a line of slope \(2\) through \((0,\ln 3)\). So \(y = 3x^2\), with zero error.

Questions on this section

Stuck on something here? Ask below and it stays attached to this topic.