Pouknouki

Plot 2

Jan 21st, 2016
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. import matplotlib.pyplot as plt
  2. import numpy as np
  3. from scipy import interpolate
  4.  
  5. def Lag(x, i, t):
  6. produit = 1
  7. for j in range(0, len(x)):
  8. if i != j:
  9. produit *= (t - x[j])/(x[i]-x[j])
  10. return produit
  11.  
  12. def Interp(x, y, t):
  13. somme = 0
  14. for i in range(0, len(x)):
  15. somme += y[i] * Lag(x, i, t)
  16.  
  17. return somme
  18.  
  19. x = [-2,5,10,-1,0,2]
  20. y = [-2,3,4,1,1,-1]
  21.  
  22. plt.ylim((-3,3))
  23. plt.xlim((-3,3))
  24. for i in range(0, 4):
  25. xR = np.linspace(-3, 3)
  26. yR = []
  27. for j in xR:
  28. yR.append(Interp(x, y, j))
  29. plt.plot(x[i], y[i], "o")
  30. plt.plot(xR, yR)
  31. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment