Solved reference notebook. See 02_SDOF_ForcedVibration_FRF_Exercises.ipynb for the
blanked-out version.
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"] = True2.1 Transfer function and Frequency Response Function (FRF)¶
For a SDOF system with viscous damping subjected to a force :
The complete solution is the sum of the homogeneous solution (studied in Chapter 1) and a particular solution. It is common to ignore the transient (homogeneous) part and focus on the steady-state response. Taking the Laplace transform with zero initial conditions gives the transfer function
Substituting gives the frequency response. Introducing the frequency ratio , and dividing through by :
Exercise “Ex1” — amplitude and phase vs. frequency ratio¶
Plot the (normalized) amplitude and the phase angle of the SDOF FRF for , on log-log / semi-log axes.
r = np.logspace(-1, 1, 400) # omega / omega_n, from 0.1 to 10
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 = (1.0) / ((1 - r**2) + 2j * zeta * r) # k * X/F
mag = np.abs(H)
phase_deg = np.angle(H, deg=True)
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[0].set_title(r"SDOF frequency-response magnitude, $\zeta=0.1 \ldots 1.0$")
axes[1].set_ylabel("Phase [deg]")
axes[1].set_xlabel(r"Frequency ratio $r=\omega/\omega_n$")
axes[1].set_title(r"SDOF frequency-response phase, $\zeta=0.1 \ldots 1.0$")
plt.tight_layout()
plt.show()
As , the magnitude peak at grows without bound (resonance), and the phase jumps sharply from to through at resonance. Larger flattens the peak and smooths the phase transition — this single family of curves is arguably the most important picture in this course.
Exercise “Ex2a” — the same FRF with python-control¶
Every linear time-invariant (LTI) system, such as the one above, can be specified by a transfer
function object. In MATLAB this was sys = tf(num, den); in Python we use control.tf.
m, k = 1.0, 1.0
zeta = 0.1
c = 2 * zeta * np.sqrt(k * m)
den = [m, c, k]
num = [1]
sys = control.tf(num, den)
print(sys)
control.bode_plot(sys, dB=False, deg=True)
plt.suptitle(rf"Bode plot at fixed $\zeta$={zeta}")
plt.show()<TransferFunction>: sys[0]
Inputs (1): ['u[0]']
Outputs (1): ['y[0]']
1
---------------
s^2 + 0.2 s + 1

2.2 Sinusoidal forcing and resonance (the undamped case)¶
Consider with : , . Trying a particular solution gives
Adding the homogeneous solution and applying , :
What happens at ? The particular-solution ansatz above blows up (division by zero), signalling that resonance changes the form of the particular solution to — an amplitude that grows without bound. This is the single most important physical phenomenon in this course.
def undamped_forced_response(t, wn, w, f0, x0, v0):
if np.isclose(w, wn):
A1, A2 = v0 / w, x0
return A1 * np.sin(w * t) + A2 * np.cos(w * t) + (f0 / (2 * w)) * t * np.sin(w * t)
A2 = x0 - f0 / (wn**2 - w**2)
A1 = v0 / wn
return A1 * np.sin(wn * t) + A2 * np.cos(wn * t) + f0 / (wn**2 - w**2) * np.cos(w * t)
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$ (off resonance)"),
(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.set_xlabel("Time [s]")
ax.set_ylabel("x(t)")
ax.set_title("Undamped forced response: resonance grows without bound")
ax.legend()
plt.show()
Let’s cross-check the resonant case against a direct numerical integration:
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]
sol = solve_ivp(sdof_forced_ode, [0, 60], [0, 0], args=(1.0, 0.0, 1.0, 1.0, 1.0),
t_eval=t, rtol=1e-10, atol=1e-12)
x_analytic = undamped_forced_response(t, wn=1.0, w=1.0, f0=1.0, x0=0.0, v0=0.0)
print("Max abs difference (resonant case):", np.max(np.abs(sol.y[0] - x_analytic)))Max abs difference (resonant case): 1.002926452997599e-08
2.3 On the use of the Laplace transform¶
The Laplace transform turns derivatives into algebra: , .
Exercise “H2” — Laplace transform table (handwritten, verified symbolically)¶
🟥 Fill in the table by hand, then check every entry with sympy.
t_s, s_s, a_s, b_s, n_s = sp.symbols("t s a b n", positive=True)
entries = {
"a": sp.Integer(1) * a_s,
"A*sin(b*t)": sp.sin(b_s * t_s),
"A*cos(b*t)": sp.cos(b_s * t_s),
"t**n": t_s**n_s,
"A*exp(-a*t)": sp.exp(-a_s * t_s),
}
print(f"{'f(t)':<16}{'F(s)':<30}")
for name, f in entries.items():
F = sp.laplace_transform(f, t_s, s_s, noconds=True)
print(f"{name:<16}{sp.simplify(F)}")f(t) F(s)
a a/s
A*sin(b*t) b/(b**2 + s**2)
A*cos(b*t) s/(b**2 + s**2)
t**n s**(-n - 1)*gamma(n + 1)
A*exp(-a*t) 1/(a + s)
Exercise “laplaceEx1” — recovering the particular solution¶
Take the Laplace transform of (zero ICs):
Inverting it should recover .
m_s, k_s, F0_s, w_s = sp.symbols("m k F0 omega", positive=True)
X_s = F0_s * s_s / ((m_s * s_s**2 + k_s) * (s_s**2 + w_s**2))
x_t = sp.inverse_laplace_transform(X_s, s_s, t_s)
sp.simplify(x_t)sympy returns the full transient + steady-state solution (including the free-vibration terms
excited by suddenly switching on the force at ); its steady-state cosine term matches
above once is substituted.
2.4 “Doing physics with MATLAB” — four canonical numerical cases¶
🟩 Reproduce, numerically, four textbook cases (now via solve_ivp rather than a symbolic
Laplace inversion — much more robust for damped/forced systems).
cases = [
dict(name="(1) Free SHM, no damping, no force",
m=1, c=0, k=4, F0=0, w=0, x0=1, v0=0, tmax=20),
dict(name="(2) Driven AT natural frequency, no damping (resonance)",
m=1, c=0, k=4, F0=1, w=2, x0=0, v0=0, tmax=40),
dict(name="(3) Driven AT natural frequency, WITH damping",
m=1, c=0.5, k=4, F0=1, w=2, x0=0, v0=0, tmax=40),
dict(name="(4) Driven far from natural frequency, WITH damping",
m=1, c=0.5, k=4, F0=1, w=3, x0=0, v0=0, tmax=40),
]
fig, axes = plt.subplots(len(cases), 1, figsize=(7, 12), sharex=False)
for ax, case in zip(axes, cases):
t_eval = np.linspace(0, case["tmax"], 4000)
sol = solve_ivp(sdof_forced_ode, [0, case["tmax"]], [case["x0"], case["v0"]],
args=(case["m"], case["c"], case["k"], case["F0"], case["w"]),
t_eval=t_eval, rtol=1e-9, atol=1e-11)
ax.plot(t_eval, sol.y[0])
ax.set_title(case["name"], fontsize=10)
ax.set_ylabel("x(t)")
plt.tight_layout()
plt.show()
Comments:
Pure SHM: constant-amplitude cosine at rad/s — no dissipation, no input.
Undamped resonance: linearly growing envelope — physically unrealistic forever, but this is exactly the mechanism that destroys lightly-damped structures excited near .
Damped resonance: the envelope grows only until it saturates at the steady-state resonant amplitude — damping is what saves real structures.
Off-resonance with damping: the transient dies out and the system settles into a modest-amplitude steady-state oscillation at the forcing frequency .