🟩 Complete every # TODO. Solution: 02_SDOF_ForcedVibration_FRF.ipynb.
Recall , and with : .
import numpy as np
import matplotlib.pyplot as plt
import sympy as sp
import control
from scipy.integrate import solve_ivp
plt.rcParams["figure.figsize"] = (7, 4.2)
plt.rcParams["axes.grid"] = TrueExercise “Ex1” — amplitude and phase vs. frequency ratio¶
🟩 For in steps of 0.1, plot (log-log) and the phase in degrees (semi-log-x) vs. .
r = np.logspace(-1, 1, 400)
zetas = np.arange(0.1, 1.01, 0.1)
fig, axes = plt.subplots(2, 1, figsize=(7, 8), sharex=True)
for zeta in zetas:
H = ... # TODO: complex FRF k*X/F as a function of r and zeta
mag = ... # TODO
phase_deg = ... # TODO
axes[0].loglog(r, mag, "k-", alpha=0.3 + 0.7 * zeta / zetas.max())
axes[1].semilogx(r, phase_deg, "k-", alpha=0.3 + 0.7 * zeta / zetas.max())
axes[0].set_ylabel(r"$|kX/F|$")
axes[1].set_ylabel("Phase [deg]")
axes[1].set_xlabel(r"Frequency ratio $r=\omega/\omega_n$")
plt.tight_layout()
plt.show()Exercise “Ex2a” — same FRF with python-control¶
🟩 Build sys = control.tf(num, den) for with ,
and plot its Bode diagram.
m, k = 1.0, 1.0
zeta = 0.1
c = ... # TODO
den = ... # TODO
num = ... # TODO
sys = ... # TODO
print(sys)
# TODO: control.bode_plot(...)Exercise — sinusoidal forcing and resonance (undamped)¶
🟩 Implement the general solution of with the special resonant case handled separately (amplitude growing as ).
def undamped_forced_response(t, wn, w, f0, x0, v0):
if np.isclose(w, wn):
A1, A2 = ..., ... # TODO
return ... # TODO
A2 = ... # TODO
A1 = ... # TODO
return ... # TODO
wn = 1.0
t = np.linspace(0, 60, 3000)
fig, ax = plt.subplots()
for w, label in [(0.7, r"$\omega=0.7\,\omega_n$"), (1.0, r"$\omega=\omega_n$ (resonance)")]:
x = undamped_forced_response(t, wn, w, f0=1.0, x0=0.0, v0=0.0)
ax.plot(t, x, label=label)
ax.legend()
plt.show()Exercise “H2” (handwritten) — Laplace transform table¶
🟥 Fill in the table by hand first. Then verify every entry with sympy.laplace_transform.
t_s, s_s, a_s, b_s, n_s = sp.symbols("t s a b n", positive=True)
entries = {
"a": ..., # TODO
"sin(b*t)": ..., # TODO
"cos(b*t)": ..., # TODO
"t**n": ..., # TODO
"exp(-a*t)": ..., # TODO
}
for name, f in entries.items():
F = sp.laplace_transform(f, t_s, s_s, noconds=True)
print(f"{name:<16}{sp.simplify(F)}")Exercise “laplaceEx1” — recover the particular solution¶
🟩 Take and use
sympy.inverse_laplace_transform to invert it. Show it reduces to
once .
m_s, k_s, F0_s, w_s = sp.symbols("m k F0 omega", positive=True)
X_s = ... # TODO
x_t = ... # TODO
x_tExercise — “Doing physics” — four canonical cases¶
🟩 Using solve_ivp, reproduce and plot the response for:
, , no force.
, driven at (its natural frequency), zero ICs.
, driven at , zero ICs.
, driven at , zero ICs.
Comment on each: which one keeps growing? Which one saturates? Why?
def sdof_forced_ode(t, y, m, c, k, F0, w):
x, v = y
f = F0 * np.cos(w * t)
return [v, (f - c * v - k * x) / m]
cases = [
dict(name="(1) Free SHM", m=1, c=0, k=4, F0=0, w=0, x0=1, v0=0, tmax=20),
dict(name="(2) Resonance, no damping", m=1, c=0, k=4, F0=1, w=2, x0=0, v0=0, tmax=40),
dict(name="(3) Resonance, with damping", m=1, c=0.5, k=4, F0=1, w=2, x0=0, v0=0, tmax=40),
dict(name="(4) Off-resonance, with damping", m=1, c=0.5, k=4, F0=1, w=3, x0=0, v0=0, tmax=40),
]
# TODO: loop over cases, solve_ivp each one, and plot on a 4x1 subplot grid