本文实例讲述了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程序设计有所帮助。
您可能感兴趣的文章:python的迭代器与生成器实例详解Python迭代用法实例教程Python中Iterator迭代器的使用杂谈python中迭代器(iterator)用法实例分析python迭代器与生成器详解python使用三角迭代计算圆周率PI的方法Python 字典(Dictionary)操作详解python两种遍历字典(dict)的方法比较python通过字典dict判断指定键值是否存在的方法Python中实现两个字典(dict)合并的方法Python实现字典(dict)的迭代操作示例