from IPython.display import Image
import numpy as np
from scipy import linalg as LA
import sympy as sp
import math
Image(filename='two_springs_two_masses.png')
# Construct mass matrix
m = 20
m1 = m
m2 = 2 * m
mMatrix = np.array([[m1, 0], [0, m2]])
mMatrix
# Construct spring stiffness matrix
k = 1000
k1 = k
k2 = 2 * k
kMatrix = np.array([[k1 + k2, -k2], [-k2, k2]])
kMatrix
# Find the eigenvalues and eigenvactors
values, vectors = LA.eig(a = kMatrix, b = mMatrix)
vectors = vectors.T
vectors = np.array([[vectors[0,0] / vectors[0, 1] , 1.0], [vectors[1,0] / vectors[1, 1], 1.0]])
values, vectors
# Ordering by the magnitude of frequency
arg = np.argsort(values)
values = np.array(values)[arg]
vectors = np.array(vectors)[arg]
values, vectors
# Natural frequency
natural_frequencies = np.sqrt(values)
natural_frequencies
# Check for orthogonality with respect to M
a = np.dot(np.dot(vectors, mMatrix), vectors.T)
a
# Drop small off-diagonal terms to make the mode normalization easier
indexes = a < 10e-8
a[indexes] = 0
a
# Construct Normal Modal Matrix
phi = np.dot(vectors.T, LA.inv(np.sqrt(a)))
phi
# Initial condition in principal corrdinates
y0 = np.dot(phi.T, np.dot(mMatrix, np.array([1, -1])))
y0
# Response in principal coordinates
t = sp.Symbol('t')
y = y0 * np.array([sp.cos(natural_frequencies[0] * t), sp.cos(natural_frequencies[1] * t)])
y
# Response in x corrdinates
x = np.dot(phi, y)
x