Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import matplotlib.pyplot as plt
- rzad = 10
- with open("data15.txt") as f:
- values = [l.split() for l in f]
- x_v = [float(w[0]) for w in values]
- y_v = [float(w[1]) for w in values]
- print(x_v)
- b_v = [y_v[0]]
- tabela = np.zeros((rzad+1, rzad+1))
- for i in range(rzad+1):
- tabela[i][0] = y_v[i]
- for i in range(1, rzad + 1):
- for j in range(rzad + 1 - i):
- tabela[j][i] = (tabela[j+1][i-1] - tabela[j][i-1]) / (x_v[j+1] - x_v[j])
- b_v.append(tabela[0][i])
- def odp_inter(x):
- x_minus = x - np.asarray(x_v)
- x_mnozone = np.multiply.accumulate(x_minus)
- x_mnozone = x_mnozone[:-1]
- b_mnozone = b_v[1:]
- siup = x_mnozone * b_mnozone
- return b_v[0] + sum(siup)
- print(b_v)
- xn_v = np.arange(-5, 5, 0.01)
- xn_v = xn_v.tolist()
- yn_v = [odp_inter(i) for i in xn_v]
- plt.plot(xn_v, yn_v)
- plt.plot(x_v, y_v)
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement