大学物理(下)实验-中南民族大学通信工程2022级
手动逐个处理数据较为麻烦且还要绘图,故想到用python+matplotlib来计算结果并数据可视化。
代码实现
python
import matplotlib.pyplot as plt
# 样品一磁化曲线
X = [0, 0.2, 0.4, 0.6, 0.8, 1, 1.5, 2.0, 2.5, 3.0, 4.0]
N1 = 100
Sx = 0.144
L = 0.13
R1 = 4.4
H = []
for x in X:
h = (N1 * Sx * x) / (L * R1)
H.append(h)
# print(f'H={h:.2f}')
Y = [0, 0.6, 1.0, 1.7, 2.0, 2.2, 2.8, 3.0, 3.4, 3.4, 4.0]
R2 = 44000
C = 0.000001
N2 = 100
S = 1.24 * (10 ** (-4))
Sy = 23
B = []
for y in Y:
b = (R2 * C * Sy * y) / (N2 * S)
B.append(b)
# print(f'B={b:.2f}')
plt.figure()
plt.plot(H, B, '-o', )
for i, b in enumerate(B):
plt.text(H[i], b + 4, f'{b:.2f}', ha='center', va='bottom')
plt.xlabel('magnetic field H(A/m)')
plt.ylabel('magnetic induction B(mT)')
plt.title('Sample 1 Magnetization Curve')
plt.grid(True)
plt.show()
# 样品一磁滞回线
X1 = [4, 3, 2, 1, 0, 2.7, 2, 1.7, 1.4, 1, 0.3, -1, -3, -4]
X2 = [-4, -3, -2, -1, 0, -2.5, -2, -1.7, -1.4, -1, -0.3, 1, 3, 4]
N1 = 100
Sx = 0.144
L = 0.13
R1 = 4.4
# H
H1, H2 = [], []
for x in X1:
h = (N1 * Sx * x) / (L * R1)
H1.append(h)
for x in X2:
h = (N1 * Sx * x) / (L * R1)
H2.append(h)
# B
Y1 = [3.8, 3.4, 2.1, -1, -2.3, 3, 2, 1, 0, -1, -2, -3, -3.8, -4]
Y2 = [-3.9, -3.5, -2, 1, 2.3, -3, -2, -1, 0, 1, 2, 3, 3.6, 4]
R2 = 44000
C = 10 ** (-6)
N2 = 100
S = 1.24 * (10 ** (-4))
Sy = 23
B1, B2 = [], []
for y in Y1:
b = (R2 * C * Sy * y) / (N2 * S)
B1.append(b)
for y in Y2:
b = (R2 * C * Sy * y) / (N2 * S)
B2.append(b)
# 绘图
plt.figure()
H1.sort()
B1.sort()
plt.plot(H1, B1, '-o', )
H2.sort()
B2.sort()
plt.plot(H2, B2, '-o', )
for i, b in enumerate(B1):
plt.text(H1[i], b + 4, f'{b:.2f}', ha='left', va='bottom')
for i, b in enumerate(B2):
plt.text(H2[i], b - 4, f'{b:.2f}', ha='right', va='bottom')
plt.xlabel('magnetic field H(A/m)')
plt.ylabel('magnetic induction B(mT)')
plt.title('The magnetic hysteresis loop of Sample One')
plt.grid(True)
plt.show()
# 样品二磁滞回线
X1 = [4, 0, 1.25, -4]
X2 = [-4, 0, -1.5, 3.8]
N1 = 100
Sx = 0.052
L = 0.13
R1 = 4.4
# H
H1, H2 = [], []
for x in X1:
h = (N1 * Sx * x) / (L * R1)
H1.append(h)
for x in X2:
h = (N1 * Sx * x) / (L * R1)
H2.append(h)
# B
Y1 = [4, -2.2, 0, -4]
Y2 = [-4, 2.2, 0, 4]
R2 = 44000
C = 10 ** (-6)
N2 = 100
S = 1.24 * (10 ** (-4))
Sy = 21.2
B1, B2 = [], []
for y in Y1:
b = (R2 * C * Sy * y) / (N2 * S)
B1.append(b)
for y in Y2:
b = (R2 * C * Sy * y) / (N2 * S)
B2.append(b)
# 绘图
plt.figure()
H1.sort()
B1.sort()
plt.plot(H1, B1, '-o', )
H2.sort()
B2.sort()
plt.plot(H2, B2, '-o', )
for i, b in enumerate(B1):
plt.text(H1[i], b + 4, f'{b:.2f}', ha='left', va='bottom')
for i, b in enumerate(B2):
plt.text(H2[i], b - 4, f'{b:.2f}', ha='right', va='bottom')
plt.xlabel('magnetic field H(A/m)')
plt.ylabel('magnetic induction B(mT)')
plt.title('The magnetic hysteresis loop of Sample Two')
plt.grid(True)
plt.show()