import numpy as np
from scipy.interpolate import PiecewisePolynomial
xi = np.array([1,10])
yi = np.array([10,1])
p = PiecewisePolynomial(xi,yi)
Does not yield a linear interpolation of the two points but
ZeroDivisionError: integer division or modulo by zero
What's wrong there?
Replace your yi
with
yi = np.array([[10], [1]])
PiecewisePolynomial requires y
array to be an array-like
or a list-of-array
structure. Each element of y
can be a function value for x
and its subsequent derivatives. Above change to y
creates the correct linear interpolation
p = PiecewisePolynomial(xi,yi)
p.__call__([5.])
>> array([6.])
p.__call__([2.])
>> array([9.])
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.