Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from matplotlib import pyplot as plt
- X=[-1.5,-0.75,0,0.75,1.5]
- Y=[-14.1014,-0.931596,0,0.931596,14.1014]
- 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
- X_new=[]
- Y_new=[]
- step=0.1
- X_start,X_stop=X[0], X[-1]
- while (X_start<X_stop+step):
- X_new.append(X_start)
- Y_new.append(L(X,Y,X_start))
- X_start+=step
- plt.plot(X_new,Y_new)
- plt.show()
- print L()
Advertisement
Add Comment
Please, Sign In to add comment