aboutsummaryrefslogtreecommitdiffstats
path: root/chapters/1-Introduction.scm
blob: 38beba848719817f9de77dbf7daaefa599fe0e0b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103

(define ((Lfree mass) state)
  (* 1/2 mass (square (velocity state))))

; geometric transform of spherical coordinates to 3D coordinates
; 'R' is radius
(define ((sphere->R3 R) state)
  (let ((q (coordinate state)))
    (let ((theta (ref q 0))
          (phi (ref q 1)))
      (up (* R (sin theta) (cos phi))   ; x
          (* R (sin theta) (sin phi))   ; y
          (* R (cos theta))))))         ; z

; apply a coordinate transform to a function over states (?)
(define ((F->C F) state)
  (up (time state)
      (F state)
      (+ (((partial 0) F) state)
         (* (((partial 1) F) state)
            (velocity state)))))

(define (Lsphere m R)
  (compose (Lfree m) (F->C (sphere->R3 R))))

((Lsphere 'm 'R)
 (up 't (up 'theta 'phi) (up 'thetadot 'phidot)))
; (+ (* 1/2 (expt R 2) m (expt phidot 2) (expt (sin theta) 2)) (* 1/2 (expt R 2) m (expt thetadot 2)))
; -> 1/2 m R^2 phidot^2 sin(theta)^2 + 1/2 R^2 m thetadot^2
; -> 1/2 m R^2 ( phidot^2 sin(theta)^2 + thetadot^2 )

; this is kinetic energy of a particle on a sphere in spherical coordinates, as expected

(define ((L2 mass metric) place velocity)
  (* 1/2 mass ((metric velocity velocity) place)))


; (metric velocity velocity) here is the magniture of velocity ("weighted sum of squares")
; 'Lc' is "Lagrangian in coordinate representation"
(define ((Lc mass metric coordsys) state)
  (let ((x (coordinates state))
        (v (velocities state))
        (e (coordinate-system->vector-basis coordsys)))
    ((L2 mass metric) ((point coordsys) x) (* e v))))

(define the-metric (literal-metric 'g R2-rect))

(define L (Lc 'm the-metric R2-rect))

(L (up 't (up 'x 'y) (up 'vx 'vy)))
; (+ (* 1/2 m (expt vx 2) (g_00 (up x y)))
;    (* m vx vy           (g_01 (up x y)))
;    (* 1/2 m (expt vy 2) (g_11 (up x y))))

; same as 1.3, assuming g_01 and g_10 are the same (?)

; going to define a path on a 2D manifold

(define gamma (literal-manifold-map 'q R1-rect R2-rect))

; ahhh!
; ``((point R1-rect 't))` creates a point on the real like (R1-rect), based on coordinate 't.
;  `((chart R2-rect) m)` takes a point m and returns coordinates

((chart R2-rect) (gamma ((point R1-rect) 't)))
; (up (q^0 t) (q^1 t))

(define coordinate-path
  (compose (chart R2-rect) gamma (point R1-rect)))

(coordinate-path 't)
; (up (q^0 t) (q^1 t))

(define Lagrange-residuals
  (((Lagrange-equations L) coordinate-path) 't))

Lagrange-residuals
; big mess

(define-coordinates t R1-rect)

(define Cartan
  (Christoffel->Cartan
    (metric->Christoffel-2 the-metric
                           (coordinate-system->basis R2-rect))))

(define geodesic-equation-residuals
  (((((covariant-derivative Cartan gamma) d/dt)
     ((differential gamma) d/dt))
    (chart R2-rect))
   ((point R1-rect) 't)))

(define metric-components
  (metric->components the-metric
                      (coordinate-system->basis R2-rect)))

(- Lagrange-residuals
   (* (* 'm (metric-components (gamma ((point R1-rect) 't))))
      geodesic-equation-residuals))
; (down 0 0)

; so the Lagrange equations correspond to the Christoffel coefficients