Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- X=[1,2,3,4,5]
- Y=[1,8,27,64,125]
- cur_X= 2
- def L(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
- print L(X,Y,cur_X)
Advertisement
Add Comment
Please, Sign In to add comment