File: linalg.usage

package info (click to toggle)
maxima 5.42.1-1
  • links: PTS
  • area: main
  • in suites: buster
  • size: 150,192 kB
  • sloc: lisp: 382,565; fortran: 14,666; perl: 14,365; tcl: 11,123; sh: 4,622; makefile: 2,688; ansic: 444; xml: 23; awk: 17; sed: 17
file content (335 lines) | stat: -rw-r--r-- 11,705 bytes parent folder | download | duplicates (16)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
Installation

  To use linalg, you'll need to have nset version 1.203.  If you
  are using Maxima 5.9.1cvs or better, you already have the required
  version of nset. Otherwise you'll need to download and install nset.
  You may download nset from http://www.unk.edu/facstaff/profiles/willisb/.
  
  You will need to append the path to linearalgebra to 
  file_search_maxima and file_search_lisp. If the path to
  the directory linearalgebra is "c:/maxima/linearalgebra", you will
  use the Maxima commands

    (%i1) file_search_maxima : cons("c:/maxima/linearalgebra/###.{mac}",file_search_maxima)$
    (%i2) file_search_lisp : cons("c:/maxima/linearalgebra/###.{lisp}",file_search_lisp)$

  Now you should be able to load and use linalg.

  (%i3) load("linalg");
        Warning - you are redefining the MACSYMA function EIGENVALUES
        Warning - you are redefining the MACSYMA function EIGENVECTORS
        Warning - you are redefining the MACSYMA function RANK
  (%o3) c:/maxima/linearalgebra/linalg.mac
  (%i4) m : matrix([1-z,2],[5,8-z]);
  (%o4) matrix([1-z,2],[5,8-z])
  (%i5) ptriangularize(m,z);
  (%o5) matrix([5,8-z],[0,-z^2/5+(9*z)/5+2/5])


columnop(m,i,j,theta)

  If m is a matrix, return the matrix that results from doing the  
  column operation Ci <- Ci - theta * Cj. If m doesn't have a row
  i or j, signal an error.

columnswap(m,i,j)

  If m is a matrix, swap columns i and j.  If m doesn't have a column
  i or j, signal an error.

columnspace(m)
 
   If m is a matrix, return span(v1,v2,...,vn), where the set
   {v1,v2,...,vn} is a basis for the column space of m.  The span 
   of the empty set is {0}. Thus, when the column space has only 
   one member, return span().

ctranspose(m)

   Return the conjugate of the transpose of the matrix m. If m is
   a block matrix, transpose and conjugate each block. 

dotproduct(u,v)

   Return the dotproduct of vectors u and v.  This is the same
   as conj(transpose(u)) . v.  The arguments u and v must be
   n x 1 matrices.
   
get_lu_factors(x) 

  When x = lu_factor(A), then get_lu_factors returns a list of the 
  form [P, L, U], where P is a permutation matrix, L is lower triangular with
  ones on the digonal, and U is upper triangular. And A = P L U.
 
hilbert_matrix(n)

  Return the n by n Hilbert matrix. When n isn't a nonnegative
  integer, signal an error.

kronecker_product(a,b)

   Return the Kronecker product of the matrices a and b.

listp (e, {pred})

  Given an optional argument pred, return true if e is 
  a Maxima list and pred evaluates to true for every list element.
  When listp is not given the optional argument, return true if e is 
  a Maxima list.  In all other cases, return false.
  
locate_matrix_entry(m, r1, c1, r2, c2, fn, rel)
   
   The first argument must be a matrix; the arguments
   r1 through c2 determine a sub-matrix of m that consists of
   rows r1 through r2 and columns c1 through c2. 
  
   Find a entry in the sub-matrix m that satisfies some property. 
   Three cases:

     (1) rel = bool and fn a predicate: 

         Scan the sub-matrix from left to right then top to bottom,
         and return the index of the first entry that satisfies the 
         predicate fn. If no matrix entry satisfies fn, return false.

     (2) rel = 'max and fn real-valued:

         Scan the sub-matrix looking for an entry that maximizes fn.
         Return the index of a maximizing entry.

     (3) rel = 'min and fn real-valued:

         Scan the sub-matrix looking for an entry that minimizes fn. 
         Return the index of a minimizing entry.

lu_backsub(m, b fld)

  When m = lu_factor(A), then lu_backsub(m,b, fld) solves the linear
  systme A x = b.

