Dvortsov_D1

polinom langranga s new znachenia

Nov 24th, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.51 KB | None | 0 0
  1. from matplotlib import pyplot as plt
  2. X=[-1.5,-0.75,0,0.75,1.5]
  3. Y=[-14.1014,-0.931596,0,0.931596,14.1014]
  4.  
  5. cur_X= 2
  6. def L(X,Y,cur_X):
  7.     res=0.0
  8.     n=len(X)
  9.     for i in range(n):
  10.         l_i=1.0
  11.         for j in range(n):
  12.             if i==j:
  13.                  continue
  14.             l_i*=(cur_X-float (X[j]))/(X[i]-X[j])
  15.         res+=Y[i]*l_i;
  16.     return res 
  17. X_new=[]
  18. Y_new=[]
  19. step=0.1
  20. X_start,X_stop=X[0], X[-1]
  21. while (X_start<X_stop+step):
  22.     X_new.append(X_start)
  23.     Y_new.append(L(X,Y,X_start))
  24.     X_start+=step  
  25. plt.plot(X_new,Y_new)
  26. plt.show()
  27. print L()
Advertisement
Add Comment
Please, Sign In to add comment