+Parentheses work again.
[lineal.git] / doc / doing_math.txt
blob70ab5ecf51164c7d65e0d0489979639e9dda7714
1                                                  NEXT: concatenating.txt
3 How to actually do math.
5 So, you want to do math, eh?
7 Assuming you know how to create a vector or matrix,
8 let's say you initialize the following variables:
11      [1 2]
12  A = [3 4]
14      [3 4]
15  B = [2 5]
17  u = (1, 2, 3)
19  v = (1, 1, 1)
22 The format for the following examples is...
24  [infix expression]
26                 [prefix expression]
28  ==>  [result]
30 [explaination]
32 ------------------------------------------------------------------------
34  A*B  or  A B
36                 (* A B)
38       [ 7 14]
39  ==>  [17 32]
41 Multiply matrices /A/ and /B/.
42 Yes, hit the not-asterisk button to get the asterisk.
43 You can also just manually type it.
45 ------------------------------------------------------------------------
47  det B
48                 (det B)
50  ==>  7
52 Determinant
54 ------------------------------------------------------------------------
56  transpose A
57                 (transpose A)
59       [1 3]
60  ==>  [2 4]
62 Transpose matrix /A/.
64 ------------------------------------------------------------------------
66  inverse B
67                 (inverse B)
69       [ 5/7 -4/7]
70  ==>  [-2/7  3/7]
72 Matrix /B/'s determinant isn't zero so the inverse is valid.
73 The inverse function does not check if an inverse actually exists.
75 ------------------------------------------------------------------------
77  B * inverse B
79                 (* B (inverse B))
81       [1 0]
82  ==>  [0 1]
84 Of course the identity matrix is returned,
85 that's the definition of inverse.
87 ------------------------------------------------------------------------
89  store("I", B inverse B)
91                 (store "I" (* B (inverse B)))
93      [1 0]
94  ==> [0 1]
96 The identity matrix we got from the previous operation is stored in the
97 variable /I/.
99 ------------------------------------------------------------------------
101  store("n", 3*2)
103                 (store "n" (* 3 2))
105  ==>  6
107 You can also use the store function to store regular numbers.
109 ------------------------------------------------------------------------
111  5 * I * 1 * 3/5
113                 (* 5 I 1 3/5)
115       [3 0]
116  ==>  [0 3]
118 Scalar-matrix multiplication is perfectly legal.
119 Also, multiplication takes as many arguments as you want.
121 ------------------------------------------------------------------------
123  A + -B
124                 (+ A (- B)) 
126       [-2 -2]
127  ==>  [ 1 -1]
129 When only one term is applied to the subtraction function, it is
130 negated.
132 ------------------------------------------------------------------------
134  dot(u,v)
135                 (dot u v)
137  ==>  6
139 Regular old dot product.
141 ------------------------------------------------------------------------
143  proj(u,v)
144                 (proj u v)
146  ==>  (2, 2, 2)
148 Projection of /u/ onto /v/. Usually written: proj  u
149                                                  v
151 ------------------------------------------------------------------------
153  orth(u,v)
154                 (orth u v)
156  ==>  (-1, 0, 1)
158 The orthogonal component of the projection of /u/ onto /v/.
160 Usually written: u - proj  u
161                          v
163 ------------------------------------------------------------------------
165  cross(u,v)
166                 (cross u v)
168  ==>  (-1, 2, -1)
170 Regular old cross product.
172 ------------------------------------------------------------------------
174  1 / 4
175                 (/ 4)
176  ==> 1/4
178 This shortand can only be done in prefix notation. It's there to be
179 consistent with common lisp's syntax.
181 ------------------------------------------------------------------------
182  vim:ft=:expandtab:tw=72: