# Ex 1.20 Sliding pendulum

Structure and Interpretation of Classical Mechanics

.

Consider a pendulum of length $l$ attached to a support that is free to move horizontally, as shown in figure 1.4. Let the mass of the support be $m_1$ and the mass of the pendulum be $m_2$. Formulate a Lagrangian and derive Lagrange’s equations for this system.

~~~

[guess]

```
(define ((F->C F) local)
(->local (time local)
(F local)
(+ (((partial 0) F) local)
(* (((partial 1) F) local)
(velocity local)))))

;

(define ((q->r l y1) local)
(let ((q (coordinate local)))
(let ((x1 (ref q 0))
(theta (ref q 1)))
(let ((x2 (+ x1 (* l (sin theta))))
(y2 (- y1 (* l (cos theta)))))
(up x1 y1 x2 y2)))))

(show-expression
((q->r 'l 'y_1)
(up 't
(up 'x_1 'theta)

;

(define (KE m vx vy)
(* 1/2 m (+ (square vx) (square vy))))

(define ((T-rect m1 m2) local)
(let ((q (coordinate local))
(v (velocity local)))
(let ((x1dot (ref v 0))
(y1dot (ref v 1))
(x2dot (ref v 2))
(y2dot (ref v 3)))
(+ (KE m1 x1dot y1dot)
(KE m2 x2dot y2dot)))))

(show-expression
((T-rect 'm_1 'm_2)
(up 't
(up 'x_1 'y_1 'x_2 'y_2)
(up 'xdot_1 'ydot_1 'xdot_2 'ydot_2))))

;

(define ((U-rect g m1 m2) local)
(let* ((q (coordinate local))
(y1 (ref q 1))
(y2 (ref q 3)))
(* g (+ (* m1 y1)
(* m2 y2)))))

(show-expression
((U-rect 'g 'm_1 'm_2)
(up 't
(up 'x_1 'y_1 'x_2 'y_2)
(up 'xdot_1 'ydot_1 'xdot_2 'ydot_2))))

;

(define (L-rect g m1 m2)
(- (T-rect m1 m2) (U-rect g m1 m2)))

(show-expression
((L-rect 'g 'm_1 'm_2)
(up 't
(up 'x_1 'y_1 'x_2 'y_2)
(up 'xdot_1 'ydot_1 'xdot_2 'ydot_2))))

;

(define (L-l l y1 g m_1 m_2)
(compose
(L-rect g m_1 m_2) (F->C (q->r l y1))))

(show-expression
((L-l 'l 'y_1 'g 'm_1 'm_2)
(->local 't
(up 'x_1 'theta)

;

(show-expression
(((Lagrange-equations
(L-l 'l 'y_1 'g 'm_1 'm_2))
(up
(literal-function 'x_1)
(literal-function 'theta)))
't))

;

```

[guess]

— Me@2021-03-26 08:22:01 PM

.

.