Name

SplineInterpolation1D — Class for performing spline interpolations between data points from a one-dimensional data set.

Synopsis

Namespace: NanoLanguage
SplineInterpolation1D(
x_values,
y_values
)

Description

Constructor for the SplineInterpolation1D object.

SplineInterpolation1D Arguments

x_values

A list of x values of data points.

Type: list(float,...)

y_values

A list of y values of data points.

Type: list(float,...)

SplineInterpolation1D Methods

A SplineInterpolation1D object provides the following methods:

  • __call__(x): Calculate and return the spline interpolation at x, i.e. f(x) where f is a SplineInterpolation1D object.

    x

    The x value to interpolate for.

    Type: float

  • derivatives(x): Calculate and return a tuple containing the derivatives (f, df/dx, d2f/dx2) of the spline interpolation evaluated at x.

    x

    The x value.

    Type: float

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.