lu_factor(m, generalfield)

  Return a list of the form [LU, perm, {cnd}], where

  (1) The matrix LU contains the factorization of m in a packed form. Packed
      form means three things: First, the rows of LU are permuted according to the 
      list perm.  If, for example, perm is the list [3,2,1], the actual first row 
      of the LU factorization is the third row of the matrix LU. Second,
      the lower triangular factor of m is the lower triangular part of LU with the
      diagonal entries replaced by all ones. Third, the upper triangular factor of 
      m is the upper triangular part of LU.  

  (2) When the field is either 'floatfield' or 'complexfloatfield,' 
      the number 'cnd' is an upper bound for the infinity norm condition number of m.
      For all other fields, the condition number isn't estimated. For these fields,
      lu_factor returns a two item list.
   
  The argument m must be a square matrix.

  The argument 'fld' must be a symbol that determines a field. The pre-defined 
  fields are:

    (a) generalfield -- the field of Maxima expressions,
    (b) floatfield --  the field of floating point numbers of the type double,
    (c) complexfloatfield --  the field of complex floating point numbers of the 
        type double,
    (d) crefield  -- the field of Maxima CRE expressions,
    (e) rationalfiled -- the field of rational numbers.

  When the field is floatfield or complexfloatfield, the algorithm uses partial
  pivoting; when the field is generalfield, rows are switched only when needed to
  avoid a zero pivot.

  Floating point addition arithmetic isn't associative, so the meaning of 'field' 
  differs from the mathematical definition.

  There is no user-interface for defining a new field. A user that is familiar with
  Common Lisp should be able to define a new field. 

  To compute the factorization, the first task is to convert each matrix entry
  to a member of the indicated field. When conversion isn't possible, the factorization
  halts with an error message. Members of the field needn't be Maxima expressions.
  Members of the complexfloatfield, for example, are Common Lisp complex numbers. Thus
  after computing the factorization, the matrix entries must be converted to Maxima
  expressions.
 
  See also get_lu_factors.

  Examples

   (%i1) w[i,j] := ?random(1.0) + %i * ?random(1.0)$
           Evaluation took 0.00 seconds (0.00 elapsed)
   (%i2) m : genmatrix(w,100,100)$
           Evaluation took 00.30 seconds (00.30 elapsed)
   (%i3) lu_factor(m,complexfloatfield)$
           Evaluation took 1.45 seconds (1.45 elapsed)
   (%i4) lu_factor(m,generalfield)$
           Evaluation took 12.10 seconds (12.10 elapsed)

   (%i1) m : matrix([1-z,3],[3,8-z]); 
   (%o1) matrix([1-z,3],[3,8-z])
   (%i2) lu_factor(m,generalfield);
   (%o2) [matrix([1-z,3],[3/(1-z),-z-9/(1-z)+8]),[1,2]]
   (%i3) get_lu_factors(%);
   (%o3) [matrix([1,0],[0,1]),matrix([1,0],[3/(1-z),1]),matrix([1-z,3],[0,-z-9/(1-z)+8])]
   (%i4) %[1] . %[2] . %[3];
   (%o4) matrix([1-z,3],[3,8-z])

mat_norm(m, p) 

  Return the matrix p-norm of the matrix m.  The allowed values for p are
  1, inf, and frobenius (the Frobenius matrix norm). The matrix m should be
  an unblocked matrix.

matrixp (e, {pred})

  Given an optional argument pred, return true if e is 
  a matrix and pred evaluates to true for every matrix element.
  When matrixp is not given an optional argument, return true 
  if e is a matrix.  In all other cases, return false.

nonnegintegerp (n)

  Return true if and only if n >= 0 and n is an integer.

nullspace(m)

   If m is a matrix, return span(v1,v2,...,vn), where the set {v1,v2,...,vn}
   is a basis for the nullspace of m.  The span of the empty set is {0}.  
   Thus, when the nullspace has only one member, return span().

nullity(m)

   If m is a matrix, return the dimension of the nullspace of m.

orthogonal_complement(v1,v2,...,vn)

   Return span(u1,u2,...,um), where the set {u1,u2,...,um} is a 
   basis for the orthogonal complement of the set(v1,v2,...,vn).

   Each vector v1 through vn must be a n x 1 matrix.

