# Cubic spline with clamped boundaries

I have a cubic spline interpolation problem to work through. I think I understand what is required of the question, but my biggest concern is the nature of clamped versus natural boundaries. All the problems I've looked at use natural boundaries, which affect the solution for the polynomials. For clamped boundaries, I'm a little confused as to how to solve for those conditions.

The question is:

$$\begin{array}{c|c|c} x & \sin{x} & \frac{d}{dx}\sin{x}=\cos{x} \\ \hline 0.30 & 0.29552 & 0.95534 \\ 0.32 & 0.31457 & 0.94924 \\ 0.35 & 0.34290 & 0.93927 \end{array}$$

$$\text{Use the above values and five-digit rounding to construct a cubic spline Q with boundary conditions}$$

$$Q'(x_{0})= f'(x_{0}) \text{ and } Q'(x_{n})=f'(x_{n})$$

$$\text{which force the slopes of the spline to assume certain values (in our case the values }$$ $$f'(x_{0})\text{ and } f'(x_{n})$$ $$\text{ respectively) at the two boundaries. Use this spline to approximate }$$ $$\sin{0.33}$$

Here is my work so far:

Spline consists of two cubics. The first for interval [0.30, 0.32], denoted

$$Q_{0}=a_{0}+b_{0}(x-0.30)+c_{0}(x-0.30)^2+d_{0}(x-0.30)^3$$

and the other for [0.32, 0.35], denoted

$$Q_{1}=a_{1}+b_{1}(x-0.32)+c_{1}(x-0.32)^2+d_{1}(x-0.32)^3$$

This leaves 8 constants to be determined:

$$0.29552=f(0.30)=a_{0}$$ $$0.31457=f(0.32)=a_{0}+b_{0}+c_{0}+d_{0}$$ $$0.31457=f(0.32)=a_{1}$$ $$0.34290=f(0.35)=a_{1}+b_{1}+c_{1}+d_{1}$$ $$Q'_{0}(x_{i})=Q'_{1}(x_{i}) \Rightarrow Q'_{0}(0.32)=Q'_{1}(0.32)=b_{0}+2c_{0}+3d_{0}=b_{1}$$ $$Q''_{0}(x_{i})=Q''_{1}(x_{i}) \Rightarrow Q''_{0}(0.32)=Q''_{1}(0.32)=2c_{0}+6d_{0}=2c_{1}$$

However, this is where I'm a bit stuck:

$$Q'_{0}(x_{0})=f'(x_{0})$$ $$Q'_{0}(x_{n})=f'(x_{n})$$

I'm not sure I understand what the implications of the clamped boundaries are, and how to solve for them here. Could anyone kindly provide some insight as to how to approach this problem?

Thanks!

• The condition $Q_0'(x_0) = f'(x_0)$ simply reduces to $$b_0 = \cos 0.3$$ and the condition $Q_1'(x_2) = f'(x_2)$ to $$b_1 + 0.04 c_0 + 0.0012 d_0 = \cos 0.34$$. Note that you've miscomputed the $Q'(x)$ (the $(x-x_i)^k$ terms are missing) – uranix Sep 22 '15 at 17:00

## 2 Answers

Instead of your last two equations you must use the following: \begin{align} &Q_0'(x_0)=f'(x_0)=0.95534\cr &Q_0'(x_1)=Q_1'(x_1)=f'(x_1)=0.94924\cr &Q_1'(x_2)=f'(x_2)=0.93927\cr \end{align} All in all you have then 8 equations for 8 unknowns, as expected.

• No, the $f'(x_1)$ shoud not be used! That's a cubic spline, insted $Q_0''(x_1) = Q_1''(x_1)$ must hold – uranix Sep 22 '15 at 16:09

There's a trick to reduce the number of equations needed.

Approach 1. Any polynomial of degree $n$ can be represented as a Taylor formula: $$P(x) = P(x_0) + P'(x_0) (x - x_0) + \dots + \frac{P^{(n)}(x_0)}{n!} (x-x_0)^n.$$ Let's write $Q_0(x)$ as $$Q_0(x) = a_0 + b_0(x - 0.32) + \frac{c_0}{2}(x - 0.32)^2 + \frac{d_0}{6}(x - 0.32)^3.$$ Now the $a_0, b_0, c_0, d_0$ are simply the value and the derivatives of $Q_0$ at $x = 0.32$. Using the same expression for $Q_1(x)$ gives $$Q_1(x) = a_1 + b_1(x - 0.32) + \frac{c_1}{2}(x - 0.32)^2 + \frac{d_1}{6}(x - 0.32)^3.$$ with $a_1, b_1, c_1, d_1$ being the values and the derivatives of $Q_1$ at $x = 0.32$. Since $$Q_0(0.32) = Q_1(0.32), \quad Q_0'(0.32) = Q_1'(0.32), \quad Q_0''(0.32) = Q_1''(0.32)$$ it immediately follows that $$a_0 = a_1, \quad b_0 = b_1, \quad c_0 = c_1.$$ Let's omit indices for $a,b,c$ now.

