Skip to content Skip to sidebar Skip to footer

Roots Of Piecewise Cubic Hermite Interpolator With Python

I would like to do some piecewise cubic hermite interpolation and get the roots of the polynomials. (I used to do this in matlab but would now like to implement this in python 3.4)

Solution 1:

This is a bug in scipy.

(Please report it on https://github.com/scipy/scipy/issues)

As a workaround, you can convert to the power basis manually:

In [1]: from scipy.interpolate import pchip

In [2]: import numpy as np

In [3]: x = np.arange(10)

In [4]: y = [1., 1., 3., 2., 1., 1., 1.5, 2., 8., 1.]

In [5]: s = pchip(x, y)

In [6]: from scipy.interpolate import PPoly

In [7]: pp = PPoly.from
PPoly.from_bernstein_basis  PPoly.from_spline

In [7]: pp = PPoly.from_bernstein_basis(s)

In [8]: pp.roots()
Out[8]: array([  9.07179677,  22.92820323])

EDIT: and if do use this workaround and you have non-default axis, best check that the axis is handled when converting. If it's not, please report it too.

Post a Comment for "Roots Of Piecewise Cubic Hermite Interpolator With Python"