二阶无阻尼微分方程

Figure_1


import numpy as np
import matplotlib.pyplot as plt

# 中文显示设置
plt.rcParams["font.family"] = ["SimHei", "Microsoft YaHei"]
plt.rcParams["axes.unicode_minus"] = False

t = np.linspace(0, 4 * np.pi, 1000)

# 创建1行3列子图,三张图放在一张画布中
fig, (ax1, ax2, ax3) = plt.subplots(1, 3, figsize=(18, 6))

# ========== 子图1:固定相位,改变振幅 ==========
phi = 0
amp_list = [0.5, 1, 1.5, 2]
for A in amp_list:
    x = A * np.cos(t + phi)
    ax1.plot(t, x, linewidth=1.8, label=f'振幅 $A={A}$')
ax1.set_xlabel('$t$')
ax1.set_ylabel('$x(t)$')
ax1.set_title(r'$\ddot{x}+x=0$:固定相位,改变振幅')
ax1.grid(alpha=0.3)
ax1.legend()

# ========== 子图2:固定振幅,改变相位 ==========
A = 1.5
phi_list = [0, np.pi/4, np.pi/2, np.pi]
for phi in phi_list:
    x = A * np.cos(t + phi)
    ax2.plot(t, x, linewidth=1.8, label=f'相位 $\phi={phi:.2f}$')
ax2.set_xlabel('$t$')
ax2.set_ylabel('$x(t)$')
ax2.set_title(r'$\ddot{x}+x=0$:固定振幅,改变相位')
ax2.grid(alpha=0.3)
ax2.legend()

# ========== 子图3:相平面轨迹图 ==========
theta = np.linspace(0, 2 * np.pi, 300)
r_list = [0.5, 1, 1.5, 2]
for r in r_list:
    x = r * np.cos(theta)
    dx = -r * np.sin(theta)
    ax3.plot(x, dx, linewidth=2, label=f'振幅 $r={r}$')
ax3.set_xlabel('$x$')
ax3.set_ylabel(r'$\dot{x}$')
ax3.set_title(r'$\ddot{x}+x=0$ 相平面轨迹(无阻尼简谐振动)')
ax3.grid(alpha=0.3)
ax3.axis('equal')
ax3.legend()

# 调整子图间距,防止标题、标签重叠
plt.tight_layout()
plt.show()
posted @ 2026-06-27 00:00  redufa  阅读(6)  评论(0)    收藏  举报