Spline Interpolation Functions

SMath has three functions for spline interpolation:

  • linterp('X-vector','Y-vector','x') returns a linearly interpolated value at x for the data vectors X-vector and Y-vector, which must be the same size.
  • cinterp('X-vector','Y-vector','x') returns a cubic-spline interpolated value at x for the data vectors X-vector and Y-vector, which must be the same size.
  • ainterp('X-vector','Y-vector','x') returns an Akima-spline interpolated value at x for the data vectors X-vector and Y-vector, which must be the same size.

Here is an example showing these functions:

spline interpolation example

Notice how misleading all of these functions are outside the range of the original data points — that is, below x=1 and above x=5. Make sure you only use these for interpolation, not extrapolation.

You can have the X-vector sorted in ascending order:

X-vector sorted in ascending order

The X-vector can also be left unsorted. Since the main use of interpolation is to estimate a y-value for an x-value not in the table, this is not advisable:

X-vector left unsorted

This page is based on a legacy wiki article by Greg Locock.