The two-bar linkage shown in the figure below is constrained to move in the plane. It is composed of three small massive bodies interconnected by two massless rigid rods in a uniform gravitational field with vertical acceleration g. The rods are pinned to the central body by a hinge that allows the linkage to fold. The system is arranged so that the hinge is completely free: the members can go through all configurations without collision. Formulate a Lagrangian that describes the system and find the Lagrange equations of motion. Use the computer to do this, because the equations are rather big.

Figure 1.3

Use three sets of rectangular coordinates, one for each body. The generalized coordinates could be represented by the position of $m_2$ and two angles, $\theta_1$ and $\theta_3$, positive CCW and measured from the X axis.

\begin{align*} x_1(t) &= x + l_1\cos\theta_1 \\ x_1(t) &= y + l_1\sin\theta_1 \\ x_2(t) &= x\\ y_2(t) &= y\\ x_3(t) &= x + l_1\cos\theta_3 \\ x_3(t) &= y + l_1\sin\theta_3 \\ \end{align*}
(defn twobar-linkage->rect [l_1 l_2]
(fn [[_ [x y theta_1 theta_3] _]]
(up (+ x (* l_1 (cos theta_1)))
(+ y (* l_1 (sin theta_1)))
x
y
(+ x (* l_2 (cos theta_3)))
(+ y (* l_2 (sin theta_3)))
)))

(defn L-const-accel-three-bodies [m_1 m_2 m_3 g]
(fn [[_  [x_1 y_1 x_2 y_2 x_3 y_3] [v_x1 v_y1 v_x2 v_y2 v_x3 v_y3]]]
(let [T1 (* 1/2 (* m_1 (+ (square v_x1) (square v_y1))))
T2 (* 1/2 (* m_2 (+ (square v_x2) (square v_y2))))
T3 (* 1/2 (* m_3 (+ (square v_x3) (square v_y3))))
T (+ T1 T2 T3)
V1 (* m_1 g y_1)
V2 (* m_2 g y_2)
V3 (* m_3 g y_3)
V (+ V1 V2 V3)]
(- T V))))

(defn L-twobar-linkage [m_1 m_2 m_3 g l_1 l_2]
(fn [q-prime]
((compose (L-const-accel-three-bodies m_1 m_2 m_3 g) (F->C (twobar-linkage->rect l_1 l_2)))
q-prime)))