【发布时间】:2010-10-23 11:45:11
【问题描述】:
我想用拉格朗日方法插值多项式,但这段代码不起作用:
def interpolate(x_values, y_values):
def _basis(j):
p = [(x - x_values[m])/(x_values[j] - x_values[m]) for m in xrange(k + 1) if m != j]
return reduce(operator.mul, p)
assert len(x_values) != 0 and (len(x_values) == len(y_values)), 'x and y cannot be empty and must have the same length'
k = len(x_values)
return sum(_basis(j) for j in xrange(k))
我关注了Wikipedia,但是当我运行它时,我在第 3 行收到了 IndexError!
谢谢
【问题讨论】:
-
如果反对者能解释反对意见,我将不胜感激......
标签: python interpolation polynomial-math