summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/lie.hs66
1 files changed, 66 insertions, 0 deletions
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 @@
1-- The magic of Lie Algebra
2
3import Numeric.LinearAlgebra
4import Text.Printf(printf)
5
6disp = putStrLn . format " " (printf "%.5f")
7
8rot1 :: Double -> Matrix Double
9rot1 a = (3><3)
10 [ 1, 0, 0
11 , 0, c, s
12 , 0,-s, c ]
13 where c = cos a
14 s = sin a
15
16g1,g2,g3 :: Matrix Double
17
18g1 = (3><3) [0, 0,0
19 ,0, 0,1
20 ,0,-1,0]
21
22rot2 :: Double -> Matrix Double
23rot2 a = (3><3)
24 [ c, 0, s
25 , 0, 1, 0
26 ,-s, 0, c ]
27 where c = cos a
28 s = sin a
29
30g2 = (3><3) [ 0,0,1
31 , 0,0,0
32 ,-1,0,0]
33
34rot3 :: Double -> Matrix Double
35rot3 a = (3><3)
36 [ c, s, 0
37 ,-s, c, 0
38 , 0, 0, 1 ]
39 where c = cos a
40 s = sin a
41
42g3 = (3><3) [ 0,1,0
43 ,-1,0,0
44 , 0,0,0]
45
46deg=pi/180
47
48-- commutator
49infix 8 &
50a & b = a <> b - b <> a
51
52infixl 6 |+|
53a |+| b = a + b + a & b */2 + (a-b) & (a & b) */12
54
55main = do
56 let a = 45*deg
57 b = 50*deg
58 c = -30*deg
59 exact = rot3 a <> rot1 b <> rot2 c
60 lie = a.*g3 |+| b.*g1 |+| c.*g2
61 putStrLn "position in the tangent space:"
62 disp lie
63 putStrLn "exponential map back to the group (2 terms):"
64 disp (expm lie)
65 putStrLn "exact position:"
66 disp exact