You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
981 B
Python
47 lines
981 B
Python
2 years ago
|
import matplotlib.pyplot as plt
|
||
|
import numpy as np
|
||
|
|
||
|
#x = [146.66, 293.33, 439.99, 573.33, 693.33, 773.33, 839.99, 879.99]
|
||
|
x = [0.3, 0.4, 0.5, 0.6, 0.8, 1.0]
|
||
|
|
||
|
#y = [-37, -79, -122, -161, -194, -218, -234, -245]
|
||
|
#y=[-53, -110, -165, -214, -261, -292, -314, -327]
|
||
|
#y = [-67, -137, -209, -274, -328, -368, -395, -411]
|
||
|
#y = [-83, -166, -249, -327, -393, -441, -474, -496]
|
||
|
#y = [-113, -229, -336, -442, -531, -595, -638, -664]
|
||
|
#y = [-142, -286, -424, -553, -663, -745, -800, -831]
|
||
|
#y=[135, 277, 417, 547, 660, 736, 791, 821]
|
||
|
y = [-0.28, -0.38, -0.47, -0.56, -0.75, -0.94]
|
||
|
u0 = 0
|
||
|
|
||
|
if len(x) != len(y):
|
||
|
print("size mismatch")
|
||
|
exit()
|
||
|
|
||
|
y = [i - u0 for i in y]
|
||
|
|
||
|
n = len(x)
|
||
|
|
||
|
mean_xy = 0
|
||
|
mean_x_sq = 0
|
||
|
|
||
|
for i in range(n):
|
||
|
mean_xy += x[i] * y[i]
|
||
|
mean_x_sq += x[i] ** 2
|
||
|
|
||
|
mean_xy /= n
|
||
|
mean_x_sq /= n
|
||
|
|
||
|
k = mean_xy / mean_x_sq
|
||
|
|
||
|
print("k = ", k)
|
||
|
|
||
|
plt.scatter(x,y)
|
||
|
#plt.show()
|
||
|
x_axis = np.array(range(0, 1000))
|
||
|
y_axis = k * x_axis
|
||
|
|
||
|
plt.plot(x_axis, y_axis)
|
||
|
plt.show()
|
||
|
#`plot(x, y))
|