Numerical Recipes applied
to
Thermodynamics

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.

xixxi+1

fi(x)=fi(xi)+(x-xi)fi1(x)+12(x-xi)2fi2(xi)+16(x-xi)3fi3(xi)

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

fi(x)=fi(xi)+(x-xi)fi1(x)+12(x-xi)2fi2(xi)+16h(x-xi)3fi2(xi+1)-fi2(xi)

where h is:

xi+1=xi+h

and the continuity conditions:

fi(xi+1)=fi+1(xi+1)fi1(xi+1)=fi+11(xi+1)fi2(xi+1)=fi+12(xi+1)

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:

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.

Breit-Wigner curve obtained with Cubic splines

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

Breit-Wigner curve obtained with Cubic splines. Zoom in

Zoom in of the previous plot.