Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import matplotlib.pyplot as plt
- import numpy as np
- from scipy import interpolate
- def Lag(x, i, t):
- produit = 1
- for j in range(0, len(x)):
- if i != j:
- produit *= (t - x[j])/(x[i]-x[j])
- return produit
- def Interp(x, y, t):
- somme = 0
- for i in range(0, len(x)):
- somme += y[i] * Lag(x, i, t)
- return somme
- x = [-2,5,10,-1,0,2]
- y = [-2,3,4,1,1,-1]
- plt.ylim((-3,3))
- plt.xlim((-3,3))
- for i in range(0, 4):
- xR = np.linspace(-3, 3)
- yR = []
- for j in xR:
- yR.append(Interp(x, y, j))
- plt.plot(x[i], y[i], "o")
- plt.plot(xR, yR)
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment