Advertisement
qtinio

ehhhh ile mozna

Apr 15th, 2019
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3.  
  4. rzad = 10
  5.  
  6. with open("data15.txt") as f:
  7. values = [l.split() for l in f]
  8. x_v = [float(w[0]) for w in values]
  9. y_v = [float(w[1]) for w in values]
  10. print(x_v)
  11.  
  12. b_v = [y_v[0]]
  13.  
  14.  
  15.  
  16. tabela = np.zeros((rzad+1, rzad+1))
  17.  
  18. for i in range(rzad+1):
  19. tabela[i][0] = y_v[i]
  20.  
  21. for i in range(1, rzad + 1):
  22. for j in range(rzad + 1 - i):
  23. tabela[j][i] = (tabela[j+1][i-1] - tabela[j][i-1]) / (x_v[j+1] - x_v[j])
  24. b_v.append(tabela[0][i])
  25.  
  26.  
  27. def odp_inter(x):
  28. x_minus = x - np.asarray(x_v)
  29. x_mnozone = np.multiply.accumulate(x_minus)
  30. x_mnozone = x_mnozone[:-1]
  31. b_mnozone = b_v[1:]
  32. siup = x_mnozone * b_mnozone
  33. return b_v[0] + sum(siup)
  34.  
  35.  
  36. print(b_v)
  37. xn_v = np.arange(-5, 5, 0.01)
  38. xn_v = xn_v.tolist()
  39.  
  40. yn_v = [odp_inter(i) for i in xn_v]
  41.  
  42. plt.plot(xn_v, yn_v)
  43. plt.plot(x_v, y_v)
  44. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement