Skip to content

Commit

Permalink
Merge pull request BlackSamorez#46 from intex2dx/master
Browse files Browse the repository at this point in the history
Лаба 1.4.5. Подробно расписана теор. часть.
  • Loading branch information
galqiwi authored Nov 11, 2022
2 parents 8873337 + dac5dee commit 1614cc5
Show file tree
Hide file tree
Showing 9 changed files with 517 additions and 0 deletions.
46 changes: 46 additions & 0 deletions 1.4.5/Artemov_I/lab 1 4 5 график квадрата.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import numpy as np
import matplotlib.pyplot as plt


def xi2(x,y, y_err):
#y = a + bx
N = len(x)
avx = sum(x/(y_err**2))/sum(1/(y_err**2))
avy = sum(y/(y_err**2))/sum(1/(y_err**2))
av2x = sum(x*x/(y_err**2))/sum(1/(y_err**2))
av2y = sum(y*y/(y_err**2))/sum(1/(y_err**2))
R_xy = (sum(x*y/(y_err**2))/sum(1/(y_err**2))-avx*avy)
S_x = av2x - avx**2
S_y = av2y - avy**2
b = R_xy/S_x
a = avy - b * avx
r = R_xy/(np.sqrt(S_x*S_y))
delta_b = np.sqrt(1/(N-2)) * np.sqrt(S_y/S_x - b**2)
delta_a = delta_b * np.sqrt(av2x)
f = a + b * x
xi = sum(((y-f)/y_err)**2)
return a, b, delta_a, delta_b, xi, r

T = np.array([10.3, 15.1, 19.9, 23.2, 28.0])
u2 = np.array([183.10, 261.0, 341.1, 396.0, 478.7])
delta_u2 = np.array([0.8, 1.0, 0.7, 0.8, 1.3])
a, b, delta_a, delta_b, xi, r = xi2(T, u2, delta_u2)
plt.errorbar(T, u2, delta_u2, [0]*5, ls='none', fmt='o-', elinewidth=2, markersize=4, color='black', capsize=2)
plt.xlabel(r"$T$, Н")
plt.ylabel(r'$u^2, 10^{2} \cdot м^2/с^2$')
T1 = np.array([9, 10.3, 15.1, 19.9, 23.2, 28.0, 30])
u2_normal = a + b * T1
print(a)
print(b)
print(delta_a)
print(delta_b)
print(r)
print(xi/3)
plt.plot(T1, u2_normal, color='red', linewidth=1, label=r'''$u^2(T) = (11 \pm 2)\cdot 10^2 + (16.61 \pm 0.10) \cdot T$
$r = 0.99994$
$\frac{\chi^2}{d.o.f.} = 2.27$
''')
plt.grid(which='major',
color = 'k')
plt.legend()
plt.show()
11 changes: 11 additions & 0 deletions 1.4.5/Artemov_I/lab 1 4 5.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
 n;nu;nu;nu;nu;nu
1;134.6;161.5;186.7;201.4;223
2;271.2;325;373.5;404.3;444
3;405.3;488.7;563;607.5;667.5
4;543.6;653.6;750.4;810.4;891.6
5;681.9;811.9;940.3;1013.5;1113
6;819.3;982.4;1129.6;1215;1338
7;957.1;1149;1317.5;1418;1559
8;1096;1313;1505;1622;1783
9;1238.4;1479;1695;1825;2008
10;1378;1645;1881;2031;2233
104 changes: 104 additions & 0 deletions 1.4.5/Artemov_I/lab 1 4 5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
def xi2(x,y, y_err):
#y = a + bx
N = len(x)
avx = sum(x/y_err)/N
avy = sum(y/y_err)/N
av2x = sum(x*x/y_err)/N
av2y = sum(y*y/y_err)/N
R_xy = (sum(x*y/y_err)/N-avx*avy)
S_x = av2x - avx**2
S_y = av2y - avy**2
b = R_xy/S_x
a = avy - b * avx
r = R_xy/(S_x*S_y)
delta_b = np.sqrt(1/(N-2)) * np.sqrt(S_y/S_x - b**2)
delta_a = delta_b * np.sqrt(av2x)
f = a + b * x
xi = sum(((y-f)/y_err)**2)
return a, b, delta_a, delta_b, xi, r


