# Cubic Spline interpolation

Cubic Spline interpolation between each data pair **x _{i}**,

**x**is done through a third-grade polynomial function, under the condition that the function

_{i+1}**f(x)**, as well as its first and second derivatives

**f(x)**and

^{1}**f(x)**, have to be continuum in the limits of the interval.

^{2}${x}_{i}\le x\le {x}_{i+1}$

${f}_{i}\left(x\right)={f}_{i}\left({x}_{i}\right)+(x-{x}_{i}){f}_{i}^{1}\left(x\right)+\frac{1}{2}(x-{x}_{i}{)}^{2}{f}_{i}^{2}({x}_{i})+\frac{1}{6}(x-{x}_{i}{)}^{3}{f}_{i}^{3}\left({x}_{i}\right)$

and, if the third-order derivative is written as a function of the second-order derivative,

${f}_{i}\left(x\right)={f}_{i}\left({x}_{i}\right)+(x-{x}_{i}){f}_{i}^{1}\left(x\right)+\frac{1}{2}(x-{x}_{i}{)}^{2}{f}_{i}^{2}({x}_{i})+\frac{1}{6h}(x-{x}_{i}{)}^{3}\left({f}_{i}^{2}\left({x}_{i+1}\right)-{f}_{i}^{2}\left({x}_{i}\right)\right)$

where *h* is:

${x}_{i+1}={x}_{i}+h$

and the continuity conditions:

$\begin{array}{c}{f}_{i}\left({x}_{i+1}\right)={f}_{i+1}\left({x}_{i+1}\right)\\ {f}_{i}^{1}\left({x}_{i+1}\right)={f}_{i+1}^{1}\left({x}_{i+1}\right)\\ {f}_{i}^{2}\left({x}_{i+1}\right)={f}_{i+1}^{2}\left({x}_{i+1}\right)\end{array}$

The files for this calculation are in folder `breitwigner/2_CubicSplines`

. It uses the Numerical Recipes libraries, `spline.c`

and `splint.c`

.

The program `splinesc.c`

is very similar to `lagrange.c`

and works in a similar way as explained in the Lagrange interpolations page.

Once we have all the inputs, we can call the `spline()`

function (you may want to check the definition again) and then we call `splint()`

inside a loop through the points (See the definition).

```
/***************************************************
* Calculating the first derivative,
* evaluating in E1 and E1 and
* calling the functions
***************************************************/
yp1 = -0,00001;
ypn = -0,5;
spline(xa, ya, N, yp1, ypn, y2);
for (i=1; i<=n; i++)
splint(xa, ya, y2, N, x[i], &y[i]);
```

## Results

And so the following values are obtained:

**σ**_{0}= 70297.063*E*= 76.100 MeV_{r}**γ = 57.986 MeV**

The region of the curve where there is more variation is the peak, that's why we take more points there. Repeat the calculation adding points for the rest of the curve.

The peak is the region of higher variation of the curve.

Zoom in of the previous plot.