~ubuntu-branches/ubuntu/karmic/maxima/karmic

« back to all changes in this revision

Viewing changes to share/linearalgebra/linearalgebra.texi.tmp

  • Committer: Bazaar Package Importer
  • Author(s): Barry deFreese
  • Date: 2006-07-06 17:04:52 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20060706170452-j9ypoqc1kjfnz221
Tags: 5.9.3-1ubuntu1
* Re-sync with Debian
* Comment out backward-delete-char-untabify in maxima.el (Closes Malone #5273)
* debian/control: build-dep automake -> automake1.9 (Closes BTS: #374663)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
\input texinfo
 
2
@c makeinfo linearalgebra.texi         to make .info
 
3
@c texi2html linearalgebra.texi        to make .html
 
4
@c texi2pdf linearalgebra.texi         to make .pdf
 
5
 
 
6
@setfilename linearalgebra.info
 
7
@settitle linearalgebra
 
8
 
 
9
@format
 
10
INFO-DIR-SECTION Math
 
11
START-INFO-DIR-ENTRY
 
12
* Maxima-linearalgebra: (linearalgebra).  A computer algebra system -- contributions.
 
13
END-INFO-DIR-ENTRY
 
14
@end format
 
15
@ifinfo 
 
16
@macro var {expr}
 
17
<\expr\>
 
18
@end macro
 
19
@end ifinfo
 
20
 
 
21
@node Top, Introduction to linearalgebra, (dir), (dir)
 
22
@top
 
23
@menu
 
24
* Introduction to linearalgebra::
 
25
* Definitions for linearalgebra::
 
26
* Function and variable index::
 
27
@end menu
 
28
 
 
29
@node Introduction to linearalgebra, Definitions for linearalgebra, Top, Top
 
30
@section Introduction to linearalgebra
 
31
 
 
32
@code{linearalgebra} is a collection of functions for linear algebra.
 
33
 
 
34
Example:
 
35
 
 
36
@c ===beg===
 
37
@c load (linearalgebra)$
 
38
@c M : matrix ([1, 2], [1, 2]);
 
39
@c nullspace (M);
 
40
@c columnspace (M);
 
41
@c ptriangularize (M - z*ident(2), z);
 
42
@c M : matrix ([1, 2, 3], [4, 5, 6], [7, 8, 9]) - z*ident(3);
 
43
@c MM : ptriangularize (M, z);
 
44
@c algebraic : true;
 
45
@c tellrat (MM [3, 3]);
 
46
@c MM : ratsimp (MM);
 
47
@c nullspace (MM);
 
48
@c M : matrix ([1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]);
 
49
@c columnspace (M);
 
50
@c apply ('orthogonal_complement, args (nullspace (transpose (M))));
 
51
@c ===end===
 
52
@example
 
53
(%i1) load (linearalgebra);
 
54
Warning - you are redefining the Maxima function require_list
 
55
Warning - you are redefining the Maxima function matrix_size
 
56
Warning - you are redefining the Maxima function rank
 
57
(%o1) /usr/local/share/maxima/5.9.2/share/linearalgebra/linearalgebra.mac
 
58
(%i2) M : matrix ([1, 2], [1, 2]);
 
59
                            [ 1  2 ]
 
60
(%o2)                       [      ]
 
61
                            [ 1  2 ]
 
62
(%i3) nullspace (M);
 
63
                               [  1  ]
 
64
                               [     ]
 
65
(%o3)                     span([   1 ])
 
66
                               [ - - ]
 
67
                               [   2 ]
 
68
(%i4) columnspace (M);
 
69
                                [ 1 ]
 
70
(%o4)                      span([   ])
 
71
                                [ 1 ]
 
72
(%i5) ptriangularize (M - z*ident(2), z);
 
73
                         [ 1   2 - z   ]
 
74
(%o5)                    [             ]
 
75
                         [           2 ]
 
76
                         [ 0  3 z - z  ]
 
77
(%i6) M : matrix ([1, 2, 3], [4, 5, 6], [7, 8, 9]) - z*ident(3);
 
78
                     [ 1 - z    2      3   ]
 
79
                     [                     ]
 
80
(%o6)                [   4    5 - z    6   ]
 
81
                     [                     ]
 
82
                     [   7      8    9 - z ]
 
83
(%i7) MM : ptriangularize (M, z);
 
84
              [ 4  5 - z            6            ]
 
85
              [                                  ]
 
86
              [                2                 ]
 
87
              [     66        z    102 z   132   ]
 
88
              [ 0   --      - -- + ----- + ---   ]
 
89
(%o7)         [     49        7     49     49    ]
 
90
              [                                  ]
 
91
              [               3        2         ]
 
92
              [           49 z    245 z    147 z ]
 
93
              [ 0    0    ----- - ------ - ----- ]
 
94
              [            264      88      44   ]
 
95
(%i8) algebraic : true;
 
96
(%o8)                         true
 
97
(%i9) tellrat (MM [3, 3]);
 
98
                         3       2
 
99
(%o9)                  [z  - 15 z  - 18 z]
 
100
(%i10) MM : ratsimp (MM);
 
101
               [ 4  5 - z           6           ]
 
102
               [                                ]
 
103
               [                2               ]
 
104
(%o10)         [     66      7 z  - 102 z - 132 ]
 
105
               [ 0   --    - ------------------ ]
 
106
               [     49              49         ]
 
107
               [                                ]
 
108
               [ 0    0             0           ]
 
109
(%i11) nullspace (MM);
 
110
                        [        1         ]
 
111
                        [                  ]
 
112
                        [   2              ]
 
113
                        [  z  - 14 z - 16  ]
 
114
                        [  --------------  ]
 
115
(%o11)             span([        8         ])
 
116
                        [                  ]
 
117
                        [    2             ]
 
118
                        [   z  - 18 z - 12 ]
 
119
                        [ - -------------- ]
 
120
                        [         12       ]
 
121
(%i12) M : matrix ([1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]);
 
122
                       [ 1   2   3   4  ]
 
123
                       [                ]
 
124
                       [ 5   6   7   8  ]
 
125
(%o12)                 [                ]
 
126
                       [ 9   10  11  12 ]
 
127
                       [                ]
 
128
                       [ 13  14  15  16 ]
 
129
(%i13) columnspace (M);
 
130
                           [ 1  ]  [ 2  ]
 
131
                           [    ]  [    ]
 
132
                           [ 5  ]  [ 6  ]
 
133
(%o13)                span([    ], [    ])
 
134
                           [ 9  ]  [ 10 ]
 
135
                           [    ]  [    ]
 
136
                           [ 13 ]  [ 14 ]
 
137
(%i14) apply ('orthogonal_complement, args (nullspace (transpose (M))));
 
138
                           [ 0 ]  [  1  ]
 
139
                           [   ]  [     ]
 
140
                           [ 1 ]  [  0  ]
 
141
(%o14)                span([   ], [     ])
 
142
                           [ 2 ]  [ - 1 ]
 
143
                           [   ]  [     ]
 
144
                           [ 3 ]  [ - 2 ]
 
145
@end example
 
146
 
 
147
@node Definitions for linearalgebra, Function and variable index, Introduction to linearalgebra, Top
 
148
@section Definitions for linearalgebra
 
149
 
 
150
@deffn {Function} addmatrices (@var{f}, @var{M_1}, ..., @var{M_n})
 
151
 
 
152
@c REWORD -- THE RESULT IS NOT GENERALLY THE SUM OF M_1, ..., M_N
 
153
Using the function @var{f} as the addition function, return the sum of
 
154
the matrices @var{M_1}, ..., @var{M_n}. The function @var{f} must accept any number of
 
155
arguments (a Maxima nary function).
 
156
 
 
157
Examples:
 
158
 
 
159
@c ===beg===
 
160
@c m1 : matrix([1,2],[3,4])$
 
161
@c m2 : matrix([7,8],[9,10])$
 
162
@c addmatrices('max,m1,m2);
 
163
@c addmatrices('max,m1,m2,5*m1);
 
164
@c ===end===
 
165
@example
 
166
(%i1) m1 : matrix([1,2],[3,4])$
 
167
(%i2) m2 : matrix([7,8],[9,10])$
 
168
(%i3) addmatrices('max,m1,m2);
 
169
(%o3) matrix([7,8],[9,10])
 
170
(%i4) addmatrices('max,m1,m2,5*m1);
 
171
(%o4) matrix([7,10],[15,20])
 
172
@end example
 
173
 
 
174
@end deffn
 
175
 
 
176
@deffn {Function} blockmatrixp (@var{M})
 
177
 
 
178
Return true if and only if @var{M} is a matrix and every entry of 
 
179
@var{M} is a matrix.
 
180
 
 
181
@end deffn
 
182
 
 
183
@deffn {Function} columnop (@var{M}, @var{i}, @var{j}, @var{theta})
 
184
 
 
185
If @var{M} is a matrix, return the matrix that results from doing the  
 
186
column operation @code{C_i <- C_i - @var{theta} * C_j}. If @var{M} doesn't have a row
 
187
@var{i} or @var{j}, signal an error.
 
188
 
 
189
@end deffn
 
190
 
 
191
@deffn {Function} columnswap (@var{M}, @var{i}, @var{j})
 
192
 
 
193
If @var{M} is a matrix, swap columns @var{i} and @var{j}.  If @var{M} doesn't have a column
 
194
@var{i} or @var{j}, signal an error.
 
195
 
 
196
@end deffn
 
197
 
 
198
@deffn {Function} columnspace (@var{M})
 
199
 
 
200
If @var{M} is a matrix, return @code{span (v_1, ..., v_n)}, where the set
 
201
@code{@{v_1, ..., v_n@}} is a basis for the column space of @var{M}.  The span 
 
202
of the empty set is @code{@{0@}}. Thus, when the column space has only 
 
203
one member, return @code{span ()}.
 
204
 
 
205
@end deffn
 
206
 
 
207
@deffn {Function} copy (@var{e})
 
208
 
 
209
Return a copy of the Maxima expression @var{e}. Although @var{e} can be any
 
210
Maxima expression, the copy function is the most useful when @var{e} is either 
 
211
a list or a matrix; consider:
 
212
@c ===beg===
 
213
load (linearalgebra);
 
214
m : [1,[2,3]]$
 
215
mm : m$
 
216
mm[2][1] : x$
 
217
m;
 
218
mm;
 
219
@c ===end===
 
220
@example 
 
221
(%i1) load("linearalgebra")$
 
222
(%i2) m : [1,[2,3]]$
 
223
(%i3) mm : m$
 
224
(%i4) mm[2][1] : x$
 
225
(%i5) m;
 
226
(%o5) [1,[x,3]]
 
227
(%i6) mm;
 
228
(%o6) [1,[x,3]]
 
229
@end example
 
230
Let's try the same experiment, but this time let @var{mm} be a copy of @var{m}
 
231
@c ===beg===
 
232
m : [1,[2,3]]$
 
233
mm : copy(m)$
 
234
mm[2][1] : x$
 
235
m;
 
236
mm;
 
237
@c ===end===
 
238
@example
 
239
(%i7) m : [1,[2,3]]$
 
240
(%i8) mm : copy(m)$
 
241
(%i9) mm[2][1] : x$
 
242
(%i10) m;
 
243
(%o10) [1,[2,3]]
 
244
(%i11) mm;
 
245
(%o11) [1,[x,3]]
 
246
@end example
 
247
This time, the assignment to @var{mm} does not change the value of @var{m}.
 
248
 
 
249
@end deffn
 
250
 
 
251
@deffn {Function} cholesky (@var{M})
 
252
@deffnx {Function} cholesky (@var{M}, @var{field})
 
253
 
 
254
Return the Cholesky factorization of the matrix selfadjoint (or hermitian) matrix 
 
255
@var{M}. The second argument defaults to 'generalring.' For a description of the
 
256
possible values for @var{field}, see @code{lu_factor}.
 
257
 
 
258
@end deffn
 
259
 
 
260
@deffn {Function} ctranspose (@var{M})
 
261
 
 
262
Return the complex conjugate transpose of the matrix @var{M}. The function
 
263
@code{ctranspose} uses @code{matrix_element_transpose} to transpose each matrix element.
 
264
 
 
265
@end deffn
 
266
 
 
267
@deffn {Function} diag_matrix (@var{d_1}, @var{d_2},...,@var{d_n})
 
268
 
 
269
Return a diagonal matrix with diagonal entries @var{d_1}, @var{d_2},...,@var{d_n}.
 
270
When the diagonal entries are matrices, the zero entries of the returned matrix
 
271
are zero matrices of the appropriate size; for example:
 
272
@c ===beg===
 
273
@c load(linearalgebra)$
 
274
@c diag_matrix(diag_matrix(1,2),diag_matrix(3,4));
 
275
@c diag_matrix(p,q);
 
276
@c ===end===
 
277
@example
 
278
(%i1) load(linearalgebra)$
 
279
 
 
280
(%i2) diag_matrix(diag_matrix(1,2),diag_matrix(3,4));
 
281
 
 
282
                            [ [ 1  0 ]  [ 0  0 ] ]
 
283
                            [ [      ]  [      ] ]
 
284
                            [ [ 0  2 ]  [ 0  0 ] ]
 
285
(%o2)                       [                    ]
 
286
                            [ [ 0  0 ]  [ 3  0 ] ]
 
287
                            [ [      ]  [      ] ]
 
288
                            [ [ 0  0 ]  [ 0  4 ] ]
 
289
(%i3) diag_matrix(p,q);
 
290
 
 
291
                                   [ p  0 ]
 
292
(%o3)                              [      ]
 
293
                                   [ 0  q ]
 
294
@end example
 
295
@end deffn
 
296
 
 
297
@deffn {Function} dotproduct (@var{u}, @var{v})
 
298
 
 
299
Return the dotproduct of vectors @var{u} and @var{v}.  This is the same
 
300
as @code{conjugate (transpose (@var{u})) . @var{v}}.  The arguments @var{u} and @var{v} must be
 
301
column vectors.
 
302
 
 
303
@end deffn
 
304
 
 
305
@deffn {Function} get_lu_factors (@var{x}) 
 
306
 
 
307
When @code{@var{x} = lu_factor (@var{A})}, then @code{get_lu_factors} returns a list of the 
 
308
form @code{[P, L, U]}, where @var{P} is a permutation matrix, @var{L} is lower triangular with
 
309
ones on the diagonal, and @var{U} is upper triangular, and @code{@var{A} = @var{P} @var{L} @var{U}}.
 
310
 
 
311
@end deffn
 
312
 
 
313
@deffn {Function} hankel (@var{col})
 
314
@deffnx {Function} hankel (@var{col}, @var{row})
 
315
 
 
316
Return a Hankel matrix @var{H}. The first first column of @var{H} is @var{col};
 
317
except for the first entry, the last row of @var{H} is @var{row}. The
 
318
default for @var{row} is the zero vector with the same length as @var{col}.
 
319
 
 
320
@end deffn
 
321
 
 
322
@deffn {Function} hessian (@var{f},@var{vars})
 
323
 
 
324
Return the hessian matrix of @var{f} with respect to the variables in the list
 
325
@var{vars}.  The @var{i},@var{j} entry of the hessian matrix is 
 
326
@var{diff(f vars[i],1,vars[j],1)}.
 
327
 
 
328
@end deffn
 
329
 
 
330
@deffn {Function} hilbert_matrix (@var{n})
 
331
 
 
332
Return the @var{n} by @var{n} Hilbert matrix. When @var{n} isn't a positive
 
333
integer, signal an error.
 
334
 
 
335
@end deffn
 
336
 
 
337
@deffn {Function} identfor (@var{M})
 
338
@deffnx {Function} identfor (@var{M}, @var{fld})
 
339
 
 
340
Return an identity matrix that has the same shape as the matrix
 
341
@var{M}.  The diagonal entries of the identity matrix are the 
 
342
multiplicative identity of the field @var{fld}; the default for
 
343
@var{fld} is @var{generalring}.
 
344
 
 
345
The first argument @var{M} should be a square matrix or a 
 
346
non-matrix. When @var{M} is a matrix, each entry of @var{M} can be a
 
347
square matrix -- thus @var{M} can be a blocked Maxima matrix. The
 
348
matrix can be blocked to any (finite) depth.
 
349
 
 
350
See also @code{zerofor}
 
351
 
 
352
@end deffn
 
353
 
 
354
@deffn {Function} invert_by_lu (@var{M}, @var{(rng generalring)})
 
355
 
 
356
Invert a matrix @var{M} by using the LU factorization.  The LU factorization
 
357
is done using the ring @var{rng}.
 
358
 
 
359
@end deffn
 
360
 
 
361
@deffn {Function} kronecker_product (@var{A}, @var{B})
 
362
 
 
363
Return the Kronecker product of the matrices @var{A} and @var{B}.
 
364
 
 
365
@end deffn
 
366
 
 
367
 
 
368
@deffn {Function} locate_matrix_entry (@var{M}, @var{r_1}, @var{c_1}, @var{r_2}, @var{c_2}, @var{f}, @var{rel})
 
369
 
 
370
The first argument must be a matrix; the arguments
 
371
@var{r_1} through @var{c_2} determine a sub-matrix of @var{M} that consists of
 
372
rows @var{r_1} through @var{r_2} and columns @var{c_1} through @var{c_2}. 
 
373
 
 
374
Find a entry in the sub-matrix @var{M} that satisfies some property. 
 
375
Three cases:
 
376
 
 
377
(1) @code{@var{rel} = 'bool} and @var{f} a predicate: 
 
378
 
 
379
Scan the sub-matrix from left to right then top to bottom,
 
380
and return the index of the first entry that satisfies the 
 
381
predicate @var{f}. If no matrix entry satisfies @var{f}, return false.
 
382
 
 
383
(2) @code{@var{rel} = 'max} and @var{f} real-valued:
 
384
 
 
385
Scan the sub-matrix looking for an entry that maximizes @var{f}.
 
386
Return the index of a maximizing entry.
 
387
 
 
388
(3) @code{@var{rel} = 'min} and @var{f} real-valued:
 
389
 
 
390
Scan the sub-matrix looking for an entry that minimizes @var{f}. 
 
391
Return the index of a minimizing entry.
 
392
 
 
393
@end deffn
 
394
 
 
395
@deffn {Function} lu_backsub (@var{M}, @var{b})
 
396
 
 
397
When @code{@var{M} = lu_factor (@var{A}, @var{field})},
 
398
then @code{lu_backsub (@var{M}, @var{b})} solves the linear
 
399
system @code{@var{A} @var{x} = @var{b}}.
 
400
 
 
401
@end deffn
 
402
 
 
403
@deffn {Function} lu_factor (@var{M}, @var{field})
 
404
 
 
405
Return a list of the form @code{[@var{LU}, @var{perm}, @var{fld}]}, 
 
406
or @code{[@var{LU}, @var{perm}, @var{fld}, @var{lower-cnd} @var{upper-cnd}]}, where
 
407
 
 
408
  (1) The matrix @var{LU} contains the factorization of @var{M} in a packed form. Packed
 
409
      form means three things: First, the rows of @var{LU} are permuted according to the 
 
410
      list @var{perm}.  If, for example, @var{perm} is the list @code{[3,2,1]}, the actual first row 
 
411
      of the @var{LU} factorization is the third row of the matrix @var{LU}. Second,
 
412
      the lower triangular factor of m is the lower triangular part of @var{LU} with the
 
413
      diagonal entries replaced by all ones. Third, the upper triangular factor of 
 
414
      @var{M} is the upper triangular part of @var{LU}.  
 
415
 
 
416
  (2) When the field is either @code{floatfield} or @code{complexfield},
 
417
      the numbers @var{lower-cnd} and @var{upper-cnd} are lower and upper bounds for the 
 
418
      infinity norm condition number of @var{M}.  For all fields, the condition number 
 
419
      might not be estimated; for such fields, @code{lu_factor} returns a two item list.
 
420
      Both the lower and upper bounds can differ from their true values by 
 
421
      arbitrarily large factors. (See also @code{mat_cond}.)
 
422
   
 
423
  The argument @var{M} must be a square matrix.
 
424
 
 
425
  The optional argument @var{fld} must be a symbol that determines a ring or field. The pre-defined 
 
426
  fields and rings are:
 
427
 
 
428
    (a) @code{generalring} -- the ring of Maxima expressions,
 
429
    (b) @code{floatfield} --  the field of floating point numbers of the type double,
 
430
    (c) @code{complexfield} --  the field of complex floating point numbers of the 
 
431
        type double,
 
432
    (d) @code{crering}  -- the ring of Maxima CRE expressions,
 
433
    (e) @code{rationalfield} -- the field of rational numbers,
 
434
    (f) @code{runningerror} -- track the all floating point rounding errors,
 
435
     (g) @code{noncommutingring} -- the ring of Maxima expressions where multiplication is the
 
436
        non-commutative dot operator.       
 
437
 
 
438
When the field is @code{floatfield}, @code{complexfield}, or
 
439
@code{runningerror}, the algorithm uses partial pivoting; for all
 
440
other fields, rows are switched only when needed to avoid a zero
 
441
pivot.
 
442
 
 
443
Floating point addition arithmetic isn't associative, so the meaning
 
444
of 'field' differs from the mathematical definition.
 
445
 
 
446
A member of the field @code{runningerror} is a two member Maxima list
 
447
of the form @code{[x,n]},where @var{x} is a floating point number and
 
448
@code{n} is an integer. The relative difference between the 'true'
 
449
value of @code{x} and @code{x} is approximately bounded by the machine
 
450
epsilon times @code{n}. The running error bound drops some terms that
 
451
of the order the square of the machine epsilon.
 
452
 
 
453
There is no user-interface for defining a new field. A user that is
 
454
familiar with Common Lisp should be able to define a new field.  To do
 
455
this, a user must define functions for the arithmetic operations and
 
456
functions for converting from the field representation to Maxima and
 
457
back. Additionally, for ordered fields (where partial pivoting will be
 
458
used), a user must define functions for the magnitude and for
 
459
comparing field members.  After that all that remains is to define a
 
460
Common Lisp structure @code{mring}.  The file @code{mring} has many
 
461
examples.
 
462
 
 
463
To compute the factorization, the first task is to convert each matrix
 
464
entry to a member of the indicated field. When conversion isn't
 
465
possible, the factorization halts with an error message. Members of
 
466
the field needn't be Maxima expressions.  Members of the
 
467
@code{complexfield}, for example, are Common Lisp complex numbers. Thus
 
468
after computing the factorization, the matrix entries must be
 
469
converted to Maxima expressions.
 
470
 
 
471
See also  @code{get_lu_factors}.
 
472
 
 
473
 
 
474
Examples:
 
475
 
 
476
@c ===beg===
 
477
@c load (linearalgebra);
 
478
@c w[i,j] := random (1.0) + %i * random (1.0);
 
479
@c showtime : true$
 
480
@c M : genmatrix (w, 100, 100)$
 
481
@c lu_factor (M, complexfield)$
 
482
@c lu_factor (M, generalring)$
 
483
@c showtime : false$
 
484
@c M : matrix ([1 - z, 3], [3, 8 - z]); 
 
485
@c lu_factor (M, generalring);
 
486
@c get_lu_factors (%);
 
487
@c %[1] . %[2] . %[3];
 
488
@c ===end===
 
489
@example
 
490
(%i1) load (linearalgebra);
 
491
Warning - you are redefining the Maxima function require_list
 
492
Warning - you are redefining the Maxima function matrix_size
 
493
Warning - you are redefining the Maxima function rank
 
494
(%o1) /usr/local/share/maxima/5.9.2/share/linearalgebra/linearalgebra.mac
 
495
(%i2) w[i,j] := random (1.0) + %i * random (1.0);
 
496
(%o2)          w     := random(1.) + %i random(1.)
 
497
                i, j
 
498
(%i3) showtime : true$
 
499
Evaluation took 0.00 seconds (0.00 elapsed)
 
500
(%i4) M : genmatrix (w, 100, 100)$
 
501
Evaluation took 7.40 seconds (8.23 elapsed)
 
502
(%i5) lu_factor (M, complexfield)$
 
503
Evaluation took 28.71 seconds (35.00 elapsed)
 
504
(%i6) lu_factor (M, generalring)$
 
505
Evaluation took 109.24 seconds (152.10 elapsed)
 
506
(%i7) showtime : false$
 
507
 
 
508
(%i8) M : matrix ([1 - z, 3], [3, 8 - z]); 
 
509
                        [ 1 - z    3   ]
 
510
(%o8)                   [              ]
 
511
                        [   3    8 - z ]
 
512
(%i9) lu_factor (M, generalring);
 
513
               [ 1 - z         3        ]
 
514
               [                        ]
 
515
(%o9)         [[   3            9       ], [1, 2]]
 
516
               [ -----  - z - ----- + 8 ]
 
517
               [ 1 - z        1 - z     ]
 
518
(%i10) get_lu_factors (%);
 
519
                  [   1    0 ]  [ 1 - z         3        ]
 
520
        [ 1  0 ]  [          ]  [                        ]
 
521
(%o10) [[      ], [   3      ], [                9       ]]
 
522
        [ 0  1 ]  [ -----  1 ]  [   0    - z - ----- + 8 ]
 
523
                  [ 1 - z    ]  [              1 - z     ]
 
524
(%i11) %[1] . %[2] . %[3];
 
525
                        [ 1 - z    3   ]
 
526
(%o11)                  [              ]
 
527
                        [   3    8 - z ]
 
528
@end example
 
529
 
 
530
@end deffn
 
531
 
 
532
@deffn {Function} mat_cond (@var{M}, 1)
 
533
@deffnx {Function} mat_cond (@var{M}, inf)
 
534
 
 
535
Return the @var{p}-norm matrix condition number of the matrix
 
536
@var{m}. The allowed values for @var{p} are 1 and @var{inf}.  This
 
537
function uses the LU factorization to invert the matrix @var{m}. Thus
 
538
the running time for @code{mat_cond} is proportional to the cube of
 
539
the matrix size; @code{lu_factor} determines lower and upper bounds
 
540
for the infinity norm condition number in time proportional to the
 
541
square of the matrix size.
 
542
 
 
543
@end deffn
 
544
 
 
545
@deffn {Function} mat_norm (@var{M}, 1)
 
546
@deffnx {Function} mat_norm (@var{M}, inf)
 
547
@deffnx {Function} mat_norm (@var{M}, frobenius)
 
548
 
 
549
Return the matrix @var{p}-norm of the matrix @var{M}.  The allowed values for @var{p} are
 
550
1, @code{inf}, and @code{frobenius} (the Frobenius matrix norm). The matrix @var{M} should be
 
551
an unblocked matrix.
 
552
 
 
553
@end deffn
 
554
 
 
555
 
 
556
@deffn {Function} matrix_size (@var{M})
 
557
 
 
558
Return a two member list that gives the number of rows and columns, respectively
 
559
of the matrix @var{M}.
 
560
 
 
561
@end deffn
 
562
 
 
563
@deffn {Function} mat_fullunblocker (@var{M})
 
564
 
 
565
If @var{M} is a block matrix, unblock the matrix to all levels. If @var{M} is a matrix,
 
566
return @var{M}; otherwise, signal an error.  
 
567
 
 
568
@end deffn
 
569
 
 
570
@deffn {Function} mat_trace (@var{M})
 
571
 
 
572
Return the trace of the matrix @var{M} If @var{M} isn't a matrix, return a
 
573
noun form. When @var{M} is a block matrix, @code{mat_trace(M)} returns
 
574
the same value as does @code{mat_trace(mat_unblocker(m))}.
 
575
 
 
576
@end deffn
 
577
 
 
578
@deffn {Function} mat_unblocker (@var{M})
 
579
 
 
580
If @var{M} is a block matrix, unblock @var{M} one level. If @var{M} is a matrix, 
 
581
@code{mat_unblocker (M)} returns @var{M}; otherwise, signal an error.
 
582
 
 
583
Thus if each entry of @var{M} is matrix, @code{mat_unblocker (M)} returns an 
 
584
unblocked matrix, but if each entry of @var{M} is a block matrix, @code{mat_unblocker (M)} 
 
585
returns a block matrix with on less level of blocking.
 
586
 
 
587
If you use block matrices, most likely you'll want to set @code{matrix_element_mult} to 
 
588
@code{"."} and @code{matrix_element_transpose} to @code{'transpose}. See also @code{mat_fullunblocker}.
 
589
 
 
590
Example:
 
591
 
 
592
@c ===beg===
 
593
@c load (linearalgebra);
 
594
@c A : matrix ([1, 2], [3, 4]);
 
595
@c B : matrix ([7, 8], [9, 10]);
 
596
@c matrix ([A, B]);
 
597
@c mat_unblocker (%);
 
598
@c ===end===
 
599
@example
 
600
(%i1) load (linearalgebra);
 
601
Warning - you are redefining the Maxima function require_list
 
602
Warning - you are redefining the Maxima function matrix_size
 
603
Warning - you are redefining the Maxima function rank
 
604
(%o1) /usr/local/share/maxima/5.9.2/share/linearalgebra/linearalgebra.mac
 
605
(%i2) A : matrix ([1, 2], [3, 4]);
 
606
                            [ 1  2 ]
 
607
(%o2)                       [      ]
 
608
                            [ 3  4 ]
 
609
(%i3) B : matrix ([7, 8], [9, 10]);
 
610
                            [ 7  8  ]
 
611
(%o3)                       [       ]
 
612
                            [ 9  10 ]
 
613
(%i4) matrix ([A, B]);
 
614
                     [ [ 1  2 ]  [ 7  8  ] ]
 
615
(%o4)                [ [      ]  [       ] ]
 
616
                     [ [ 3  4 ]  [ 9  10 ] ]
 
617
(%i5) mat_unblocker (%);
 
618
                         [ 1  2  7  8  ]
 
619
(%o5)                    [             ]
 
620
                         [ 3  4  9  10 ]
 
621
@end example
 
622
 
 
623
@end deffn
 
624
 
 
625
@deffn {Function} nonnegintegerp (@var{n})
 
626
 
 
627
Return @code{true} if and only if @code{@var{n} >= 0} and @var{n} is an integer.
 
628
 
 
629
@end deffn
 
630
 
 
631
@deffn {Function} nullspace (@var{M})
 
632
 
 
633
If @var{M} is a matrix, return @code{span (v_1, ..., v_n)}, where the set @code{@{v_1, ..., v_n@}}
 
634
is a basis for the nullspace of @var{M}.  The span of the empty set is @code{@{0@}}.  
 
635
Thus, when the nullspace has only one member, return @code{span ()}.
 
636
 
 
637
@end deffn
 
638
 
 
639
@deffn {Function} nullity (@var{M})
 
640
 
 
641
If @var{M} is a matrix, return the dimension of the nullspace of @var{M}.
 
642
 
 
643
@end deffn
 
644
 
 
645
@deffn {Function} orthogonal_complement (@var{v_1}, ..., @var{v_n})
 
646
 
 
647
Return @code{span (u_1, ..., u_m)}, where the set @code{@{u_1, ..., u_m@}} is a 
 
648
basis for the orthogonal complement of the set @code{(v_1, ..., v_n)}.
 
649
 
 
650
Each vector @var{v_1} through @var{v_n} must be a column vector.
 
651
 
 
652
@end deffn
 
653
 
 
654
@deffn {Function} polynomialp (@var{p}, @var{L}, @var{coeffp}, @var{exponp})
 
655
@deffnx {Function} polynomialp (@var{p}, @var{L}, @var{coeffp})
 
656
@deffnx {Function} polynomialp (@var{p}, @var{L})
 
657
 
 
658
Return true if @var{p} is a polynomial in the variables in the list @var{L},
 
659
The predicate @var{coeffp} must evaluate to @code{true} for each
 
660
coefficient, and the predicate @var{exponp} must evaluate to @code{true} for all 
 
661
exponents of the variables in @var{L}. If you want to use a non-default
 
662
value for @var{exponp}, you must supply @var{coeffp} with a value even if you want
 
663
to use the default for @var{coeffp}.
 
664
 
 
665
@c WORK THE FOLLOWING INTO THE PRECEDING
 
666
@code{polynomialp (@var{p}, @var{L}, @var{coeffp})} is equivalent to
 
667
@code{polynomialp (@var{p}, @var{L}, @var{coeffp}, 'nonnegintegerp)}.
 
668
 
 
669
@code{polynomialp (@var{p}, @var{L})} is equivalent to
 
670
@code{polynomialp (@var{p}, L@var{,} 'constantp, 'nonnegintegerp)}.
 
671
 
 
672
The polynomial needn't be expanded:
 
673
 
 
674
@c ===beg===
 
675
@c load (linearalgebra);
 
676
@c polynomialp ((x + 1)*(x + 2), [x]);
 
677
@c polynomialp ((x + 1)*(x + 2)^a, [x]);
 
678
@c ===end===
 
679
@example
 
680
(%i1) load (linearalgebra);
 
681
Warning - you are redefining the Maxima function require_list
 
682
Warning - you are redefining the Maxima function matrix_size
 
683
Warning - you are redefining the Maxima function rank
 
684
(%o1) /usr/local/share/maxima/5.9.2/share/linearalgebra/linearalgebra.mac
 
685
(%i2) polynomialp ((x + 1)*(x + 2), [x]);
 
686
(%o2)                         true
 
687
(%i3) polynomialp ((x + 1)*(x + 2)^a, [x]);
 
688
(%o3)                         false
 
689
@end example
 
690
 
 
691
An example using non-default values for coeffp and exponp:
 
692
 
 
693
@c ===beg===
 
694
@c load (linearalgebra);
 
695
@c polynomialp ((x + 1)*(x + 2)^(3/2), [x], numberp, numberp);
 
696
@c polynomialp ((x^(1/2) + 1)*(x + 2)^(3/2), [x], numberp, numberp);
 
697
@c ===end===
 
698
@example
 
699
(%i1) load (linearalgebra);
 
700
Warning - you are redefining the Maxima function require_list
 
701
Warning - you are redefining the Maxima function matrix_size
 
702
Warning - you are redefining the Maxima function rank
 
703
(%o1) /usr/local/share/maxima/5.9.2/share/linearalgebra/linearalgebra.mac
 
704
(%i2) polynomialp ((x + 1)*(x + 2)^(3/2), [x], numberp, numberp);
 
705
(%o2)                         true
 
706
(%i3) polynomialp ((x^(1/2) + 1)*(x + 2)^(3/2), [x], numberp, numberp);
 
707
(%o3)                         true
 
708
@end example
 
709
 
 
710
Polynomials with two variables:
 
711
 
 
712
@c ===beg===
 
713
@c load (linearalgebra);
 
714
@c polynomialp (x^2 + 5*x*y + y^2, [x]);
 
715
@c polynomialp (x^2 + 5*x*y + y^2, [x, y]);
 
716
@c ===end===
 
717
@example
 
718
(%i1) load (linearalgebra);
 
719
Warning - you are redefining the Maxima function require_list
 
720
Warning - you are redefining the Maxima function matrix_size
 
721
Warning - you are redefining the Maxima function rank
 
722
(%o1) /usr/local/share/maxima/5.9.2/share/linearalgebra/linearalgebra.mac
 
723
(%i2) polynomialp (x^2 + 5*x*y + y^2, [x]);
 
724
(%o2)                         false
 
725
(%i3) polynomialp (x^2 + 5*x*y + y^2, [x, y]);
 
726
(%o3)                         true
 
727
@end example
 
728
 
 
729
@end deffn
 
730
 
 
731
@deffn {Function} polytocompanion (@var{p}, @var{x})
 
732
 
 
733
If @var{p} is a polynomial in @var{x}, return the companion matrix of @var{p}. For
 
734
a monic polynomial @var{p} of degree @var{n},
 
735
we have @code{@var{p} = (-1)^@var{n} charpoly (polytocompanion (@var{p}, @var{x}))}.
 
736
 
 
737
When @var{p} isn't a polynomial in @var{x}, signal an error.
 
738
 
 
739
@end deffn
 
740
 
 
741
@deffn {Function} ptriangularize (@var{M}, @var{v})
 
742
 
 
743
If @var{M} is a matrix with each entry a polynomial in @var{v}, return 
 
744
a matrix @var{M2} such that
 
745
 
 
746
(1) @var{M2} is upper triangular,
 
747
 
 
748
(2) @code{@var{M2} = @var{E_n} ... @var{E_1} @var{M}},
 
749
where @var{E_1} through @var{E_n} are elementary matrices 
 
750
whose entries are polynomials in @var{v},
 
751
 
 
752
(3) @code{|det (@var{M})| = |det (@var{M2})|},
 
753
 
 
754
Note: This function doesn't check that every entry is a polynomial in @var{v}.  
 
755
 
 
756
@end deffn
 
757
 
 
758
@deffn {Function} rowop (@var{M}, @var{i}, @var{j}, @var{theta})
 
759
 
 
760
If @var{M} is a matrix, return the matrix that results from doing the  
 
761
row operation @code{R_i <- R_i - theta * R_j}. If @var{M} doesn't have a row
 
762
@var{i} or @var{j}, signal an error.
 
763
 
 
764
@end deffn
 
765
 
 
766
@deffn {Function} rank (@var{M})
 
767
 
 
768
Return the rank of that matrix @var{M}. The rank is the dimension of the
 
769
column space. Example:
 
770
@c ===beg===
 
771
@c load (linearalgebra);
 
772
@c 
 
773
@c ===end===
 
774
@example
 
775
(%i1) load(linearalgebra)$
 
776
(%i2) rank(matrix([1,2],[2,4]));
 
777
(%o2) 1
 
778
(%i3) rank(matrix([1,b],[c,d]));
 
779
Proviso:  @{d-b*c # 0@}
 
780
(%o3) 2
 
781
@end example
 
782
 
 
783
@end deffn
 
784
 
 
785
 
 
786
@deffn {Function} rowswap (@var{M}, @var{i}, @var{j})
 
787
 
 
788
If @var{M} is a matrix, swap rows @var{i} and @var{j}. If @var{M} doesn't have a row
 
789
@var{i} or @var{j}, signal an error.
 
790
 
 
791
@end deffn
 
792
 
 
793
@deffn {Function} toeplitz (@var{col})
 
794
@deffnx {Function} toeplitz (@var{col}, @var{row})
 
795
 
 
796
Return a Toeplitz matrix @var{T}. The first first column of @var{T} is @var{col};
 
797
except for the first entry, the first row of @var{T} is @var{row}. The
 
798
default for @var{row} is complex conjugate of @var{col}. Example:
 
799
@c ===beg===
 
800
@c load(linearalgebra)$
 
801
@c toeplitz([1,2,3],[x,y,z]);
 
802
@c toeplitz([1,1+%i]);
 
803
@c ==end===
 
804
@example
 
805
(%i1) load(linearalgebra)$
 
806
 
 
807
(%i2)  toeplitz([1,2,3],[x,y,z]);
 
808
 
 
809
                                  [ 1  y  z ]
 
810
                                  [         ]
 
811
(%o2)                             [ 2  1  y ]
 
812
                                  [         ]
 
813
                                  [ 3  2  1 ]
 
814
(%i3)  toeplitz([1,1+%i]);
 
815
 
 
816
                              [   1     1 - %I ]
 
817
(%o3)                         [                ]
 
818
                              [ %I + 1    1    ]
 
819
@end example
 
820
 
 
821
@end deffn
 
822
 
 
823
@deffn {Function} vandermonde_matrix ([@var{x_1}, ..., @var{x_n}])
 
824
 
 
825
Return a @var{n} by @var{n} matrix whose @var{i}-th row is 
 
826
@code{[1, @var{x_i}, @var{x_i}^2, ... @var{x_i}^(@var{n}-1)]}. 
 
827
 
 
828
@end deffn
 
829
 
 
830
@deffn {Function} zerofor (@var{M})
 
831
@deffnx {Function}  zerofor (@var{M}, @var{fld})
 
832
 
 
833
Return a zero  matrix that has the same shape as the matrix
 
834
@var{M}.  Every entry of the zero matrix matrix is the
 
835
additive identity of the field @var{fld}; the default for
 
836
@var{fld} is @var{generalring}.
 
837
 
 
838
The first argument @var{M} should be a square matrix or a
 
839
non-matrix. When @var{M} is a matrix, each entry of @var{M} can be a
 
840
square matrix -- thus @var{M} can be a blocked Maxima matrix. The
 
841
matrix can be blocked to any (finite) depth.
 
842
 
 
843
See also @code{identfor}
 
844
 
 
845
@end deffn
 
846
 
 
847
@deffn {Function} zeromatrixp (@var{M})
 
848
 
 
849
If @var{M} is not a block matrix, return @code{true} if @code{is (equal (@var{e}, 0))} 
 
850
is true for each element @var{e} of the matrix @var{M}.  If @var{M} is a block matrix, return
 
851
@code{true} if @code{zeromatrixp} evaluates to true for each element of @var{e}.
 
852
 
 
853
@end deffn
 
854
 
 
855
@node Function and variable index,  , Definitions for linearalgebra, Top
 
856
@appendix Function and variable index
 
857
@printindex fn
 
858
@printindex vr
 
859
 
 
860
@bye