df = pd.read_csv("lab 1 4 5.csv", encoding="utf-8", sep=";")
n = df.iloc[:, [0]]
nu_1 = df.iloc[:, [1]]
nu_1_list = np.array((nu_1["nu"]))

x = np.array(range(1, 11))
print(x)
plt.plot(x, nu_1_list, color="black", marker='o', ls="none", markersize= 4.5)
plt.xlabel("n")
plt.ylabel(r"$\nu_n(n), Гц$")
print(x)
print(nu_1_list)
res = xi2(x, nu_1_list, np.array([1]*10))
plt.plot([0, 11], [res[0], res[0] + res[1]*11], color="black", label=r"$\nu_n = (-7.2 \pm 1.9) + (138.1 \pm 0.3) \cdot n$", linewidth=0.8)
print(res)


nu_1 = df.iloc[:, [2]]
nu_1_list = np.array((nu_1["nu.1"]))

x = np.array(range(1, 11))
print(x)
plt.plot(x, nu_1_list, color="red", marker='o', ls="none", markersize= 4.5)
plt.xlabel("n")
plt.ylabel(r"$\nu_n(n), Гц$")
print(x)
print(nu_1_list)
res = xi2(x, nu_1_list, np.array([1]*10))
plt.plot([0, 11], [res[0], res[0] + res[1]*11], color="red", label=r"$\nu_n = (-6.0 \pm 1.8) + (164.9 \pm 0.3) \cdot n$",linewidth=0.8)
print(res)


nu_1 = df.iloc[:, [3]]
nu_1_list = np.array((nu_1["nu.2"]))

x = np.array(range(1, 11))
print(x)
plt.plot(x, nu_1_list, color="grey", marker='o', ls="none", markersize= 4.5)
plt.xlabel("n")
plt.ylabel(r"$\nu_n(n), Гц$")
print(x)
print(nu_1_list)
res = xi2(x, nu_1_list, np.array([1]*10))
plt.plot([0, 11], [res[0], res[0] + res[1]*11], color="grey", label=r"$\nu_n = (-2.5 \pm 0.7) + (188.48 \pm 0.11) \cdot n$",linewidth=0.8)
print(res)


nu_1 = df.iloc[:, [4]]
nu_1_list = np.array((nu_1["nu.3"]))

x = np.array(range(1, 11))
print(x)
plt.plot(x, nu_1_list, color="green", marker='o', ls="none", markersize= 4.5)
plt.xlabel("n")
plt.ylabel(r"$\nu_n(n), Гц$")
print(x)
print(nu_1_list)
res = xi2(x, nu_1_list, np.array([1]*10))
plt.plot([0, 11], [res[0], res[0] + res[1]*11], color="green", label=r"$\nu_n = (-2.1 \pm 0.8) + (203.08 \pm 0.13) \cdot n$",linewidth=0.8)
print(res)


nu_1 = df.iloc[:, [5]]
nu_1_list = np.array((nu_1["nu.4"]))

x = np.array(range(1, 11))
print(x)
plt.plot(x, nu_1_list, color="darkblue", marker='o', ls="none", markersize= 4.5)
plt.xlabel("n")
plt.ylabel(r"$\nu_n(n), Гц$")
print(x)
print(nu_1_list)
res = xi2(x, nu_1_list, np.array([1]*10))
plt.plot([0, 11], [res[0], res[0] + res[1]*11], color="darkblue", label=r"$\nu_n = (-2.1 \pm 1.0) + (223.29 \pm 0.16) \cdot n$",linewidth=0.8)
print(res)


plt.legend()
plt.grid(which='major',
color = 'k')
plt.show()
Loading

0 comments on commit 1614cc5

Please sign in to comment.