Scipy Functions with Excel and pyxll 2 – Interpolation

Following the previous post I will now look in more detail at the functions in the py_Interpolate spreadsheet included in the download file:

py_SciPy.zip

Details of the required pyxll package (including download, free trial, and full documentation) can be found at: pyxll

For those installing a new copy of pyxll, a 10% discount on the first year’s fees is available using the coupon code “NEWTONEXCELBACH10”.

The py_Interpolate spreadsheet has 10 user defined functions linking to the Scipy spline interpolation functions. The Scipy help on each function is easily accessed from within Excel:

Open the “Insert Function” dialog, then click on “Help on this function” in the bottom left corner.

That takes you straight to the Scipy on-line help:

The examples in the spreadsheet plot the same data using each of the 9 functions. The screenshots below compare the output from the py_CubicSpline function, with “natural” end conditions, with the other nine functions:

py_Akima1D:

py_BarycentricInterp:

scipy.interpolate.barycentric_interpolate

scipy.interpolate.barycentric_interpolate(xiyixaxis=0)

Convenience function for polynomial interpolation.

Constructs a polynomial that passes through a given set of points, then evaluates the polynomial. For reasons of numerical stability, this function does not compute the coefficients of the polynomial.

This function uses a “barycentric interpolation” method that treats the problem as a special case of rational function interpolation. This algorithm is quite stable, numerically, but even in a world of exact computation, unless the x coordinates are chosen very carefully – Chebyshev zeros (e.g., cos(i*pi/n)) are a good choice – polynomial interpolation itself is a very ill-conditioned process due to the Runge phenomenon.

py_KroghInterp:

scipy.interpolate.krogh_interpolate

scipy.interpolate.krogh_interpolate(xiyixder=0axis=0)

Convenience function for polynomial interpolation.

See KroghInterpolator for more details.

py_GridData1

scipy.interpolate.griddata

scipy.interpolate.griddata(pointsvaluesximethod=’linear’fill_value=nanrescale=False)

Interpolate unstructured D-D data.

py_UniSpline

scipy.interpolate.UnivariateSpline

class scipy.interpolate.UnivariateSpline(xyw=Nonebbox=[None, None]k=3s=Noneext=0check_finite=False)

1-D smoothing spline fit to a given set of data points.

Fits a spline y = spl(x) of degree k to the provided xy data. s specifies the number of knots by specifying a smoothing condition.

py_Splev

scipy.interpolate.splev

scipy.interpolate.splev(xtckder=0ext=0)

Evaluate a B-spline or its derivatives.

Given the knots and coefficients of a B-spline representation, evaluate the value of the smoothing polynomial and its derivatives. This is a wrapper around the FORTRAN routines splev and splder of FITPACK.

py_CubicSplineS

scipy.interpolate.CubicSpline

class scipy.interpolate.CubicSpline(xyaxis=0bc_type=’not-a-knot’extrapolate=None)

Cubic spline data interpolator.

Interpolate data with a piecewise cubic polynomial which is twice continuously differentiable [1]. The result is represented as a PPoly instance with breakpoints matching the given data.

py_Interp1d(

scipy.interpolate.interp1d

class scipy.interpolate.interp1d(xykind=’linear’axis=-1copy=Truebounds_error=Nonefill_value=nanassume_sorted=False)

Interpolate a 1-D function.

Legacy

This class is considered legacy and will no longer receive updates. This could also mean it will be removed in future SciPy versions.

py_Pchip

scipy.interpolate.PchipInterpolator

class scipy.interpolate.PchipInterpolator(xyaxis=0extrapolate=None)

PCHIP 1-D monotonic cubic interpolation.

x and y are arrays of values used to approximate some function f, with y = f(x). The interpolant uses monotonic cubic splines to find the value of new points. (PCHIP stands for Piecewise Cubic Hermite Interpolating Polynomial).

This entry was posted in Curve fitting, Excel, Link to Python, Maths, Newton, NumPy and SciPy, PyXLL, UDFs and tagged , , , , , , , , . Bookmark the permalink.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.