2 ***********************************************************************
4 Some utilities for working with vectors.
6 Copyright (C) Nov. 2008 Volker van Nek (van dot nek at arcor dot de)
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
23 ***********************************************************************
25 vector_rebuild.mac provides to do basic vector calculations in a
26 readable form. Choose lists or one column matrices to represent vectors.
28 Loading vector_rebuild.mac sets the option variables listarith,
29 doallmxops and domxmxops to false. Then addition, scalar multiplication
30 and non commutative multiplication are not carried out automatically.
31 These operations need an additional step which is done by vector_simp:
33 (%i1) load(vector_rebuild)$
34 (%i2) line: [1,2]+t*[3,4];
35 (%o2) t [3, 4] + [1, 2]
37 (%o3) [3 t + 1, 4 t + 2]
39 Such expanded expressions can be reconstructed by vector_rebuild:
41 (%i4) vector_rebuild(%,[t]);
42 (%o4) t [3, 4] + [1, 2]
44 Vector calculations can be directly reconstructed:
46 (%i5) [1,2]+t*[3,4]+[5,6]+(t/2-1)*[7,8]$
47 (%i6) vector_rebuild(%,[t]);
49 (%o6) t [--, 8] + [- 1, 0]
52 While working with column vectors it can be useful to pull out the gcd:
54 (%i7) covect([1/2,1/3,1/4])$
55 (%i8) %, vector_factor;
62 The option variable vector_factor_minus controls whether a common
63 minus sign is also pulled out (true) or not (false=default):
65 (%i9) vector_factor([-2,-4]), vector_factor_minus:true;
68 The function extract_equations extracts the system of equations from
71 (%i10) veq: line = [4,3]+s*[2,1];
72 (%o10) t [3, 4] + [1, 2] = s [2, 1] + [4, 3]
73 (%i11) sys: extract_equations(veq);
74 (%o11) [3 t + 1 = 2 s + 4, 4 t + 2 = s + 3]
76 This system can now be solved by e.g. algsys.
78 The calculation of a cross product and the vector length is carried
81 (%i12) [1,0,0]~[0,1,0];
83 (%i13) (v:covect([1,2]), 1/|v|*v);
88 ***********************************************************************
90 vector_rebuild.mac is in a very experimental state of development.
91 Be warned: It is not compatible with vect.mac.
93 ***********************************************************************
95 Example: Calculating common points of two planes (e.g. identical planes)
97 (%i1) load(vector_rebuild)$
98 (%i2) v([args]):= covect(args)$
99 (%i3) plane1: v(1,2,3)+p*v(4,5,6)+q*v(7,8,9);
102 (%o3) q [ 8 ] + p [ 5 ] + [ 2 ]
105 (%i4) plane2: v(3,2,1)+r*v(6,5,4)+s*v(9,8,7)$
106 (%i5) veq: plane1 = plane2;
107 [ 7 ] [ 4 ] [ 1 ] [ 9 ] [ 6 ] [ 3 ]
108 [ ] [ ] [ ] [ ] [ ] [ ]
109 (%o5) q [ 8 ] + p [ 5 ] + [ 2 ] = s [ 8 ] + r [ 5 ] + [ 2 ]
110 [ ] [ ] [ ] [ ] [ ] [ ]
111 [ 9 ] [ 6 ] [ 3 ] [ 7 ] [ 4 ] [ 1 ]
112 (%i6) map(disp, sys: extract_equations(veq))$
113 7 q + 4 p + 1 = 9 s + 6 r + 3
115 8 q + 5 p + 2 = 8 s + 5 r + 2
117 9 q + 6 p + 3 = 7 s + 4 r + 1
119 (%i7) params: algsys(sys,[p,q,r,s]);
121 (%o7) [[p = %r1, q = %r2, r = - --------------------,
124 s = --------------------]]
126 (%i8) params: %, %r1=u, %r2=v;
127 16 v + 13 u + 16 13 v + 10 u + 10
128 (%o8) [[p = u, q = v, r = - ----------------, s = ----------------]]
130 (%i9) subst(params,plane1);
133 (%o9) v [ 8 ] + u [ 5 ] + [ 2 ]
136 (%i10) subst(params,plane2);
138 16 v + 13 u + 16 [ ] 13 v + 10 u + 10 [ ] [ ]
139 (%o10) (- ----------------) [ 5 ] + ---------------- [ 8 ] + [ 2 ]
142 (%i11) vector_rebuild(%,[u,v]);
145 (%o11) v [ 8 ] + u [ 5 ] + [ 2 ]
150 ***********************************************************************
154 (%i1) load(vector_rebuild)$
157 (%i4) plane: x.n = a.n;
158 (%o4) x . [1, 2, 3] = [2, 0, 1] . [1, 2, 3]
159 (%i5) %, vector_simp;
160 (%o5) x . [1, 2, 3] = 5
161 (%i6) %, x=[x1,x2,x3], vector_simp;
162 (%o6) 3 x3 + 2 x2 + x1 = 5
164 ***********************************************************************
166 (%i1) load(vector_rebuild)$
167 (%i2) v([args]):= covect(args)$
176 (%i6) plane: x.n = a.n;
179 (%o6) x . [ 2 ] = [ 0 ] . [ 2 ]
182 (%i7) %, vector_simp;
188 (%i8) %, x=v(x1,x2,x3), vector_simp;
189 (%o8) 3 x3 + 2 x2 + x1 = 5
190 (%i9) point: v(0,1,2)$
191 (%i10) plane, x=point, vector_simp;
193 (%i11) distance: |(point-a)*en|;
202 (%o12) -------- [ 2 ] + [ 0 ]
205 (%i13) vector_simp(%);
217 (%i14) vector_rebuild(%,[t]), vector_factor;
220 (%o14) -------- [ 2 ] + [ 0 ]
223 (%i15) vector_factor(v(-2,-4));
227 (%i16) vector_factor(v(-2,-4)), vector_factor_minus:true;
232 ***********************************************************************
236 (%i1) load(vector_rebuild)$
237 (%i2) M: matrix([1,2],[3,-1]);
241 (%i3) M_1: M^^-1, vector_factor;
245 (%i5) M.M_1, vector_simp;
250 ***********************************************************************