🟩 Code exercise. Complete every # TODO cell below during the lesson. The fully worked
solution is in 01_SDOF_FreeVibration.ipynb — try not to peek until you’re done!
Recall the free-vibration EoM , with , , and the three regimes:
Overdamped ():
Critically damped ():
Underdamped (): ,

import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import solve_ivp
import sympy as sp
plt.rcParams["figure.figsize"] = (7, 4.2)
plt.rcParams["axes.grid"] = TrueExercise 1 — implement sdof_free_response¶
🟩 Complete the function below so that it returns the analytic free response for any value of (handle the three cases explicitly), given , , , , .
def sdof_free_response(t, m, c, k, x0, v0):
"""Analytic free response of m*x'' + c*x' + k*x = 0. Complete the three branches below."""
wn = np.sqrt(k / m)
zeta = c / (2 * np.sqrt(k * m))
delta = zeta**2 - 1
if zeta > 1: # overdamped
s1 = ... # TODO
s2 = ... # TODO
A = ... # TODO: use x0, v0, s1, s2
B = ... # TODO
x = ... # TODO
elif np.isclose(zeta, 1.0): # critically damped
A = ... # TODO
B = ... # TODO
x = ... # TODO
else: # underdamped
wd = ... # TODO
C = ... # TODO
D = ... # TODO
x = ... # TODO
return xExercise 2 — plot the three damping regimes¶
🟩 Using , , , , plot the free response for on the same axes, ,s.
m, k = 1.0, 1.0
x0, v0 = 1.0, 0.0
t = np.linspace(0, 20, 1000)
wn = np.sqrt(k / m)
fig, ax = plt.subplots()
for zeta, label in [(0.05, r"underdamped, $\zeta=0.05$"),
(0.3, r"underdamped, $\zeta=0.3$"),
(1.0, r"critically damped, $\zeta=1$"),
(1.8, r"overdamped, $\zeta=1.8$")]:
c = ... # TODO: relate c to zeta, k, m
x = ... # TODO: call sdof_free_response
ax.plot(t, x, label=label)
ax.axhline(0, color="k", lw=0.6)
ax.set_xlabel("Time [s]")
ax.set_ylabel("x(t)")
ax.set_title("SDOF free response for the three damping regimes")
ax.legend()
plt.show()Exercise 3 — cross-check with numerical integration¶
🟩 Write the state-space right-hand side sdof_ode(t, y, m, c, k) with and
integrate it with solve_ivp for . Compare with the analytic solution on the same
plot.
def sdof_ode(t, y, m, c, k):
x, v = y
xdot = ... # TODO
vdot = ... # TODO
return [xdot, vdot]
zeta = 0.1
c = 2 * zeta * np.sqrt(k * m)
sol = ... # TODO: solve_ivp(...)
x_analytic = sdof_free_response(t, m, c, k, x0, v0)
fig, ax = plt.subplots()
ax.plot(t, x_analytic, label="Analytic")
# TODO: plot sol.y[0] vs t as a dashed line labeled "solve_ivp (numerical)"
ax.set_xlabel("Time [s]")
ax.set_ylabel("x(t)")
ax.legend()
plt.show()Exercise 4 — symbolic check (the “Ex0” review)¶
🟥 Handwritten / symbolic exercise. Use sympy.dsolve to solve
symbolically with initial conditions ,
, and compare the structure of the result with your hand derivation.
t_sym, m_s, c_s, k_s, x0_s, v0_s = sp.symbols("t m c k x0 v0")
x = sp.Function("x")
ode = ... # TODO: sp.Eq(...)
sol_sym = ... # TODO: sp.dsolve(...)
sol_symHomework 1 (blue box)¶
🟦 Homework.
Make sure the symbolic review above runs and matches your hand derivation.
Derive the logarithmic decrement for an underdamped system, show that , and invert it to estimate from two successive measured peaks.
Code it: for , generate the free response, locate two successive peaks one damped period apart, compute numerically, and recover an estimate of . Check it matches .
zeta_true = 0.05
c = 2 * zeta_true * np.sqrt(k * m)
wd = ... # TODO
Td = ... # TODO
t_fine = np.linspace(0, 20, 20000)
x_fine = sdof_free_response(t_fine, m, c, k, x0=1.0, v0=0.0)
# TODO: find the index of the first peak i1 (t < Td) and the index i2 nearest to t1+Td
i1 = ...
t1 = t_fine[i1]
i2 = ...
delta_log = ... # TODO
zeta_est = ... # TODO
print(f"True zeta = {zeta_true:.4f}")
print(f"Log decrement = {delta_log:.4f}")
print(f"Estimated zeta = {zeta_est:.4f}")