In [2]:
import numpy as np
from matplotlib import pyplot as plt
data_points = np.array([
[300, 207],
[310, 209],
[320, (195+199)/2],
[330, (176+180)/2],
[340, 146.5],
[350, (114+117)/2],
[360, 89],
[370, 70],
[380, 53],
[390, 40.5],
[400, 32.5],
[410, 26]
])
x, y = data_points.T
plt.scatter(x,y)
Out[2]:
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]: