fork download
  1. import matplotlib.pyplot as plt
  2. import numpy as np
  3.  
  4. # ---------------- 参数(ωn=1) ----------------
  5. wn = 1
  6. xi_underd = 0.6 # 欠阻尼
  7. xi_over = 1.5 # 过阻尼
  8.  
  9. # 计算各根坐标
  10. # 无阻尼
  11. s_undamp1 = 0 + 1j*wn
  12. s_undamp2 = 0 - 1j*wn
  13. # 欠阻尼
  14. sigma_u = -xi_underd * wn
  15. omega_d = np.sqrt(1 - xi_underd**2) * wn
  16. s_under1 = sigma_u + 1j*omega_d
  17. s_under2 = sigma_u - 1j*omega_d
  18. # 临界阻尼
  19. s_crit = -wn
  20. # 过阻尼
  21. sigma_o = -xi_over * wn
  22. omega_o = np.sqrt(xi_over**2 - 1) * wn
  23. s_over1 = sigma_o + omega_o
  24. s_over2 = sigma_o - omega_o
  25.  
  26. # ---------------- 绘图 ----------------
  27. plt.figure(figsize=(9,8), dpi=120)
  28. ax = plt.gca()
  29. ax.set_aspect('equal')
  30.  
  31. # 坐标轴
  32. ax.axhline(y=0, color='k', lw=1.2)
  33. ax.axvline(x=0, color='k', lw=1.2)
  34. plt.text(0.05, 0.05, "O", fontsize=13)
  35. plt.xlabel(r'$\sigma$ (实轴)', fontsize=12)
  36. plt.ylabel(r'$j\omega$ (虚轴)', fontsize=12)
  37.  
  38. # 单位圆
  39. theta = np.linspace(0, 2*np.pi, 200)
  40. xc = np.cos(theta)
  41. yc = np.sin(theta)
  42. ax.plot(xc, yc, c='gray', ls='--', lw=1, label='单位圆')
  43.  
  44. # 画各阻尼极点(不同颜色)
  45. # 无阻尼:红色
  46. ax.plot(s_undamp1.real, s_undamp1.imag, 'ro', markersize=8)
  47. ax.plot(s_undamp2.real, s_undamp2.imag, 'ro', markersize=8)
  48. plt.text(0.08, 1.05, r'无阻尼: $\lambda_{1,2}=\pm j\omega_n$', color='r', fontsize=10)
  49.  
  50. # 欠阻尼:蓝色
  51. ax.plot(s_under1.real, s_under1.imag, 'bo', markersize=8)
  52. ax.plot(s_under2.real, s_under2.imag, 'bo', markersize=8)
  53. plt.text(sigma_u-0.32, omega_d+0.12,
  54. r'欠阻尼: $\lambda_{1,2}=-\xi\omega_n\pm j\sqrt{1-\xi^2}\omega_n$',
  55. color='b', fontsize=10)
  56.  
  57. # 临界阻尼:绿色(重根,一个点)
  58. ax.plot(s_crit.real, s_crit.imag, 'gs', markersize=9)
  59. plt.text(s_crit-0.38, -0.13,
  60. r'临界阻尼: $\lambda_1=\lambda_2=-\omega_n$',
  61. color='g', fontsize=10)
  62.  
  63. # 过阻尼:橙色
  64. ax.plot(s_over1.real, s_over1.imag, 'o', c='#ff8822', markersize=8)
  65. ax.plot(s_over2.real, s_over2.imag, 'o', c='#ff8822', markersize=8)
  66. plt.text(s_over2-0.35, 0.13,
  67. r'过阻尼: $\lambda_{1,2}=-\xi\omega_n\pm\sqrt{\xi^2-1}\omega_n$',
  68. color='#ff8822', fontsize=10)
  69.  
  70. plt.xlim(-2.2, 1.2)
  71. plt.ylim(-1.6, 1.6)
  72. plt.grid(True, alpha=0.3)
  73. plt.title("二阶系统:不同阻尼下特征根在s复平面上的位置示意图", fontsize=13)
  74. plt.tight_layout()
  75. plt.show()
  76.  
Success #stdin #stdout #stderr 1.1s 67044KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
/usr/local/lib/python3.7/dist-packages/matplotlib/mathtext.py:843: MathTextWarning: Font 'default' does not have a glyph for '\u5b9e' [U+5b9e], substituting with a dummy symbol.
  MathTextWarning)
/usr/local/lib/python3.7/dist-packages/matplotlib/mathtext.py:843: MathTextWarning: Font 'default' does not have a glyph for '\u8f74' [U+8f74], substituting with a dummy symbol.
  MathTextWarning)
/usr/local/lib/python3.7/dist-packages/matplotlib/mathtext.py:843: MathTextWarning: Font 'default' does not have a glyph for '\u865a' [U+865a], substituting with a dummy symbol.
  MathTextWarning)
/usr/local/lib/python3.7/dist-packages/matplotlib/mathtext.py:843: MathTextWarning: Font 'default' does not have a glyph for '\u65e0' [U+65e0], substituting with a dummy symbol.
  MathTextWarning)
/usr/local/lib/python3.7/dist-packages/matplotlib/mathtext.py:843: MathTextWarning: Font 'default' does not have a glyph for '\u963b' [U+963b], substituting with a dummy symbol.
  MathTextWarning)
/usr/local/lib/python3.7/dist-packages/matplotlib/mathtext.py:843: MathTextWarning: Font 'default' does not have a glyph for '\u5c3c' [U+5c3c], substituting with a dummy symbol.
  MathTextWarning)
/usr/local/lib/python3.7/dist-packages/matplotlib/mathtext.py:843: MathTextWarning: Font 'default' does not have a glyph for '\u6b20' [U+6b20], substituting with a dummy symbol.
  MathTextWarning)
/usr/local/lib/python3.7/dist-packages/matplotlib/mathtext.py:843: MathTextWarning: Font 'default' does not have a glyph for '\u4e34' [U+4e34], substituting with a dummy symbol.
  MathTextWarning)
/usr/local/lib/python3.7/dist-packages/matplotlib/mathtext.py:843: MathTextWarning: Font 'default' does not have a glyph for '\u754c' [U+754c], substituting with a dummy symbol.
  MathTextWarning)
/usr/local/lib/python3.7/dist-packages/matplotlib/mathtext.py:843: MathTextWarning: Font 'default' does not have a glyph for '\u8fc7' [U+8fc7], substituting with a dummy symbol.
  MathTextWarning)