From 29b9a4adfdcd624ecb1f67b7fba5830fa76260c9 Mon Sep 17 00:00:00 2001 From: Alberto Ruiz Date: Sat, 27 Oct 2007 19:25:17 +0000 Subject: Lie algebra example --- examples/lie.hs | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 examples/lie.hs diff --git a/examples/lie.hs b/examples/lie.hs new file mode 100644 index 0000000..87f7ed1 --- /dev/null +++ b/examples/lie.hs @@ -0,0 +1,66 @@ +-- The magic of Lie Algebra + +import Numeric.LinearAlgebra +import Text.Printf(printf) + +disp = putStrLn . format " " (printf "%.5f") + +rot1 :: Double -> Matrix Double +rot1 a = (3><3) + [ 1, 0, 0 + , 0, c, s + , 0,-s, c ] + where c = cos a + s = sin a + +g1,g2,g3 :: Matrix Double + +g1 = (3><3) [0, 0,0 + ,0, 0,1 + ,0,-1,0] + +rot2 :: Double -> Matrix Double +rot2 a = (3><3) + [ c, 0, s + , 0, 1, 0 + ,-s, 0, c ] + where c = cos a + s = sin a + +g2 = (3><3) [ 0,0,1 + , 0,0,0 + ,-1,0,0] + +rot3 :: Double -> Matrix Double +rot3 a = (3><3) + [ c, s, 0 + ,-s, c, 0 + , 0, 0, 1 ] + where c = cos a + s = sin a + +g3 = (3><3) [ 0,1,0 + ,-1,0,0 + , 0,0,0] + +deg=pi/180 + +-- commutator +infix 8 & +a & b = a <> b - b <> a + +infixl 6 |+| +a |+| b = a + b + a & b */2 + (a-b) & (a & b) */12 + +main = do + let a = 45*deg + b = 50*deg + c = -30*deg + exact = rot3 a <> rot1 b <> rot2 c + lie = a.*g3 |+| b.*g1 |+| c.*g2 + putStrLn "position in the tangent space:" + disp lie + putStrLn "exponential map back to the group (2 terms):" + disp (expm lie) + putStrLn "exact position:" + disp exact -- cgit v1.2.3