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())
xnew = np.arange(0, 9, 0.1)
ynew = f(xnew)
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())
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?