Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.46 KB | None | 0 0
  1. def n(j,axis,x):
  2. n=1
  3. for i in np.arange(j):
  4. n *=(axis-x[i])
  5. return n
  6. def divdif(y,x,i,n):
  7. if n==0:
  8. return y[i]
  9. if n==1:
  10. return (y[i]-y[i-1])/(x[i-1]-x[i])
  11. else:
  12. return (divdif(y,x,i,n-1)-divdif(y,x,i-1,n-1))/(x[i-n]-x[i])
  13. def N(axis,x,y):
  14. N=0.
  15. for j in range(len(x)):
  16. N +=divdif(f(x),x,-1,j)*n(j,axis,x)
  17. return N
  18. for order in dano:
  19. x=np.linspace(-1.,1.,order,endpoint=True)
  20. plt.plot(x,f(x),'d')
  21. plt.plot(xaxis,N(xaxis,x,f(x)),label='n='+str(order))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement