🟩 Complete every # TODO. Solution: 05_MDOF_EigenProblem_ModalAnalysis.ipynb.
import numpy as np
import matplotlib.pyplot as plt
from scipy.linalg import eigh
from scipy.integrate import solve_ivp
plt.rcParams["figure.figsize"] = (7, 4.2)
plt.rcParams["axes.grid"] = True
np.set_printoptions(precision=4, suppress=True)Exercise (handwritten) — 3-step approach¶
🟥 (1) Solve . (2) Solve with . (3) Physically sort the natural frequencies with their mode shapes.
Exercise “EX4” — solve the eigenproblem¶
🟩 For , build , and complete eigsort using
scipy.linalg.eigh(K, M), sorted by ascending frequency.
M = np.array([[5.0, 0.0], [0.0, 10.0]])
K = np.array([[4.0, -2.0], [-2.0, 6.0]])
def eigsort(K, M):
lam, U = ... # TODO
order = ... # TODO
lam, U = lam[order], U[:, order]
wn = ... # TODO
return U, wn
U, wn = eigsort(K, M)
print("Natural frequencies (rad/s):", wn)
print("Mode shapes:\n", U)Exercise “EX4B” — verify orthogonality, compute modal mass/stiffness¶
🟩 Verify and compute modal mass and modal stiffness ; check .
u1, u2 = U[:, 0], U[:, 1]
is_it_zero = ... # TODO
m1_modal, m2_modal = ..., ... # TODO
k1_modal, k2_modal = ..., ... # TODO
print(is_it_zero, m1_modal, m2_modal, k1_modal, k2_modal)Exercise “EX4C” — modal matrix¶
🟩 Build and verify and are both diagonal.
P = ... # TODO
print(P.T @ M @ P)
print(P.T @ K @ P)Exercise “EX4D” — modal response to initial conditions¶
🟩 For , : compute , , propagate each uncoupled SHM , then recover . Cross-check against a direct numerical integration of the coupled system.
x0 = np.array([1.0, 1.0])
xdot0 = np.array([0.0, 0.0])
q0 = ... # TODO
qdot0 = ... # TODO
t = np.arange(0, 100.1, 0.1)
q1 = ... # TODO
q2 = ... # TODO
q = np.vstack([q1, q2])
x = P @ q
# TODO: plot x[0], x[1] vs t
def mdof_free_ode(t, y, M, K):
n = M.shape[0]
x, v = y[:n], y[n:]
a = ... # TODO
return np.concatenate([v, a])
sol = ... # TODO: solve_ivp(...)
# TODO: print max abs difference between modal and numerical solutionsExercise “EX4E” — proportional damping & forced modal response¶
🟩 For , : build , get the modal quantities, and derive (mass-normalized modes). For , build the steady-state modal solution , , with , then recover . Cross-check against direct numerical integration of the full damped, coupled system (they should match once the transient dies out).
M = np.diag([9.0, 1.0])
K = np.array([[27.0, -3.0], [-3.0, 3.0]])
alpha, beta = 0.0, 0.1
C = ... # TODO
U, wn = eigsort(K, M)
P = U
Mm = ... # TODO
Cm = ... # TODO
Km = ... # TODO
zeta = ... # TODO
print(zeta)
Omega, F2amp = 2.0, 3.0
f_amp = np.array([0.0, F2amp])
N_amp = ... # TODO
t = np.linspace(0, 60, 6000)
q_ss = np.zeros((2, len(t)))
for i in range(2):
denom = ... # TODO
Qamp = ... # TODO
phi = ... # TODO
q_ss[i] = Qamp * np.cos(Omega * t - phi)
x_ss = P @ q_ss
def mdof_forced_ode(t, y, M, C, K, f_amp, Omega):
n = M.shape[0]
x, v = y[:n], y[n:]
f = ... # TODO
a = ... # TODO
return np.concatenate([v, a])
sol = ... # TODO
# TODO: plot x_ss[0] vs sol.y[0] and print the max abs difference for t>40