Roots of a piecewise cubic germite python interpolator

I would like to do some piecewise cubic germitic interpolation and get the roots of the polynomials. (I used this in Matlab, but now I would like to implement this in python 3.4).
I tried using scipy PchipInterpolator. The interpolation is fine, but when I tried to restore the roots, I got this error ...
I am stuck here now and have not found any workaround. Here is a simple code reproducing what I'm doing and the exact error message ...

import matplotlib.pyplot as plt
from scipy import interpolate, __version__
import numpy as np

print('numpy : ' + np.__version__)
print('scipy :' + __version__)

x = np.arange(10)
y = [1., 1., 3., 2., 1., 1., 1.5, 2., 8., 1.]
f = interpolate.PchipInterpolator(x, y, axis=0, extrapolate=None)
print(f.roots()) # this produces an error !

xnew = np.arange(0, 9, 0.1)
ynew = f(xnew)   # use interpolation function returned by `PchipInterpolator`
plt.plot(x, y, 'o', xnew, ynew, '-')
plt.show()

Error message:

numpy : 1.10.1
scipy :0.17.1
Traceback (most recent call last):
  File "test.py", line 11, in <module>
    print(f.roots()) # this produces an error !
  File "/usr/local/lib/python3.4/dist-packages/scipy/interpolate/_monotone.py", line 105, in roots
    return (PPoly.from_bernstein_basis(self._bpoly)).roots()
AttributeError: 'PchipInterpolator' object has no attribute '_bpoly'

Process finished with exit code 1

However, scipy docs say: "Roots () Return the roots of an interpolated function."

What am I missing here?

+4
1

scipy.

( https://github.com/scipy/scipy/issues)

:

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: , axis, , . , .

+3

All Articles