Pouknouki

Plot

Jan 21st, 2016
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 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 * k * np.pi / 30 for k in range(0, 31)]
  20. y = [np.cos(x[i]) for i in range(0, 31)]
  21.  
  22. xR = np.linspace(0,2*np.pi,31)
  23.  
  24. plt.ylim((-2,2))
  25. plt.xlim((0,2*np.pi))
  26. for i in range(0, 31):
  27. yR = []
  28. for j in xR:
  29. yR.append(Interp(x, y, j))
  30. plt.plot(x[i], y[i], "o")
  31. plt.plot(xR, yR)
  32. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment