SplineInterpolation1D¶
- class SplineInterpolation1D(x_values, y_values, left_boundary_type=0, left_boundary_value=0.0, right_boundary_type=0, right_boundary_value=0.0)¶
Constructor for the SplineInterpolation1D object.
- Parameters:
x_values (list(float,...)) – A list of x values of data points.
y_values (list(float,...)) – A list of y values of data points.
left_boundary_type (int (0 | 1 | 2)) –
Boundary condition type for the left boundary.
0 - Parabolically terminated spline (left_boundary_value is ignored).
1 - First derivative boundary condition.
2 - Second derivative boundary condition.
left_boundary_value (float) – Left boundary condition value.
right_boundary_type (int (0 | 1 | 2)) –
Boundary condition type for the right boundary.
0 - Parabolically terminated spline (right_boundary_value is ignored).
1 - First derivative boundary condition.
2 - Second derivative boundary condition.
right_boundary_value (float) – Right boundary condition value.
- derivatives(x)¶
Calculate and return a tuple containing the derivatives (f, df/dx, d2f/dx2) of the spline interpolation evaluated at x.
@param x : The x value. @type : float @return The tuple (f, df/dx, d2f/dx2)
Usage Examples¶
Define a spline interpolation of the sin
function:
x = numpy.linspace(-4,9,20)
y = numpy.sin(x)
f = SplineInterpolation1D(x,y)
Using the function, we obtain:
>>> print f(3)
0.141203196688
>>> print f.derivatives(3)
(0.14120319668785397, -0.98998913849695858, -0.14589372176098986)
>>> print numpy.array(f.derivatives(3)) - \\
numpy.array((numpy.sin(3), numpy.cos(3), -numpy.sin(3)))
[ 8.31886280e-05 3.35810349e-06 -4.77371370e-03]
Notes¶
The data points does not need to have an increasing value of x.
The data points does not need to have an equidistant separation.
Function values outside the interpolation range will be extrapolated using the outermost spline function.