# Cubic Spline¶

We consider here a cubic spline passing through the points \((x_i,y_i)\) with \(a=x_1<\ldots<x_n=b\), that is, a class function \({\mathcal C}^2\) on \([a, b]\) and each restriction at the interval \([x_{i-1},x_i]\), \(1\leq i\leq n\), is a polynomial of degree less than 3. We will note \(S\) such a spline. His equation is given by

where

If we derive this equation twice with respect to \(x\), we get

Since \(A = 1\) in \(x_i\) and \(A = 0\) in \(x_ {i + 1}\) and conversely for \(B\), we can see that the second derivative is continuous at the interface of the two intervals \([x_{i-1}, x_{i}]\) and \([x_{i}, x_{i + 1}]\).

It remains to determine the expression of \(y''_i\). To do this, we will calculate the first derivative and impose that it is continuous at the interface of two intervals. The first derivative is given by

We therefore want the value of the first derivative in \(x = x_i\) over the interval \([x_{i-1}, x_{i}]\) to be equal to the value of the first derivative in \(x = x_i\) over the interval \([x_{i}, x_{i + 1}]\); which gives us for \(i = 2, \dots, n-1\)

with

So we have \(n-2\) linear equations to calculate the \(n\) unknowns \(y''_i\) for \(i = 1, \dots, n\). So we have to make a choice for the first and last values and we will take them equal to zero. We can recognize the resolution of a system with a tridiagonal matrix. It is then easy to solve it by using the algorithm of Thomas which one recalls the principle

The solution is then obtained by the formula