Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from matplotlib import pyplot as plt
- def pr(x,y,cur):
- res=0.0
- for i in range (len(x)):
- li=1.0
- for j in range (len(x)):
- if (i!=j):
- li*=(cur-float(x[j]))/(x[i]-x[j])
- res+=y[i]*li
- return res
- x=[1,2,3,4,5,6]
- y=[1,8,27,64,125,216]
- x_new=[]
- y_new=[]
- step=0.0005
- x_start,x_stop=x[0],x[-1]
- while x_start<x_stop+step:
- x_new.append(x_start)
- y_new.append(pr(x,y,x_start))
- x_start+=step
- plt.plot(x_new,y_new)
- plt.plot(x,y)
- plt.show()
- print pr (x,y,1)
Add Comment
Please, Sign In to add comment