Haifisch7734

Lagrange

Nov 8th, 2014
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.67 KB | None | 0 0
  1. def conv(T, x):
  2.     Ttmp = T[:] #skopiowanie zawartosci tablicy bez referencji
  3.     for i in range(1, len(T)):
  4.         T[i] = Ttmp[i -1] * x + Ttmp[i]
  5.     T.append(x * Ttmp[len(Ttmp) - 1])
  6.     return T
  7.  
  8. def interpolate(X, Y):
  9.     Tret = []  
  10.     for i in range(0, len(X)):
  11.         Tret.append(0)
  12.     for i in range(0, len(X)):
  13.         T = [1]
  14.         m = Y[i]
  15.         for j in range(0, len(X)):
  16.             if i != j:
  17.                 T = conv(T, -X[j])
  18.                 m = m / (X[i] - X[j])
  19.         for j in range(0, len(T)):
  20.             T[j] = T[j] * m
  21.             Tret[j] = Tret[j] + T[j]
  22.     return Tret
  23.    
  24. X = [0.230000, 0.270000, 0.330000, 0.410000, 0.470000, 0.520000]
  25. Y = [0.050042, 0.100335, 0.171657, 0.255342, 0.309336, 0.376403]
  26.  
  27. T = interpolate(X,Y)
  28. print T
Advertisement
Add Comment
Please, Sign In to add comment