Dvortsov_D1

formula langranga (interpolysia)

Nov 24th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.25 KB | None | 0 0
  1. X=[1,2,3,4,5]
  2. Y=[1,8,27,64,125]
  3. cur_X= 2
  4. def L(X,Y,cur_X):
  5.     res=0.0
  6.     n=len(X)
  7.     for i in range(n):
  8.         l_i=1.0
  9.         for j in range(n):
  10.             if i==j:
  11.                  continue
  12.             l_i*=(cur_X-float (X[j]))/(X[i]-X[j])
  13.         res+=Y[i]*l_i;
  14.     return res     
  15. print L(X,Y,cur_X)
Advertisement
Add Comment
Please, Sign In to add comment