polynomialp(p, l,  {(coeffp 'constantp), (exponp 'nonnegintegerp)})

  Return true if p is a polynomial in the variables in the Maxmia list l,
  The predicate coeffp (default constantp) must evaluate to true for each
  coefficient, and the predicate exponp must evaluate to true for all 
  exponents of the variables in the list l. If you want to use a non-default
  value for exponp, you must supply coeffp with a value even if you want
  to use the default for coeffp.

  The polynomial needn't be expanded:
  
    (%i1) polynomialp((x+1)*(x+2),[x]);
    (%o1) true

    (%i2) polynomialp((x+1)*(x+2)^a,[x]);
    (%o2) false

  An example using non-default values for coeffp and exponp:

    (%i3) polynomialp((x+1)*(x+2)^(3/2),[x],numberp,numberp);
    (%o3) true

    (%i4) polynomialp((x^(1/2)+1)*(x+2)^(3/2),[x],numberp,numberp);
    (%o4) true

  Polynomials with two variables:

    (%i5) polynomialp(x^2 + 5*x*y + y^2,[x]);
    (%o5) false

    (%i6) polynomialp(x^2 + 5*x*y + y^2,[x,y]);
    (%o6) true

polytocompanion(p,x)
   
  If p is a polynomial in x, return the companion matrix of p. For
  a monic polynomial p of degree n, we have p = (-1)^n charpoly(polytocompanion(p, x)).

  When p isn't a polynomial in x, signal an error.
  
ptriangularize(m,v)
   
   If m is a matrix with each entry a polynomial in v, return 
   a matrix m' such that
 
     (1) m' is upper triangular,
     (2) m' = E_n ... E_1 m, where E1 through En are elementary matrices 
         whose entries are polynomials in v,
     (3) |det(m)| = |det(m')|,

   Note: This function doesn't check that every entry is a polynomial in v.  

rowop(m,i,j,theta)

  If m is a matrix, return the matrix that results from doing the  
  row operation Ri <- Ri - theta * Rj. If m doesn't have a row
  i or j, signal an error.

rowswap(m,i,j)

  If m is a matrix, swap rows i and j. If m doesn't have a row
  i or j, signal an error.

mat_unblocker(m)

  If m is a block matrix, return its unblocked form. If m is a matrix,
  return m; otherwise, signal an error.  If you use block matrices,
  most likely you'll want to set matrix_element_mult : "." and
  matrix_element_transpose : 'transpose. 

  Example

    (%i1) a : matrix([1,2],[3,4])$
    (%i2) b : matrix([7,8],[9,10])$
    (%i3) matrix([a,b]);
    (%o3) matrix([matrix([1,2],[3,4]),matrix([7,8],[9,10])])
    (%i4) mat_unblocker(%);
    (%o4) matrix([1,2,7,8],[3,4,9,10])

vandermonde_matrix([x1,x2,...,xn])

  Return a n by n matrix whose i-th row is 
  [1, xi, xi^2, ... xi^(n-1)]. 

zeromatrixp(m)

  If is(equal(e,0)) is true for each entry of the matrix m, return true; otherwise,
  return false.  When m is not a matrix, signal an error.


Short demo:

(%i1) batch("linalg.demo");
batching #pc:/maxima/linearalgebra/linalg.demo
(%i2) load(linalg)
(%o2) c:/maxima/linearalgebra/linalg.mac
(%i3) m:matrix([1,2],[1,2])
(%o3) matrix([1,2],[1,2])
(%i4) nullspace(m)
(%o4) span(matrix([1],[-1/2]))
(%i5) columnspace(m)
(%o5) span(matrix([1],[1]))
(%i6) ptriangularize(m-z*ident(2),z)
(%o6) matrix([1,2-z],[0,3*z-z^2])
(%i7) m:matrix([1,2,3],[4,5,6],[7,8,9])-z*ident(3)
(%o7) matrix([1-z,2,3],[4,5-z,6],[7,8,9-z])
(%i8) mm:ptriangularize(m,z)
(%o8) matrix([4,5-z,6],[0,66/49,-z^2/7+(102*z)/49+132/49],[0,0,(49*z^3)/264-(245*z^2)/88-(147*z)/44])
(%i9) algebraic:true
(%o9) true
(%i10) tellrat(mm[3,3])
(%o10) [z^3-15*z^2-18*z]
(%i11) mm:ratsimp(mm)
(%o11) matrix([4,5-z,6],[0,66/49,-(7*z^2-102*z-132)/49],[0,0,0])
(%i12) nullspace(mm)
(%o12) span(matrix([1],[(z^2-14*z-16)/8],[-(z^2-18*z-12)/12]))
(%i13) m:matrix([1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16])
(%o13) matrix([1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16])
(%i14) column_space(m)
(%o14) column_space(matrix([1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]))
(%i15) apply('orthogonal_complment,args(nullspace(transpose(m))))
(%o15) orthogonal_complment(matrix([0],[1],[-2],[1]),matrix([1],[0],[-3],[2]))