summaryrefslogtreecommitdiff
path: root/examples/lie.hs
diff options
context:
space:
mode:
authorAlberto Ruiz <aruiz@um.es>2014-05-21 10:30:55 +0200
committerAlberto Ruiz <aruiz@um.es>2014-05-21 10:30:55 +0200
commit197e88c3b56d28840217010a2871c6ea3a4dd1a4 (patch)
tree825be9d6c9d87d23f7e5497c0133d11d52c63535 /examples/lie.hs
parente07c3dee7235496b71a89233106d93f6cc94ada1 (diff)
update dependencies, move examples etc
Diffstat (limited to 'examples/lie.hs')
-rw-r--r--examples/lie.hs65
1 files changed, 65 insertions, 0 deletions
diff --git a/examples/lie.hs b/examples/lie.hs
new file mode 100644
index 0000000..db21ea8
--- /dev/null
+++ b/examples/lie.hs
@@ -0,0 +1,65 @@
1-- The magic of Lie Algebra
2
3import Numeric.LinearAlgebra
4
5disp = putStrLn . dispf 5
6
7rot1 :: Double -> Matrix Double
8rot1 a = (3><3)
9 [ 1, 0, 0
10 , 0, c, s
11 , 0,-s, c ]
12 where c = cos a
13 s = sin a
14
15g1,g2,g3 :: Matrix Double
16
17g1 = (3><3) [0, 0,0
18 ,0, 0,1
19 ,0,-1,0]
20
21rot2 :: Double -> Matrix Double
22rot2 a = (3><3)
23 [ c, 0, s
24 , 0, 1, 0
25 ,-s, 0, c ]
26 where c = cos a
27 s = sin a
28
29g2 = (3><3) [ 0,0,1
30 , 0,0,0
31 ,-1,0,0]
32
33rot3 :: Double -> Matrix Double
34rot3 a = (3><3)
35 [ c, s, 0
36 ,-s, c, 0
37 , 0, 0, 1 ]
38 where c = cos a
39 s = sin a
40
41g3 = (3><3) [ 0,1,0
42 ,-1,0,0
43 , 0,0,0]
44
45deg=pi/180
46
47-- commutator
48infix 8 &
49a & b = a <> b - b <> a
50
51infixl 6 |+|
52a |+| b = a + b + a&b /2 + (a-b)&(a & b) /12
53
54main = do
55 let a = 45*deg
56 b = 50*deg
57 c = -30*deg
58 exact = rot3 a <> rot1 b <> rot2 c
59 lie = scalar a * g3 |+| scalar b * g1 |+| scalar c * g2
60 putStrLn "position in the tangent space:"
61 disp lie
62 putStrLn "exponential map back to the group (2 terms):"
63 disp (expm lie)
64 putStrLn "exact position:"
65 disp exact