<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 2 DOF System
<img src="figures/struct01_conv.svg" alt="Dynamic System" style="width
Step1:  The eigenvalues problem
Step2:  Mass Displacements and Inertial Forces
We downgrade the  hinge in $\mathcal B$ to permit a unit horizontal displacement and observe that the centre of instantaneous rotation for the lower beam is at the intersection of the vertical in $\mathcal B$ and the line connecting $\mathcal A$ and $\mathcal C$.
<img src="figures/struct03_conv.svg" alt="Dynamic System" style="width
Step3:  Initialization
<ASSISTANT_TASK:>
Python Code:
l = [1, 1, 1, 2, 1]
m = [[p( 2/3, 0), p(-1/3, 1), p(1, 0), p(2/3, 0), p(4/3, 0)],
     [p(-2/3, 0), p(-2/3, 0), p(0, 0), p(1/3, 0), p(2/3, 0)]]
F = array([[vw(emme, chi, l) for emme in m] for chi in m])
K = inv(F)
M = eye(2)
dl(dmat(r'\boldsymbol{F}=\frac{1}{27}\frac{L^3}{EJ}', F*27, r','))
dl(dmat(r'\boldsymbol{K}=\frac{1}{53}\frac{EJ}{L^3}', K*53, r','))
dl(dmat(r'\boldsymbol{M}=m', M,'.', fmt='%d'))
Explanation: 2 DOF System
<img src="figures/struct01_conv.svg" alt="Dynamic System" style="width: 67%;"/>
The dynamical system in figure is composed of two massless, uniform beams
supporting a dimensionless body of mass $m$.
With $\omega_0^2=(EJ)/(mL^3)$ determine the system's eigenvalues
$\omega_i^2=\lambda_i^2\,\omega_0^2$ and the mass normalized eigenvectors.
The system is subjected to a horizontal motion $u_\mathcal{B}= u_\mathcal{B}(t)$,
determine the mass displacements 
$\boldsymbol x_\mathcal{B} = \boldsymbol r\,u_\mathcal{B}$ and write the modal equations of dynamic equilibrium as
$$\ddot q_i + \lambda_i^2\omega_0^2\,q_i = \alpha_i\,\ddot u_\mathcal{B}$$
determining the numerical values of the $\alpha_i$.
Structural matrices
The flexibility is computed using the Principle of Virtual Displacements, the stiffness is computed by inversion and the mass matrix is the unit matrix multiplied by $m$, $\ \boldsymbol M=m\,\boldsymbol I$.
<img src="figures/struct02_conv.svg" alt="Dynamic System" style="width: 67%;"/>
End of explanation
wn2, Psi = eigh(K, M) ; Psi[:,0] *= -1
Lambda2 = diag(wn2)
dl(dmat(r'\boldsymbol{\Lambda^2}=', Lambda2, r'.'))
dl(dmat(r'\boldsymbol{\Psi}=', Psi,  r'.'))
Explanation: The eigenvalues problem
End of explanation
r = array((2/3, 1/3))
a = -Psi.T@r
print('The modal equations of motion are')
for i, (ai, l2i) in enumerate(zip(a, wn2), 1):
    dl(r'$$\ddot q_{%d} %+.6f\,\omega_0^2\,q_{%d} = %+.6f\,\ddot u_\mathcal{B}$$' %
        (i, l2i, i, ai))
Explanation: Mass Displacements and Inertial Forces
We downgrade the  hinge in $\mathcal B$ to permit a unit horizontal displacement and observe that the centre of instantaneous rotation for the lower beam is at the intersection of the vertical in $\mathcal B$ and the line connecting $\mathcal A$ and $\mathcal C$.
<img src="figures/struct03_conv.svg" alt="Dynamic System" style="width: 67%;"/>
The angle of rotation of the lower beam is $\theta_2=1/3L$, anti-clockwise and the angle of rotation of the upper beam (that rotates about the hinge in $\mathcal A$) is equal but clockwise, due to the continuity of displacements in the internal hinge $\mathcal C$.
Knowing the angle of rotation of the upper beam, the mass displacements are
$$ x_1 = 2L\frac{1}{3L}=\frac{2}{3}\quad
\text{ and }\quad x_2=L\frac{1}{3L}=\frac{1}{3}.$$
We can eventually write
$$ \boldsymbol x_\text{tot} = \boldsymbol x + \begin{Bmatrix}
   2/3\1/3 \end{Bmatrix}\,u_\mathcal{B}$$
and the inertial force can be written as
$$\boldsymbol f_\text{I} =
\boldsymbol M \, \ddot{\boldsymbol x}\text{tot} =
\boldsymbol M \, \ddot{\boldsymbol x} +
\boldsymbol M \, \begin{Bmatrix}2/3\1/3\end{Bmatrix}\,\ddot u\mathcal{B}
$$
The Modal Equations of Motion
The equation of motion, in structural coordinates, is
$$
\boldsymbol M \, \ddot{\boldsymbol x} +
\boldsymbol K \, \boldsymbol x = 
- \boldsymbol M \, \begin{Bmatrix}2/3\1/3\end{Bmatrix}\,\ddot u_\mathcal{B}
$$
or, because $\boldsymbol M = m\, \boldsymbol I$,
$$
\boldsymbol M \, \ddot{\boldsymbol x} +
\boldsymbol K \, \boldsymbol x = 
- m\, \begin{Bmatrix}2/3\1/3\end{Bmatrix}\,\ddot u_\mathcal{B}
$$
Using the modal expansion, $\boldsymbol x = \boldsymbol\Psi\, \boldsymbol q$ and premultiplying  term by term by $\boldsymbol\Psi^T$ we have, because the eigenvectors are normalized w/r to the mass matrix,
$$
m\,\boldsymbol I \, \ddot{\boldsymbol q} + m\omega_0^2\,
\boldsymbol \Lambda^2 \, \boldsymbol q = 
- m\,\boldsymbol\Psi^T\, \begin{Bmatrix}2/3\1/3\end{Bmatrix}\,\ddot u_\mathcal{B}.
$$
End of explanation
from numpy import array, diag, eye, poly1d
from scipy.linalg import eigh, inv
from IPython.display import Latex, HTML
display(HTML(open('01.css').read()))
def p(*l): return poly1d(l)
def vw(M, Χ, L):
    return sum(p(l)-p(0) for (m, χ, l) in zip(M, Χ, L) for p in ((m*χ).integ(),))
def dmat(pre, mat, post, mattype='b', fmt='%+.6g'):
    s = r'\begin{align}' + pre + r'\begin{%smatrix}'%mattype
    s += r'\\'.join('&'.join(fmt%val for val in row) for row in mat)
    s += r'\end{%smatrix}'%mattype + post + r'\end{align}'
    return s
def dl(ls): 
    display(Latex(ls))
    return None
Explanation: Initialization
End of explanation
<END_TASK>