python计算牛顿迭代多项式实例分析

本文实例讲述了python计算牛顿迭代多项式的方法。分享给大家供大家参考。具体实现方法如下:

”’ p = evalpoly(a,xdata,x).
evaluates newton’s polynomial p at x. the coefficient
vector ‘a’ can be computed by the function ‘coeffts’.
a = coeffts(xdata,ydata).
computes the coefficients of newton’s polynomial.
”’
def evalpoly(a,xdata,x):
n = len(xdata) – 1 # degree of polynomial
p = a[n]
for k in range(1,n+1):
p = a[n-k] + (x -xdata[n-k])*p
return p
def coeffts(xdata,ydata):
m = len(xdata) # number of data points
a = ydata.copy()
for k in range(1,m):
a[k:m] = (a[k:m] – a[k-1])/(xdata[k:m] – xdata[k-1])
return a

希望本文所述对大家的python程序设计有所帮助。

Posted in 未分类

发表评论