fig, axes = plt.subplots(1, 2, figsize=(11, 4))
t_plot = np.linspace(0, 0.5, 1000)
# Varying voltage
for V_val, color, lbl in zip([3, 6, 9, 12],
plt.cm.Blues(np.linspace(0.4, 0.9, 4)),
['$V=3$ V','$V=6$ V','$V=9$ V','$V=12$ V']):
def motor_V(t, y, V=V_val):
I, omega = y
return [(V - Ra*I - Kb*omega)/La, (Kt*I - b*omega)/J]
sol = solve_ivp(motor_V, (0,0.5), [0,0], t_eval=t_plot, max_step=1e-4)
axes[0].plot(sol.t*1e3, sol.y[1], color=color, lw=2, label=lbl)
omega_ss_v = Kt*V_val/(b*Ra + Kb*Kt)
axes[0].axhline(omega_ss_v, color=color, ls=':', lw=1, alpha=0.7)
axes[0].set_xlabel('Time (ms)'); axes[0].set_ylabel('$\\omega(t)$ (rad/s)')
axes[0].set_title('Speed control: varying $V$')
axes[0].legend(fontsize=8.5)
# Varying friction
V_fixed = 12.0
for b_val, color, lbl in zip([0.05, 0.1, 0.2, 0.5],
plt.cm.Reds(np.linspace(0.4, 0.9, 4)),
['$b=0.05$','$b=0.1$','$b=0.2$','$b=0.5$']):
def motor_b(t, y, bv=b_val):
I, omega = y
return [(V_fixed - Ra*I - Kb*omega)/La, (Kt*I - bv*omega)/J]
sol = solve_ivp(motor_b, (0,0.5), [0,0], t_eval=t_plot, max_step=1e-4)
omega_ss_b = Kt*V_fixed/(b_val*Ra + Kb*Kt)
axes[1].plot(sol.t*1e3, sol.y[1], color=color, lw=2,
label=f'{lbl}, $\\omega_{{ss}}={omega_ss_b:.1f}$')
axes[1].set_xlabel('Time (ms)'); axes[1].set_ylabel('$\\omega(t)$ (rad/s)')
axes[1].set_title('Effect of friction $b$ on transient ($V=12$ V)')
axes[1].legend(fontsize=7.5)
plt.tight_layout()
plt.show()