REZZE.NET

SICM Exercise 1.13

Solution to exercise 1.13 of Structure and Interpretation of Classical Mechanics by Gerald Jay Sussman and Jack Wisdom.

Higher-derivative Lagrangians

🛈 Note

Write a procedure to compute the Lagrange equations for Lagrangians that depend upon acceleration, as in exercise 1.10. Note that Gamma can take an optional argument giving the length of the initial segment of the local tuple needed. The default length is 3, giving components of the local tuple up to and including the velocities.

(define ((Lagrange-equations-acc Lagrangian) q)
  (let* ((part1 (compose ((partial 1) Lagrangian) (Gamma q 4)))
         (part2 (compose ((partial 2) Lagrangian) (Gamma q 4)))
         (part3 (compose ((partial 3) Lagrangian) (Gamma q 4)))
         (D2part3 ((square D) part3))
         (Dpart2 (D part2)))
    (+ D2part3 (- Dpart2) part1)))

(define ((Lagrange-equations-n Lagrangian n) q)
  (define (Lagrange-equations-iter sum i)
    (let* ((sign (if (eq? (modulo i 2) 0) -1 1))
           (next (* sign
                    ((expt D (- i 1))
                     (compose ((partial i) Lagrangian) (Gamma q n))))))
      (if (> i 1)
          (Lagrange-equations-iter (+ sum next) (- i 1))
          sum)))
    
  (Lagrange-equations-iter (compose ((partial 1) Lagrangian) (Gamma q n))
                           (- n 1)))
  
(define ((L-spring m k) local)
  (let* ((x (coordinate local))
         (a (acceleration local)))
    (- (* -1/2 m x a)
       (* 1/2 k (square x)))))
  
(show-expression
 (((Lagrange-equations-acc (L-spring 'm 'k))
   (literal-function 'x))
  't))
  
(show-expression
 (((Lagrange-equations-n (L-spring 'm 'k) 4)
   (literal-function 'x))
  't))
Tags:
Authors: