# Clamped Cubic Spline : interpolates f?

Given the partition $x_0=0,x_1=.05,x_2=.1 \text{ of } [0,0.1] \text{ and } f(x) = e^{2x}: \\ \text{Find the cubic spline s with clamped boundary condition that interpolates f.}$

The first thing I did, to solve this question is create a table with $x,f(x),f'(x)$ and try to find x.

$$\begin{array}{c|lcr} x & \text{f(x)} & \text{f'(x)} & \\ \hline 0 & 1& 2 \\ .05 & 1.1052 & 2.2103\\ .1 & 1.2214 & 2.4428 \end{array}$$

Then I tried to find matrix A and matrix B then solve $AX=B$ but this is where I ran into some problems.

$h_0= .05-0=.05 ;h_1= .1-.05=.05$

$$A= \begin{bmatrix} 2(.05) & .05 & 0 \\ .05 & 2(.05+.05) & .05 \\ 0 & .05 & 2(.05+.05) \\ \end{bmatrix} = \begin{bmatrix} .1 & .05 & 0 \\ .05 & .2 & .05 \\ 0 & .05 & .2 \\ \end{bmatrix}$$

$$b= \begin{bmatrix} \frac{3}{.05}(1.105-1)-3(2)=.312 & \\ \frac{3}{.05}(1.12214-1)-\frac{3}{.05}(1.1052-1)=1.0164 & \\ 3(2.4428)-\frac{3}{.05}(1.2214-1.1052=-.35651 & \\ \end{bmatrix}$$

The answer is supposed to be

$$x= \begin{bmatrix} 1.998302 & \\ 2.208498& \\ 2.4406449 \\ \end{bmatrix}$$

Yet when I do $Ax=b$ I get

$$x= \begin{bmatrix} .748& \\ 4.7& \\ .59\\ \end{bmatrix}$$

Does anyone know how to solve this?

• Why only three unknowns? Even just one cubic has four coefficients. A two-component cubic spline has eight. – Ian Dec 8 '17 at 1:20
• I suppose the question is trying to set the size n to a limit. – Jon Dec 8 '17 at 1:27
• – ja72 Dec 10 '17 at 5:40

Suppose the cubic spline is \begin{align} s(x) &= s_1(x) = a_1x^3 +b_1x^2 + c_1x + d_1 \quad \text{for} \quad 0 \le x \le 0.05 \\ s(x) &= s_2(x) = a_2x^3 +b_2x^2 + c_2x + d_2 \quad \text{for} \quad 0.05 \le x \le 0.1 \end{align} We need to find the 8 coefficients $a_1, b_1, c_1, d_1, a_2, b_2, c_2, d_2$.

Conceptually, this is easy: we just write down equations that express the things we know, and solve them. First, we have the interpolation conditions: \begin{align} s(0) = f(0) \quad &\Longrightarrow \quad d_1 = f(0) = 1 \\ s(0.05) = f(0.05) \quad &\Longrightarrow \quad a_1(0.05)^3 +b_1(0.05)^2 + c_1(0.05) + d_1 = f(0.05) \\ s(0.1) = f(0.1) \quad &\Longrightarrow \quad 0.001a_1 + 0.01b_1 + 0.1c_1 + d_1 = f(0.1) \\ \end{align} Next, we have two conditions that come from interpolation of end-slopes (the "clamped" condition): \begin{align} s'(0) = f'(0) \quad &\Longrightarrow \quad c_1 = f'(0) \\ s'(0.1) = f'(0.1) \quad &\Longrightarrow \quad 0.03a_1 + 0.2b_1 + c_1 = f'(0.1) \end{align} Next, we have three equations that express the continuity of $s$ at $x=0.05$: \begin{align} s_1(0.05) = s_2(0.05) \quad &\Longrightarrow \quad a_1(0.05)^3 +b_1(0.05)^2 + c_1(0.05) + d_1 = a_2(0.05)^3 +b_2(0.05)^2 + c_2(0.05) + d_2 \\ s_1'(0.05) = s_2'(0.05) \quad &\Longrightarrow \quad 3a_1(0.05)^2 + 2b_1(0.05) + c_1(0.05) = 3a_2(0.05)^2 + 2b_2(0.05) + c_2(0.05) \\ s_1''(0.05) = s_2''(0.05) \quad &\Longrightarrow \quad 6a_1(0.05) + 2b_1 = 6a_2(0.05) + 2b_2 \\ \end{align} Solve these 8 equations to get $a_1, b_1, c_1, d_1, a_2, b_2, c_2, d_2$.

Typical cubic spline calculation involves finding the 2nd derivatives at the interior points such that each interval is defined as

$$y_i(x) = \left[ \matrix{ 1-\zeta & \zeta & -\frac{h^2}{6} \zeta ( \zeta^2-3 \zeta+2) & \frac{h^2}{6} \zeta (\zeta^2-1)} \right] \pmatrix{y_i \\ y_{i+1} \\ \ddot{y}_i \\ \ddot{y}_{i+1} }$$

where $\zeta = \frac{x-x_i}{h}$ and $h=x_{i+1}-x_{i}$. This formulation leads to a computationally simpler system of equations.

In this case, since we have all the 1st derivatives at hand it might be simpler to transform the 2nd derivative coefficients $\pmatrix{y_i \\ y_{i+1} \\ \ddot{y}_i \\ \ddot{y}_{i+1}}$ to the slopes $\pmatrix{y_i \\ y_{i+1} \\ \dot{y}_i \\ \dot{y}_{i+1}}$. The end result is

$$y_i(x) = \left[ \matrix{ (1-\zeta)^2 (2\zeta+1) & \zeta^2 (3-2\zeta) & h \zeta (1-\zeta)^2 & -h \zeta^2 (1-\zeta)} \right] \pmatrix{y_i \\ y_{i+1} \\ \dot{y}_i \\ \dot{y}_{i+1} }$$

You have 3 nodes and 2 intervals:

• 1st Interval
• $x_i=0$, $x_{i+1}=0.05$, $h=0.05$
• $y_i=1$, $y_{i+1}=\mathrm{e}^{0.01}$
• $\dot{y}_i=2$, $\dot{y}_{i+1}=2 \mathrm{e}^{0.01}$

$$y_1(x) = \left[ \matrix{(1-20x)^2(40x+1) & 400x^2(3-40x) & x (1-20x)^2 & -20x^2 (1-20x)} \right] \pmatrix{1 \\ \mathrm{e}^{0.01} \\ 2 \\ 2 \mathrm{e}^{0.01} }$$

• 2nd Interval
• $x_i=0.05$, $x_{i+1}=0.1$, $h=0.05$
• $y_i=\mathrm{e}^{0.01}$, $y_{i+1}=\mathrm{e}^{0.02}$
• $\dot{y}_i=2 \mathrm{e}^{0.01}$, $\dot{y}_{i+1}=2 \mathrm{e}^{0.02}$

$$y_1(x) = \left[ \matrix{4(1-10x)^2(40x-1) & 5(1-8x)(20x-1) & \frac{1}{5} (10x-1)^2 (20x-1) & \frac{1}{10} (10x-1)(1-20x)^2 } \right] \pmatrix{1 \\ \mathrm{e}^{0.01} \\ 2 \\ 2 \mathrm{e}^{0.01} }$$

So this is the way I would approach this type of problem, since all the slopes are known. No need to solve a system of equations.

But if you are required to solve this using a system of equations then I would use the following rules:

• Beginning Slope - beginning slope is known as $\dot{y}_i$ $$\dot{y}_1 = \left[ \matrix{-\frac{1}{h}& \frac{1}{h}} \right] \pmatrix{y_1 \\ y_{2} }+ \left[ \matrix{ -\frac{h}{3} & -\frac{h}{6} }\right] \pmatrix{ \ddot{y}_1 \\ \ddot{y}_{2}}$$
• Ending Slope - the ending slope is known as $\dot{y}_{n}$ $$\dot{y}_{n} = \left[ \matrix{-\frac{1}{h} & \frac{1}{h}} \right] \pmatrix{y_{n-1} \\ y_{n} }+ \left[ \matrix{ \frac{h}{6} & \frac{h}{3} }\right] \pmatrix{ \ddot{y}_{n-1} \\ \ddot{y}_{n}}$$
• Intermediate Slope Matching - on node $i$ the slopes match when $$0 = \left[ \matrix{\frac{1}{h}&-\frac{2}{h}&\frac{1}{h}} \right] \pmatrix{y_{i-1} \\ y_i \\ y_{i+1} } + \left[ \matrix{-\frac{h}{6}&-\frac{2 h}{3}& -\frac{h}{6}} \right] \pmatrix{\ddot{y}_{i-1} \\ \ddot{y}_i \\ \ddot{y}_{i+1} }$$

With $n$ nodes (points) and $n-1$ intervals the above equations are $2+(n-2)=n$ equations also. Each node has an unknown 2nd derivative $\ddot{y}_i$ so the above is a system of $n$ equations with $n$ unknowns.

Specifically with this problem there are 3 nodes and 2+1 equations

$$\begin{bmatrix} \frac{h}{3} & \frac{h}{6} & 0 \\ \frac{h}{6} & \frac{2 h}{3} & \frac{h}{6} \\ 0 & \frac{h}{6} & \frac{h}{3} \end{bmatrix} \pmatrix{\ddot{y}_1 \\ \ddot{y}_2 \\ \ddot{y}_3 } = \begin{bmatrix} - \frac{1}{h} & \frac{1}{h} & 0 \\ \frac{1}{h} & -\frac{2}{h} & \frac{1}{h} \\ 0 & \frac{1}{h} & -\frac{1}{h} \end{bmatrix} \pmatrix{{y}_1 \\ {y}_2 \\ {y}_3 } + \pmatrix{-\dot{y}_1 \\ 0 \\ \dot{y}_3 }$$