用示波器测动态滞回线

大学物理(下)实验-中南民族大学通信工程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()

结果显示

相关推荐
230万光年的思念22 分钟前
分子动力学模拟参考文献
python
HongXu_CaiYi1 小时前
0103-python相关-函数、文件
python
vortex52 小时前
从Conda到UV:Python项目依赖管理的现代演进
python·conda·uv
何以解忧,唯有..2 小时前
Python time 模块详解:时间处理与日期操作指南
开发语言·python
梅雅达编程笔记2 小时前
Day 18 · 综合实战 B:AI 客服 Agent(专栏收官)
python·智能客服·ai agent·意图识别·ai客服·大模型应用·ai办公自动化
测试老哥3 小时前
Pytest自动化测试框架tep环境变量、fixtures、用例三者之间的关系
自动化测试·软件测试·python·测试工具·测试用例·pytest·职场发展
Buke..3 小时前
【APP 逆向】哔哩哔哩 sign 参数逆向(下):OLLVM 混淆还原 sign 算法
java·javascript·爬虫·python·算法
JacksonMx3 小时前
Java CompletableFuture 异步编程实战:从入门到架构师避坑指南
linux·数据库·python
W_326003 小时前
Python-OpenCV HSV颜色空间与inRange颜色分割:按颜色提取目标物体
图像处理·人工智能·python·opencv·机器学习
Buke..4 小时前
【APP 逆向】哔哩哔哩 sign 参数逆向(上):Frida 反调试绕过与 unidbg 调用
java·开发语言·爬虫·python·安卓