In [61]:
import numpy as np
from matplotlib import pyplot as plt
data_points = np.array([
[ 4936.490, 0],
[ 7264.623, 0.7],
[ 9005.072, 10.4],
[10343.531, 37.0],
[11441.591, 77.4],
[12391.082, 122.8],
[13245.908, 169.5],
[14038.782, 216.0],
[14727.344, 254.0],
[15398.375, 286.0],
[15997.332, 314.0],
[16597.289, 336.0]
])
x, y = data_points.T
plt.scatter(x,y)
Out[61]:
In [62]:
a = ( np.mean(y)*sum([i*i for i in x]) - np.mean(x)*sum(np.multiply(x, y)) ) / (sum([i*i for i in x]) - len(x)*np.mean(x)**2)
b = ( sum(np.multiply(x, y)) - len(x)*np.mean(x)*np.mean(y) ) / (sum([i*i for i in x]) - len(x)*np.mean(x)**2)
line = np.polyfit(x, y, 1)
print(line, (a,b))
In [68]:
def lineeqn(xo):
return line[0]*xo + line[1]
plt.plot(x, y, 'b+')
plt.plot(x, lineeqn(x), 'r')
plt.grid()
plt.show()
In [64]:
vsd = [j - line[1] for j in y]
stefs = []
for l in range(len(vsd)):
stefs.append(2.43*10**(-4)*vsd[l]/x[l])
stefs, np.mean(stefs)
Out[64]:
In [58]:
stef = 2.43*10**(-4)*(216.0-line[1])/14038.782*10**-3
stef
Out[58]: