”’ 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


Posted in 未分类