egison-3.7.8: sample/math/geometry/polar-laplacian-2d-3.egi
;;;
;;; Polar coordinates
;;;
(define $x [|r θ|])
(define $X [|(* r (cos θ)) ; = x
(* r (sin θ)) ; = y
|])
;;
;; Local coordinates
;;
(define $e ((∂/∂ X~# $) x_#))
e
;[| [| (cos θ) (sin θ) |] [| (* -1 r (sin θ)) (* r (cos θ)) |] |]
;;
;; Metric tensor
;;
(define $g__ (generate-tensor 2#(V.* e_%1 e_%2) {2 2}))
(define $g~~ (with-symbols {i j} (/ (unit-tensor {2 2})_i_j g_i_j)))
g_#_#;[| [| 1 0 |] [| 0 r^2 |] |]_#_#
g~#~#;[| [| 1 0 |] [| 0 (/ 1 r^2) |] |]~#~#
;;
;; Derive Laplacian
;;
(define $sqrt-g (sqrt (M.det g_#_#)))
sqrt-g;r
(define $Laplacian (/ (contract + (∂/∂ (* sqrt-g (. g~i~j (∂/∂ (f r θ) x_j))) x_i)) sqrt-g))
Laplacian
;(/ (+ (* (f|1 r θ) r) (* r^2 (f|1|1 r θ)) (f|2|2 r θ)) r^2)