from matplotlib import pyplot as plt X=[-3, -2, -1, 0, 1, 2, 3] Y=[9, 4, 1, 0, 1, 0, 0] cur_x = 4 def lagr(x, y, cur_x): res = 0.0 n = len(X) for i in range(n): l_i=1.0 for j in range(n): if i == j: continue l_i*=(cur_x-float(x[j]))/(x[i]-x[j]) res+=y[i]*l_i return res X_new = [] Y_new = [] step=0.001 X_start,X_stop = X[0],X[-1] while X_start