# Cubic Spline interpolation

Cubic Spline interpolation between each data pair xi, xi+1 is done through a third-grade polynomial function, under the condition that the function f(x), as well as its first and second derivatives f(x)1 and f(x)2, have to be continuum in the limits of the interval.

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

${f}_{i}\left(x\right)={f}_{i}\left({x}_{i}\right)+\left(x-{x}_{i}\right){f}_{i}^{1}\left(x\right)+\frac{1}{2}\left(x-{x}_{i}{\right)}^{2}{f}_{i}^{2}\left({x}_{i}\right)+\frac{1}{6}\left(x-{x}_{i}{\right)}^{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)+\left(x-{x}_{i}\right){f}_{i}^{1}\left(x\right)+\frac{1}{2}\left(x-{x}_{i}{\right)}^{2}{f}_{i}^{2}\left({x}_{i}\right)+\frac{1}{6h}\left(x-{x}_{i}{\right)}^{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
• Er = 76.100 MeV
• γ = 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.