kilolilo

polin

Nov 24th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.47 KB | None | 0 0
  1. from matplotlib import pyplot as plt
  2. def pr(x,y,cur):
  3.     res=0.0
  4.     for i in range (len(x)):
  5.         li=1.0
  6.         for j in range (len(x)):
  7.             if (i!=j):
  8.                 li*=(cur-float(x[j]))/(x[i]-x[j])
  9.         res+=y[i]*li   
  10.     return res
  11. x=[1,2,3,4,5,6]
  12. y=[1,8,27,64,125,216]
  13. x_new=[]
  14. y_new=[]
  15. step=0.0005
  16. x_start,x_stop=x[0],x[-1]
  17. while x_start<x_stop+step:
  18.     x_new.append(x_start)
  19.     y_new.append(pr(x,y,x_start))
  20.     x_start+=step
  21. plt.plot(x_new,y_new)
  22. plt.plot(x,y)
  23. plt.show()
  24. print pr (x,y,1)
Add Comment
Please, Sign In to add comment