先引入差商的概念,类似一种迭代计算?
丢代码:
1 import numpy as np 2 data = [(0.4,0.41075),(0.55,0.57815),(0.65,0.69675),(0.8,0.88811),(0.9,1.02652)] 3 4 count = len(data) 5 N = [[0 for j in range(count-i)] for i in range(count)] 6 for i in range(count): 7 N[0][i] = data[i][1] 8 print(N) 9 # 求差商表(关键点) 10 for i in range(1, len(N)): 11 for j in range(len(N[i])): 12 N[i][j] = (N[i-1][j+1] - N[i-1][j]) / (data[j+i][0] - data[j][0]) 13 print(N) 14 15 # 差值x 16 x = 0.596 17 _sum = 0 18 for i in range(count): 19 _mult = N[i][0] 20 print(N[i][0],end="") 21 for j in range(i): 22 _mult *= x-data[j][0] 23 print("(x-{})".format(data[j][0]),end= "") 24 print("+") 25 _sum += _mult 26 print(_sum)
over。