We have only $5$ unknowns $a, b, c, d_0$ and $d_1$ and five equations for them $$Q_0(0.32) \equiv Q_1(0.32) = f(0.32)\\ Q_0(0.3) = f(0.3)\\ Q_1(0.34) = f(0.34)\\ Q_0'(0.3) = f'(0.3)\\ Q_1'(0.34) = f'(0.34)$$ or (let $h = 0.02$) $$a = f(0.32)\\ a - h b + \frac{h^2}{2} c - \frac{h^3}{6} d_0 = f(0.3)\\ a + h b + \frac{h^2}{2} c + \frac{h^3}{6} d_1 = f(0.34)\\ b - h c + \frac{h^2}{2} d_0 = f'(0.3)\\ b + h c + \frac{h^2}{2} d_1 = f'(0.34)$$ Subtracting the second from the third $$b + \frac{h^2}{12} (d_1 + d_0) = \frac{f(0.34) - f(0.3)}{2h} \sim f'(0.32)$$ Adding the fifth to the fourth $$b + \frac{h^2}{4} (d_0 + d_1) = \frac{f'(0.3) + f'(0.34)}{2} \sim f'(0.32)$$ Eliminating $d_1 + d_0$ gives $$b = 3\frac{f(0.34) - f(0.3)}{4h} - \frac{f'(0.3) + f'(0.34)}{4}$$ Now adding the second to the third and subtracting the first twice $$c + \frac{h}{6} (d_1-d_0) = \frac{f(0.3) -2f(0.32)+ f(0.34)}{h^2} \sim f''(0.32)\\$$ Finally, subtracting the fourth from the fifth gives $$c + \frac{h}{4}(d_1 - d_0) = \frac{f'(0.34) - f'(0.30)}{2h} \sim f''(0.32)$$ Eliminating $d_1 - d_0$ now results in $$c = 3\frac{f(0.3) -2f(0.32)+ f(0.34)}{h^2} - 2\frac{f'(0.34) - f'(0.30)}{2h}$$ Now it is not hard to find $d_0$ and $d_1$. Here are the final values. $$a = 0.314567\\ b = 0.949235\\ c = -0.314577\\ d_0 = -0.952343\\ d_1 = -0.946052$$

Approach 2. Recall what is a Hermite cubic. Note that we know $Q_0(0.3), Q_0'(0.3), Q_0(0.32)$ but do not know $Q_0'(0.32)$. We can perform the Hermite interpolation symbolically, letting $Q_0'(0.32) = \alpha$. Note that $Q_1'(0.32)$ is exactly the same. $$Q_0(x) = (2t^3 - 3t^2 + 1) f(0.3) +(-2t^3 + 3t^2) f(0.32) + (t^3 - 2t^2 + t) h f'(0.3) + (t^3 - t^2) h \alpha, \quad t = \frac{x - 0.3}{h}.$$ Similarly, $$Q_1(x) = (2s^3 - 3s^2 + 1) f(0.32) +(-2s^3 + 3s^2) f(0.34) + (s^3 - 2s^2 + t) h \alpha + (s^3 - s^2) h f'(0.34), \quad s = \frac{x - 0.32}{h}.$$ The only condition to determine $\alpha$ is $$Q_0''(0.32) = Q_1''(0.32)\\ Q_0''\big|_{t = 1} = Q_1''\big|_{s = 0}.$$ Differentiating ($\frac{d}{dx} = \frac{dt}{dx}\frac{d}{dt} = \frac{1}{h}\frac{d}{dt}$) gives $$Q_0''(x) = \frac{12t - 6}{h^2} f(0.30) +\frac{-12t + 6}{h^2} f(0.32) + \frac{6t-4}{h}f'(0.30) + \frac{6t-2}{h}\alpha\\ Q_1''(x) = \frac{12s - 6}{h^2} f(0.32) +\frac{-12s + 6}{h^2} f(0.34) + \frac{6s-4}{h}\alpha + \frac{6s-2}{h}f''(0.34)\\ Q_0''\big|_{t = 1} = \frac{6}{h} \frac{f(0.30) - f(0.32)}{h} + \frac{2f'(0.3) + 4\alpha}{h}\\ Q_1''\big|_{s = 0} = \frac{6}{h} \frac{f(0.34) - f(0.32)}{h} - \frac{2f'(0.34) + 4\alpha}{h}\\ 3 \frac{f(0.3) - f(0.32)}{h} + f'(0.30) + 2\alpha = 3\frac{f(0.34) - f(0.32)}{h} - f'(0.34) - 2\alpha\\ \alpha = \frac{1}{4}\left( 6\frac{f(0.34) - f(0.30)}{2h} - f'(0.30) -f'(0.34) \right) = 0.949235.$$ Note this is exactly the value of $b$ from Approach 1.