# Cubic spline-interpolations with extra conditions of $f(x)=x^4$

Let $$f(x)=x^4$$ and $$x\in[-1,1]$$. How can I find a cubic Spline $$S$$ that is an interpolation polynomial at the data points $$x_0=-1, x_1=0$$ and $$x_2=1$$? $$S$$ should also fulfill the extra condition $$S'(-1)=f'(-1)$$ and $$S'(1)=f'(1)$$.

Right now I'm learning numerical calculus and currently I'm trying to wrap my head around how spline-interpolation works. How would I go about this question for example? I thought of defining two spline-functions $$S_1(x):=a_3x^3+a_2x^2+a_1x+a_0$$ and $$S_2(x):=b_3x^3+b_2x^2+b_1x+b_0$$, where $$S(x)|_{x\in[-1,0]}=S_1(x)$$ and $$S(x)|_{x\in[0,1]}=S_2(x)$$. This would lead me to six equations, since $$S_1(-1)=1,S_0(0)=0,S_2(0)=0,S_2(1)=1,S'_1(-1)=-4$$ and $$S'(1)=4$$. But since I have 8 variables, this problem isn't solvable (yet). What am I missing/doing wrong? (I also tried adding the two conditions $$S'_1(0)=S'_2(0)$$ and $$S''_1(0)=S_2''(0)$$ in order to get an $$S\in \mathcal{C}^2$$ and 8 equations, although even that seems to not help.

• Can you elaborate why that last point didn't help? Commented May 14, 2021 at 14:23

Your approach is completely valid. If you set up these equations you'lle nd up with a system that looks like so: $$\begin{array}[c] SS_1(x_0) = f(x_0) \\ S_1(x_1) = f(x_1) \\ S_2(x_1) = f(x_1) \\ S_2(x_2) = f(x_2) \\ S_1'(x_0) = f'(x_0) \\ S_2'(x_2) = f'(x_2) \\ S_1'(x_1) = S_2'(x_1) \\ S_1''(x_1) = S_2''(x_1) \\ \end{array} \begin{bmatrix} x_0^3 & x_0^2 & x_0 & 1 & & & & \\ x_1^3 & x_1^2 & x_1 & 1 & & & & \\ & & & & x_1^3 & x_1^2 & x_1 & 1\\ & & & & x_2^3 & x_2^2 & x_2 & 1\\ 3x_0^2 & 2x_0 & 1 & & & & & \\ & & & & 3x_2^2 & 2x_2 & 1 & \\ 3x_1^2 & 2x_1 & 1 & & -3x_1^2 & -2x_1 & -1\\ 6x_1 & 2 & & & -6x_1^2 & -2 & & \\ \end{bmatrix} \begin{bmatrix}a_3 \\ a_2 \\ a_1 \\ a_0 \\ b_3 \\ b_2 \\ b_1 \\ b_0 \end{bmatrix} = \begin{bmatrix} f(x_0) \\ f(x_1) \\ f(x_1) \\ f(x_2) \\ f'(x_0) \\ f'(x_2) \\ 0 \\ 0 \end{bmatrix}$$ The determinant of the matrix is 12 and it is therefore invertible.
• Thank you! I came to the same matrix, calculated it by hand and got very weird numbers, like $a_3=-\frac{13}{4}$ two times in a row. That didn't make any sense to me since my calculations looked valid and I thought it had to be the wrong way to solve this. Turns out by checking your system of equations again and plugging in the values for $x_i, f(x_i)$ and $f'(x_i)$ it's actually working out now: $S_1(x)=-2x^3-x^2$ and $S_2(x)=2x^3-x^2$ are working out perfectly. Commented May 14, 2021 at 16:35