import numpy as np
import matplotlib.pyplot as plt

data = np.loadtxt('RT.txt', usecols=(0, 1))
E = data[:, 0]
OC = data[:, 1]
P = 0.62892951

X = np.ones((len(E), 3))
X[:, 1] = E
X[:, 2] = E**2
V = np.dot(X.T, X)
U = np.dot(X.T, OC)
b = np.dot(np.linalg.inv(V), U)
t = np.linspace(-60000, 10000, 100)
f = b[0] + b[1]*t + b[2]*t**2
plt.plot(E, OC, '*', t, f, 'r')
plt.xlabel('epocha')
plt.ylabel('O-C [s]')
dP = b[2]*2/P

print('Perioda RT And sa linearne skracuje o {} s za jednu periodu.'
      .format(-round(dP, 12)))
