2 * Introduction to Matrices and Linear Algebra::
3 * Functions and Variables for Matrices and Linear Algebra::
6 @c -----------------------------------------------------------------------------
7 @node Introduction to Matrices and Linear Algebra, Functions and Variables for Matrices and Linear Algebra, Matrices and Linear Algebra, Matrices and Linear Algebra
8 @section Introduction to Matrices and Linear Algebra
9 @c -----------------------------------------------------------------------------
18 @c -----------------------------------------------------------------------------
19 @node Dot, Matrices, Introduction to Matrices and Linear Algebra, Introduction to Matrices and Linear Algebra
21 @c -----------------------------------------------------------------------------
23 The operator @code{.} represents noncommutative multiplication and scalar
24 product. When the operands are 1-column or 1-row matrices @code{a} and
25 @code{b}, the expression @code{a.b} is equivalent to
26 @code{sum (a[i]*b[i], i, 1, length(a))}. If @code{a} and @code{b} are not
27 complex, this is the scalar product, also called the inner product or dot
28 product, of @code{a} and @code{b}. The scalar product is defined as
29 @code{conjugate(a).b} when @code{a} and @code{b} are complex;
30 @mref{innerproduct} in the @code{eigen} package provides the complex scalar
33 When the operands are more general matrices,
34 the product is the matrix product @code{a} and @code{b}.
35 The number of rows of @code{b} must equal the number of columns of @code{a},
36 and the result has number of rows equal to the number of rows of @code{a}
37 and number of columns equal to the number of columns of @code{b}.
39 To distinguish @code{.} as an arithmetic operator from the decimal point in a
40 floating point number, it may be necessary to leave spaces on either side.
41 For example, @code{5.e3} is @code{5000.0} but @code{5 . e3} is @code{5}
44 There are several flags which govern the simplification of expressions
45 involving @code{.}, namely @mrefcomma{dot0nscsimp} @mrefcomma{dot0simp}@w{}
46 @mrefcomma{dot1simp} @mrefcomma{dotassoc} @mrefcomma{dotconstrules}@w{}
47 @mrefcomma{dotdistrib} @mrefcomma{dotexptsimp} @mrefcomma{dotident} and
50 @c -----------------------------------------------------------------------------
51 @node Matrices, Vectors, Dot, Introduction to Matrices and Linear Algebra
53 @c -----------------------------------------------------------------------------
54 Matrices are handled with speed and memory-efficiency in mind. This means that
55 assigning a matrix to a variable will create a reference to, not a copy of the
56 matrix. If the matrix is modified all references to the matrix point to the
57 modified object (See @mref{copymatrix} for a way of avoiding this):
59 @c M1: matrix([0,0],[0,0]);
66 (%i1) M1: matrix([0,0],[0,0]);
89 Converting a matrix to nested lists and vice versa works the following way:
92 @c M1: apply('matrix,l);
98 (%i1) l: [[1,2],[3,4]];
99 (%o1) [[1, 2], [3, 4]]
102 (%i2) M1: apply('matrix,l);
108 (%i3) M2: transpose(M1);
115 (%o4) [[1, 3], [2, 4]]
118 @c -----------------------------------------------------------------------------
119 @node Vectors, eigen, Matrices, Introduction to Matrices and Linear Algebra
121 @c -----------------------------------------------------------------------------
123 @code{vect} is a package of functions for vector analysis. @code{load ("vect")}
124 loads this package, and @code{demo ("vect")} displays a demonstration.
125 @c find maxima -name \*orth\* YIELDS NOTHING; ARE THESE FUNCTIONS IN ANOTHER FILE NOW ??
126 @c and SHARE;VECT ORTH contains definitions of various orthogonal curvilinear coordinate systems.
128 The vector analysis package can combine and simplify symbolic
129 expressions including dot products and cross products, together with
130 the gradient, divergence, curl, and Laplacian operators. The
131 distribution of these operators over sums or products is governed
132 by several flags, as are various other expansions, including expansion
133 into components in any specific orthogonal coordinate systems.
134 There are also functions for deriving the scalar or vector potential
137 The @code{vect} package contains these functions:
138 @mrefcomma{vectorsimp} @mrefcomma{scalefactors} @mrefcomma{express}@w{}
139 @mrefcomma{potential} and @mrefdot{vectorpotential}
140 @c REVIEW vect.usg TO ENSURE THAT TEXINFO HAS WHATEVER IS THERE
141 @c PRINTFILE(VECT,USAGE,SHARE); for details.
143 By default the @code{vect} package does not declare the dot operator to be a
144 commutative operator. To get a commutative dot operator @code{.}, the command
145 @code{declare(".", commutative)} must be executed.
147 @opencatbox{Categories:}
149 @category{Share packages}
150 @category{Package vect}
153 @c -----------------------------------------------------------------------------
154 @node eigen, , Vectors, Introduction to Matrices and Linear Algebra
156 @c -----------------------------------------------------------------------------
158 The package @code{eigen} contains several functions devoted to the
159 symbolic computation of eigenvalues and eigenvectors.
160 Maxima loads the package automatically if one of the functions
161 @code{eigenvalues} or @code{eigenvectors} is invoked.
162 The package may be loaded explicitly as @code{load ("eigen")}.
164 @code{demo ("eigen")} displays a demonstration of the capabilities
166 @code{batch ("eigen")} executes the same demonstration,
167 but without the user prompt between successive computations.
169 The functions in the @code{eigen} package are:@*
170 @mrefcomma{innerproduct} @mrefcomma{unitvector} @mrefcomma{columnvector}@w{}
171 @mrefcomma{gramschmidt} @mrefcomma{eigenvalues}@*
172 @mrefcomma{eigenvectors} @mrefcomma{uniteigenvectors} and
173 @mrefdot{similaritytransform}
175 @opencatbox{Categories:}
178 @category{Share packages}
179 @category{Package eigen}
182 @c end concepts Matrices and Linear Algebra
184 @c -----------------------------------------------------------------------------
185 @node Functions and Variables for Matrices and Linear Algebra, , Introduction to Matrices and Linear Algebra, Matrices and Linear Algebra
186 @section Functions and Variables for Matrices and Linear Algebra
187 @c -----------------------------------------------------------------------------
189 @c -----------------------------------------------------------------------------
191 @deffn {Function} addcol (@var{M}, @var{list_1}, @dots{}, @var{list_n})
193 Appends the column(s) given by the one
194 or more lists (or matrices) onto the matrix @var{M}.
196 See also @mref{addrow} and @mrefdot{append}
198 @opencatbox{Categories:}
203 @c -----------------------------------------------------------------------------
205 @deffn {Function} addrow (@var{M}, @var{list_1}, @dots{}, @var{list_n})
207 Appends the row(s) given by the one or
208 more lists (or matrices) onto the matrix @var{M}.
210 See also @mref{addcol} and @mrefdot{append}
212 @opencatbox{Categories:}
217 @c -----------------------------------------------------------------------------
219 @deffn {Function} adjoint (@var{M})
221 Returns the adjoint of the matrix @var{M}.
222 The adjoint matrix is the transpose of the matrix of cofactors of @var{M}.
224 @opencatbox{Categories:}
229 @c -----------------------------------------------------------------------------
230 @anchor{augcoefmatrix}
231 @deffn {Function} augcoefmatrix ([@var{eqn_1}, @dots{}, @var{eqn_m}], [@var{x_1}, @dots{}, @var{x_n}])
233 Returns the augmented coefficient
234 matrix for the variables @var{x_1}, @dots{}, @var{x_n} of the system of linear
235 equations @var{eqn_1}, @dots{}, @var{eqn_m}. This is the coefficient matrix
236 with a column adjoined for the constant terms in each equation (i.e., those
237 terms not dependent upon @var{x_1}, @dots{}, @var{x_n}).
240 (%i1) m: [2*x - (a - 1)*y = 5*b, c + b*y + a*x = 0]$
241 (%i2) augcoefmatrix (m, [x, y]);
247 @opencatbox{Categories:}
248 @category{Linear equations}
253 @c --- 04.10.2010 --------------------------------------------------------------
254 @anchor{cauchy_matrix}
255 @deffn {Function} cauchy_matrix @
256 @fname{cauchy_matrix} ([@var{x_1}, @var{x_2}, @dots{}, @var{x_m}], [@var{y_1}, @var{y_2}, @dots{}, @var{y_n}]) @
257 @fname{cauchy_matrix} ([@var{x_1}, @var{x_2}, @dots{}, @var{x_n}])
259 Returns a @code{n} by @var{m} Cauchy matrix with the elements @var{a[i,j]}
260 = 1/(@var{x_i}+@var{y_i}). The second argument of @code{cauchy_matrix} is
261 optional. For this case the elements of the Cauchy matrix are
262 @var{a[i,j]} = 1/(@var{x_i}+@var{x_j}).
264 Remark: In the literature the Cauchy matrix can be found defined in two forms.
265 A second definition is @var{a[i,j]} = 1/(@var{x_i}-@var{y_i}).
270 @c cauchy_matrix([x1, x2], [y1, y2]);
271 @c cauchy_matrix([x1, x2]);
274 (%i1) cauchy_matrix([x1, x2], [y1, y2]);
285 (%i2) cauchy_matrix([x1, x2]);
295 @opencatbox{Categories:}
300 @c -----------------------------------------------------------------------------
302 @deffn {Function} charpoly (@var{M}, @var{x})
304 Returns the characteristic polynomial for the matrix @var{M}
305 with respect to variable @var{x}. That is,
306 @code{determinant (@var{M} - diagmatrix (length (@var{M}), @var{x}))}.
309 (%i1) a: matrix ([3, 1], [2, 4]);
313 (%i2) expand (charpoly (a, lambda));
315 (%o2) lambda - 7 lambda + 10
316 (%i3) (programmode: true, solve (%));
317 (%o3) [lambda = 5, lambda = 2]
318 (%i4) matrix ([x1], [x2]);
322 (%i5) ev (a . % - lambda*%, %th(2)[1]);
328 (%i7) x2^2 + x1^2 = 1;
331 (%i8) solve ([%th(2), %], [x1, x2]);
334 (%o8) [[x1 = - -------, x2 = - -------],
338 [x1 = -------, x2 = -------]]
343 @opencatbox{Categories:}
348 @c -----------------------------------------------------------------------------
350 @deffn {Function} coefmatrix ([@var{eqn_1}, @dots{}, @var{eqn_m}], [@var{x_1}, @dots{}, @var{x_n}])
352 Returns the coefficient matrix for the
353 variables @var{x_1}, @dots{}, @var{x_n} of the system of linear equations
354 @var{eqn_1}, @dots{}, @var{eqn_m}.
357 (%i1) coefmatrix([2*x-(a-1)*y+5*b = 0, b*y+a*x = 3], [x,y]);
363 @opencatbox{Categories:}
364 @category{Linear equations}
369 @c -----------------------------------------------------------------------------
371 @deffn {Function} col (@var{M}, @var{i})
373 Returns the @var{i}'th column of the matrix @var{M}.
374 The return value is a matrix.
377 @opencatbox{Categories:}
382 @c -----------------------------------------------------------------------------
383 @anchor{columnvector}
385 @deffn {Function} columnvector (@var{L})
386 @deffnx {Function} covect (@var{L})
388 Returns a matrix of one column and @code{length (@var{L})} rows,
389 containing the elements of the list @var{L}.
391 @code{covect} is a synonym for @code{columnvector}.
393 @code{load ("eigen")} loads this function.
395 @c FOLLOWING COMMENT PRESERVED. WHAT DOES THIS MEAN ??
396 This is useful if you want to use parts of the outputs of
397 the functions in this package in matrix calculations.
401 @c HMM, SPURIOUS "redefining the Macsyma function".
402 @c LEAVE IT HERE SINCE THAT'S WHAT A USER ACTUALLY SEES.
404 (%i1) load ("eigen")$
405 Warning - you are redefining the Macsyma function eigenvalues
406 Warning - you are redefining the Macsyma function eigenvectors
407 (%i2) columnvector ([aa, bb, cc, dd]);
417 @opencatbox{Categories:}
422 @c -----------------------------------------------------------------------------
424 @deffn {Function} copymatrix (@var{M})
426 Returns a copy of the matrix @var{M}. This is the only way
427 to make a copy aside from copying @var{M} element by element.
429 Note that an assignment of one matrix to another, as in @code{m2: m1}, does not
430 copy @code{m1}. An assignment @code{m2 [i,j]: x} or @code{setelmx(x, i, j, m2)}
431 also modifies @code{m1 [i,j]}. Creating a copy with @code{copymatrix} and then
432 using assignment creates a separate, modified copy.
435 @opencatbox{Categories:}
440 @c -----------------------------------------------------------------------------
442 @deffn {Function} determinant (@var{M})
444 Computes the determinant of @var{M} by a method similar to
445 Gaussian elimination.
447 @c JUST HOW DOES ratmx AFFECT THE RESULT ??
448 The form of the result depends upon the setting of the switch @mrefdot{ratmx}
450 @c IS A SPARSE DETERMINANT SOMETHING OTHER THAN THE DETERMINANT OF A SPARSE MATRIX ??
451 There is a special routine for computing sparse determinants which is called
452 when the switches @code{ratmx} and @mref{sparse} are both @code{true}.
454 @c EXAMPLES NEEDED HERE
455 @opencatbox{Categories:}
460 @c -----------------------------------------------------------------------------
462 @defvr {Option variable} detout
463 Default value: @code{false}
465 When @code{detout} is @code{true}, the determinant of a
466 matrix whose inverse is computed is factored out of the inverse.
468 For this switch to have an effect @mref{doallmxops} and @mref{doscmxops} should
469 be @code{false} (see their descriptions). Alternatively this switch can be
470 given to @mref{ev} which causes the other two to be set correctly.
475 (%i1) m: matrix ([a, b], [c, d]);
480 (%i3) doallmxops: false$
481 (%i4) doscmxops: false$
489 @c THERE'S MORE TO THIS STORY: detout: false$ invert (m); RETURNS THE SAME THING.
490 @c IT APPEARS THAT doallmxops IS CRUCIAL HERE.
492 @opencatbox{Categories:}
494 @category{Evaluation flags}
498 @c -----------------------------------------------------------------------------
500 @deffn {Function} diagmatrix (@var{n}, @var{x})
502 Returns a diagonal matrix of size @var{n} by @var{n} with the diagonal elements
503 all equal to @var{x}. @code{diagmatrix (@var{n}, 1)} returns an identity matrix
504 (same as @code{ident (@var{n})}).
506 @var{n} must evaluate to an integer, otherwise @code{diagmatrix} complains with
509 @var{x} can be any kind of expression, including another matrix. If @var{x} is
510 a matrix, it is not copied; all diagonal elements refer to the same instance,
514 @opencatbox{Categories:}
519 @c -----------------------------------------------------------------------------
521 @defvr {Option variable} doallmxops
522 Default value: @code{true}
524 When @code{doallmxops} is @code{true},
525 @c UMM, WHAT DOES THIS MEAN EXACTLY ??
526 all operations relating to matrices are carried out.
527 When it is @code{false} then the setting of the
528 individual @code{dot} switches govern which operations are performed.
530 @c NEED EXAMPLES HERE
531 @opencatbox{Categories:}
536 @c -----------------------------------------------------------------------------
538 @defvr {Option variable} domxexpt
539 Default value: @code{true}
541 When @code{domxexpt} is @code{true},
542 a matrix exponential, @code{exp (@var{M})} where @var{M} is a matrix, is
543 interpreted as a matrix with element @code{[i,j]} equal to @code{exp (m[i,j])}.
544 Otherwise @code{exp (@var{M})} evaluates to @code{exp (@var{ev(M)})}.
546 @code{domxexpt} affects all expressions of the form
547 @code{@var{base}^@var{power}} where @var{base} is an expression assumed scalar
548 or constant, and @var{power} is a list or matrix.
553 (%i1) m: matrix ([1, %i], [a+b, %pi]);
557 (%i2) domxexpt: false$
563 (%i4) domxexpt: true$
572 @opencatbox{Categories:}
577 @c -----------------------------------------------------------------------------
579 @defvr {Option variable} domxmxops
580 Default value: @code{true}
582 When @code{domxmxops} is @code{true}, all matrix-matrix or
583 matrix-list operations are carried out (but not scalar-matrix
584 operations); if this switch is @code{false} such operations are not carried out.
585 @c IS THIS AN EVALUATION OR A SIMPLIFICATION FLAG ??
588 @opencatbox{Categories:}
593 @c -----------------------------------------------------------------------------
595 @defvr {Option variable} domxnctimes
596 Default value: @code{false}
598 When @code{domxnctimes} is @code{true}, non-commutative products of
599 matrices are carried out.
600 @c IS THIS AN EVALUATION OR A SIMPLIFICATION FLAG ??
603 @opencatbox{Categories:}
608 @c -----------------------------------------------------------------------------
610 @defvr {Option variable} dontfactor
611 Default value: @code{[]}
613 @code{dontfactor} may be set to a list of variables with respect to which
614 factoring is not to occur. (The list is initially empty.) Factoring also will
615 not take place with respect to any variables which are less important, according
616 the variable ordering assumed for canonical rational expression (CRE) form, than
617 those on the @code{dontfactor} list.
619 @opencatbox{Categories:}
620 @category{Expressions}
624 @c -----------------------------------------------------------------------------
626 @defvr {Option variable} doscmxops
627 Default value: @code{false}
629 When @code{doscmxops} is @code{true}, scalar-matrix operations are
631 @c IS THIS AN EVALUATION OR A SIMPLIFICATION FLAG ??
634 @opencatbox{Categories:}
639 @c -----------------------------------------------------------------------------
641 @defvr {Option variable} doscmxplus
642 Default value: @code{false}
644 When @code{doscmxplus} is @code{true}, scalar-matrix operations yield
645 a matrix result. This switch is not subsumed under @mrefdot{doallmxops}
646 @c IS THIS AN EVALUATION OR A SIMPLIFICATION FLAG ??
649 @opencatbox{Categories:}
654 @c -----------------------------------------------------------------------------
656 @defvr {Option variable} dot0nscsimp
657 Default value: @code{true}
659 @c WHAT DOES THIS MEAN EXACTLY ??
660 When @code{dot0nscsimp} is @code{true}, a non-commutative product of zero
661 and a nonscalar term is simplified to a commutative product.
664 @opencatbox{Categories:}
665 @category{Simplification flags and variables}
669 @c -----------------------------------------------------------------------------
671 @defvr {Option variable} dot0simp
672 Default value: @code{true}
674 @c WHAT DOES THIS MEAN EXACTLY ??
675 When @code{dot0simp} is @code{true},
676 a non-commutative product of zero and
677 a scalar term is simplified to a commutative product.
680 @opencatbox{Categories:}
681 @category{Simplification flags and variables}
685 @c -----------------------------------------------------------------------------
687 @defvr {Option variable} dot1simp
688 Default value: @code{true}
690 @c WHAT DOES THIS MEAN EXACTLY ??
691 When @code{dot1simp} is @code{true},
692 a non-commutative product of one and
693 another term is simplified to a commutative product.
696 @opencatbox{Categories:}
697 @category{Simplification flags and variables}
701 @c -----------------------------------------------------------------------------
703 @defvr {Option variable} dotassoc
704 Default value: @code{true}
706 When @code{dotassoc} is @code{true}, an expression @code{(A.B).C} simplifies to
708 @c "." MEANS NONCOMMUTATIVE MULTIPLICATION RIGHT ??
711 @opencatbox{Categories:}
712 @category{Simplification flags and variables}
716 @c -----------------------------------------------------------------------------
717 @anchor{dotconstrules}
718 @defvr {Option variable} dotconstrules
719 Default value: @code{true}
721 When @code{dotconstrules} is @code{true}, a non-commutative product of a
722 constant and another term is simplified to a commutative product.
723 @c TERMINOLOGY: (1) SWITCH/FLAG/SOME OTHER TERM ??
724 @c (2) ASSIGN/SET/TURN ON/SOME OTHER TERM ??
725 Turning on this flag effectively turns on @mrefcomma{dot0simp}@w{}
726 @mrefcomma{dot0nscsimp} and @mref{dot1simp} as well.
729 @opencatbox{Categories:}
730 @category{Simplification flags and variables}
734 @c -----------------------------------------------------------------------------
736 @defvr {Option variable} dotdistrib
737 Default value: @code{false}
739 When @code{dotdistrib} is @code{true}, an expression @code{A.(B + C)} simplifies
743 @opencatbox{Categories:}
744 @category{Simplification flags and variables}
748 @c -----------------------------------------------------------------------------
750 @defvr {Option variable} dotexptsimp
751 Default value: @code{true}
753 When @code{dotexptsimp} is @code{true}, an expression @code{A.A} simplifies to
757 @opencatbox{Categories:}
758 @category{Simplification flags and variables}
762 @c -----------------------------------------------------------------------------
764 @defvr {Option variable} dotident
767 @code{dotident} is the value returned by @code{X^^0}.
768 @c "RETURNED" ?? IS THIS A SIMPLIFICATION OR AN EVALUATION ??
771 @opencatbox{Categories:}
772 @category{Simplification flags and variables}
776 @c -----------------------------------------------------------------------------
778 @defvr {Option variable} dotscrules
779 Default value: @code{false}
781 When @code{dotscrules} is @code{true}, an expression @code{A.SC} or @code{SC.A}
782 simplifies to @code{SC*A} and @code{A.(SC*B)} simplifies to @code{SC*(A.B)}.
783 @c HMM, DOES "SC" MEAN "SCALAR" HERE ?? CLARIFY
786 @opencatbox{Categories:}
787 @category{Simplification flags and variables}
791 @c -----------------------------------------------------------------------------
793 @deffn {Function} echelon (@var{M})
795 Returns the echelon form of the matrix @var{M},
796 as produced by Gaussian elimination.
797 The echelon form is computed from @var{M}
798 by elementary row operations such that the first
799 non-zero element in each row in the resulting matrix is one and the
800 column elements under the first one in each row are all zero.
802 @mref{triangularize} also carries out Gaussian elimination, but it does not
803 normalize the leading non-zero element in each row.
805 @mref{lu_factor} and @mref{cholesky} are other functions which yield
806 triangularized matrices.
809 @c M: matrix ([3, 7, aa, bb], [-1, 8, 5, 2], [9, 2, 11, 4]);
814 (%i1) M: matrix ([3, 7, aa, bb], [-1, 8, 5, 2], [9, 2, 11, 4]);
830 [ 0 0 1 ----------- ]
835 @opencatbox{Categories:}
836 @category{Linear equations}
841 @c -----------------------------------------------------------------------------
844 @deffn {Function} eigenvalues (@var{M})
845 @deffnx {Function} eivals (@var{M})
847 @c eigen.mac IS AUTOLOADED IF eigenvalues OR eigenvectors IS REFERENCED; EXTEND THAT TO ALL FUNCTIONS ??
848 @c EACH FUNCTION INTENDED FOR EXTERNAL USE SHOULD HAVE ITS OWN DOCUMENTATION ITEM
849 Returns a list of two lists containing the eigenvalues of the matrix @var{M}.
850 The first sublist of the return value is the list of eigenvalues of the
851 matrix, and the second sublist is the list of the
852 multiplicities of the eigenvalues in the corresponding order.
854 @code{eivals} is a synonym for @code{eigenvalues}.
856 @code{eigenvalues} calls the function @mref{solve} to find the roots of the
857 characteristic polynomial of the matrix. Sometimes @code{solve} may not be able
858 to find the roots of the polynomial; in that case some other functions in this
859 package (except @mrefcomma{innerproduct} @mrefcomma{unitvector}@w{}
860 @mref{columnvector} and @mref{gramschmidt}) will not work.
861 @c WHICH ONES ARE THE FUNCTIONS WHICH DON'T WORK ??
862 @c ACTUALLY IT'S MORE IMPORTANT TO LIST THE ONES WHICH DON'T WORK HERE
863 @c WHAT DOES "will not work" MEAN, ANYWAY ??
864 Sometimes @code{solve} may find only a subset of the roots of the polynomial.
865 This may happen when the factoring of the polynomial contains polynomials
866 of degree 5 or more. In such cases a warning message is displayed and the
867 only the roots found and their corresponding multiplicities are returned.
869 In some cases the eigenvalues found by @code{solve} may be complicated
870 expressions. (This may happen when @code{solve} returns a not-so-obviously real
871 expression for an eigenvalue which is known to be real.) It may be possible to
872 simplify the eigenvalues using some other functions.
873 @c WHAT ARE THOSE OTHER FUNCTIONS ??
875 The package @code{eigen.mac} is loaded automatically when
876 @code{eigenvalues} or @mref{eigenvectors} is referenced.
877 If @code{eigen.mac} is not already loaded,
878 @code{load ("eigen")} loads it.
879 After loading, all functions and variables in the package are available.
880 @c REFER TO OVERVIEW OF PACKAGE (INCLUDING LIST OF FUNCTIONS) HERE
882 @c NEED EXAMPLES HERE
883 @opencatbox{Categories:}
884 @category{Package eigen}
888 @c -----------------------------------------------------------------------------
889 @anchor{eigenvectors}
891 @deffn {Function} eigenvectors (@var{M})
892 @deffnx {Function} eivects (@var{M})
894 Computes eigenvectors of the matrix @var{M}.
895 The return value is a list of two elements.
896 The first is a list of the eigenvalues of @var{M}
897 and a list of the multiplicities of the eigenvalues.
898 The second is a list of lists of eigenvectors.
899 There is one list of eigenvectors for each eigenvalue.
900 There may be one or more eigenvectors in each list.
902 @code{eivects} is a synonym for @code{eigenvectors}.
904 The package @code{eigen.mac} is loaded automatically when
905 @mref{eigenvalues} or @code{eigenvectors} is referenced.
906 If @code{eigen.mac} is not already loaded,
907 @code{load ("eigen")} loads it.
908 After loading, all functions and variables in the package are available.
910 Note that @code{eigenvectors} internally calls @code{eigenvalues} to
911 obtain eigenvalues. So, when @code{eigenvalues} returns a subset of
912 all the eigenvalues, the @code{eigenvectors} returns the corresponding
913 subset of the all the eigenvectors, with the same warning displayed as
916 The flags that affect this function are:
918 @code{nondiagonalizable} is set to @code{true} or @code{false} depending on
919 whether the matrix is nondiagonalizable or diagonalizable after
920 @code{eigenvectors} returns.
922 @code{hermitianmatrix} when @code{true}, causes the degenerate
923 eigenvectors of the Hermitian matrix to be orthogonalized using the
924 Gram-Schmidt algorithm.
926 @code{knowneigvals} when @code{true} causes the @code{eigen} package to assume
927 the eigenvalues of the matrix are known to the user and stored under the global
928 name @code{listeigvals}. @code{listeigvals} should be set to a list similar
929 to the output @code{eigenvalues}.
931 The function @mref{algsys} is used here to solve for the eigenvectors.
932 Sometimes if the eigenvalues are messy, @code{algsys} may not be able to find a
933 solution. In some cases, it may be possible to simplify the eigenvalues by
934 first finding them using @code{eigenvalues} command and then using other
935 functions to reduce them to something simpler. Following simplification,
936 @code{eigenvectors} can be called again with the @code{knowneigvals} flag set
939 See also @mrefdot{eigenvalues}
943 A matrix which has just one eigenvector per eigenvalue.
946 @c M1: matrix ([11, -1], [1, 7]);
947 @c [vals, vecs] : eigenvectors (M1);
948 @c for i thru length (vals[1]) do disp (val[i] = vals[1][i],
949 @c mult[i] = vals[2][i], vec[i] = vecs[i]);
953 (%i1) M1: matrix ([11, -1], [1, 7]);
959 (%i2) [vals, vecs] : eigenvectors (M1);
960 (%o2) [[[9 - sqrt(3), sqrt(3) + 9], [1, 1]],
961 [[[1, sqrt(3) + 2]], [[1, 2 - sqrt(3)]]]]
964 (%i3) for i thru length (vals[1]) do disp (val[i] = vals[1][i],
965 mult[i] = vals[2][i], vec[i] = vecs[i]);
972 vec = [[1, sqrt(3) + 2]]
981 vec = [[1, 2 - sqrt(3)]]
988 A matrix which has two eigenvectors for one eigenvalue (namely 2).
991 @c M1 : matrix ([0, 1, 0, 0], [0, 0, 0, 0], [0, 0, 2, 0], [0, 0, 0, 2]);
992 @c [vals, vecs] : eigenvectors (M1);
993 @c for i thru length (vals[1]) do disp (val[i] = vals[1][i],
994 @c mult[i] = vals[2][i], vec[i] = vecs[i]);
998 (%i1) M1: matrix ([0, 1, 0, 0], [0, 0, 0, 0], [0, 0, 2, 0],
1009 (%i2) [vals, vecs]: eigenvectors (M1);
1010 (%o2) [[[0, 2], [2, 2]], [[[1, 0, 0, 0]],
1011 [[0, 0, 1, 0], [0, 0, 0, 1]]]]
1014 (%i3) for i thru length (vals[1]) do disp (val[i] = vals[1][i],
1015 mult[i] = vals[2][i], vec[i] = vecs[i]);
1022 vec = [[1, 0, 0, 0]]
1031 vec = [[0, 0, 1, 0], [0, 0, 0, 1]]
1038 @opencatbox{Categories:}
1039 @category{Package eigen}
1043 @c -----------------------------------------------------------------------------
1045 @deffn {Function} ematrix (@var{m}, @var{n}, @var{x}, @var{i}, @var{j})
1047 Returns an @var{m} by @var{n} matrix, all elements of which
1048 are zero except for the @code{[@var{i}, @var{j}]} element which is @var{x}.
1049 @c WOW, THAT SEEMS PRETTY SPECIALIZED ...
1051 @opencatbox{Categories:}
1056 @c -----------------------------------------------------------------------------
1057 @anchor{entermatrix}
1058 @deffn {Function} entermatrix (@var{m}, @var{n})
1060 Returns an @var{m} by @var{n} matrix, reading the elements interactively.
1062 If @var{n} is equal to @var{m}, Maxima prompts for the type of the matrix
1063 (diagonal, symmetric, antisymmetric, or general) and for each element.
1064 Each response is terminated by a semicolon @code{;} or dollar sign @code{$}.
1066 If @var{n} is not equal to @var{m},
1067 Maxima prompts for each element.
1069 The elements may be any expressions, which are evaluated.
1070 @code{entermatrix} evaluates its arguments.
1074 (%i2) m: entermatrix (n, n)$
1076 Is the matrix 1. Diagonal 2. Symmetric 3. Antisymmetric
1078 Answer 1, 2, 3 or 4 :
1099 @opencatbox{Categories:}
1100 @category{Console interaction}
1105 @c -----------------------------------------------------------------------------
1107 @deffn {Function} genmatrix @
1108 @fname{genmatrix} (@var{a}, @var{i_2}, @var{j_2}, @var{i_1}, @var{j_1}) @
1109 @fname{genmatrix} (@var{a}, @var{i_2}, @var{j_2}, @var{i_1}) @
1110 @fname{genmatrix} (@var{a}, @var{i_2}, @var{j_2})
1112 Returns a matrix generated from @var{a}, taking element
1113 @code{@var{a}[@var{i_1}, @var{j_1}]} as the upper-left element and
1114 @code{@var{a}[@var{i_2}, @var{j_2}]} as the lower-right element of the matrix.
1115 Here @var{a} is a declared array (created by @code{array} but not by
1116 @mref{make_array}) or a @mrefcomma{hashed array} or a @mrefcomma{memoizing function} or a lambda
1117 expression of two arguments. (A @mref{memoizing function} is created like other functions
1118 with @mref{:=} or @mrefcomma{define} but arguments are enclosed in square
1119 brackets instead of parentheses.)
1121 If @var{j_1} is omitted, it is assumed equal to @var{i_1}.
1122 If both @var{j_1} and @var{i_1} are omitted, both are assumed equal to 1.
1124 If a selected element @code{i,j} of the array is undefined,
1125 the matrix will contain a symbolic element @code{@var{a}[i,j]}.
1130 @c h [i, j] := 1 / (i + j - 1);
1131 @c genmatrix (h, 3, 3);
1132 @c array (a, fixnum, 2, 2);
1135 @c genmatrix (a, 2, 2);
1136 @c genmatrix (lambda ([i, j], j - i), 3, 3);
1137 @c genmatrix (B, 2, 2);
1141 (%i1) h [i, j] := 1 / (i + j - 1);
1143 (%o1) h := ---------
1147 (%i2) genmatrix (h, 3, 3);
1161 (%i3) array (a, fixnum, 2, 2);
1165 (%i4) a [1, 1] : %e;
1169 (%i5) a [2, 2] : %pi;
1173 (%i6) genmatrix (a, 2, 2);
1179 (%i7) genmatrix (lambda ([i, j], j - i), 3, 3);
1187 (%i8) genmatrix (B, 2, 2);
1196 @opencatbox{Categories:}
1201 @c -----------------------------------------------------------------------------
1202 @anchor{gramschmidt}
1203 @deffn {Function} gramschmidt @
1204 @fname{gramschmidt} (@var{x}) @
1205 @fname{gramschmidt} (@var{x}, @var{F})
1207 Carries out the Gram-Schmidt orthogonalization algorithm on @var{x}, which is
1208 either a matrix or a list of lists. @var{x} is not modified by
1209 @code{gramschmidt}. The inner product employed by @code{gramschmidt} is
1210 @var{F}, if present, otherwise the inner product is the function
1211 @mrefdot{innerproduct}
1213 If @var{x} is a matrix, the algorithm is applied to the rows of @var{x}. If
1214 @var{x} is a list of lists, the algorithm is applied to the sublists, which must
1215 have equal numbers of elements. In either case, the return value is a list of
1216 lists, the sublists of which are orthogonal and span the same space as @var{x}.
1217 If the dimension of the span of @var{x} is less than the number of rows or
1218 sublists, some sublists of the return value are zero.
1220 @mref{factor} is called at each stage of the algorithm to simplify intermediate
1221 results. As a consequence, the return value may contain factored integers.
1223 @code{load("eigen")} loads this function.
1227 Gram-Schmidt algorithm using default inner product function.
1231 @c x: matrix ([1, 2, 3], [9, 18, 30], [12, 48, 60]);
1232 @c y: gramschmidt (x);
1233 @c map (innerproduct, [y[1], y[2], y[3]], [y[2], y[3], y[1]]);
1236 (%i1) load ("eigen")$
1238 (%i2) x: matrix ([1, 2, 3], [9, 18, 30], [12, 48, 60]);
1246 (%i3) y: gramschmidt (x);
1249 (%o3) [[1, 2, 3], [- ---, - --, ---], [- ----, ----, 0]]
1253 (%i4) map (innerproduct, [y[1], y[2], y[3]], [y[2], y[3], y[1]]);
1258 Gram-Schmidt algorithm using a specified inner product function.
1262 @c ip (f, g) := integrate (f * g, u, a, b);
1263 @c y: gramschmidt ([1, sin(u), cos(u)], ip), a=-%pi/2, b=%pi/2;
1264 @c map (ip, [y[1], y[2], y[3]], [y[2], y[3], y[1]]), a=-%pi/2,
1268 (%i1) load ("eigen")$
1270 (%i2) ip (f, g) := integrate (f * g, u, a, b);
1271 (%o2) ip(f, g) := integrate(f g, u, a, b)
1274 (%i3) y: gramschmidt ([1, sin(u), cos(u)], ip), a=-%pi/2, b=%pi/2;
1276 (%o3) [1, sin(u), --------------]
1280 (%i4) map (ip, [y[1], y[2], y[3]], [y[2], y[3], y[1]]), a=-%pi/2,
1286 @opencatbox{Categories:}
1287 @category{Package eigen}
1291 @c -----------------------------------------------------------------------------
1293 @deffn {Function} ident (@var{n})
1295 Returns an @var{n} by @var{n} identity matrix.
1297 @opencatbox{Categories:}
1302 @c -----------------------------------------------------------------------------
1303 @anchor{innerproduct}
1305 @deffn {Function} innerproduct (@var{x}, @var{y})
1306 @deffnx {Function} inprod (@var{x}, @var{y})
1308 Returns the inner product (also called the scalar product or dot product) of
1309 @var{x} and @var{y}, which are lists of equal length, or both 1-column or 1-row
1310 matrices of equal length. The return value is @code{conjugate (x) . y},
1311 where @code{.} is the noncommutative multiplication operator.
1313 @code{load ("eigen")} loads this function.
1315 @code{inprod} is a synonym for @code{innerproduct}.
1317 @c NEED EXAMPLE HERE
1318 @opencatbox{Categories:}
1319 @category{Package eigen}
1323 @c -----------------------------------------------------------------------------
1324 @anchor{invert_by_adjoint}
1325 @deffn {Function} invert_by_adjoint (@var{M})
1326 Returns the inverse of the matrix @var{M}.
1327 The inverse is computed by the adjoint method.
1329 @code{invert_by_adjoint} honors the @mref{ratmx} and @mref{detout} flags,
1330 the same as @mrefdot{invert}
1334 @c -----------------------------------------------------------------------------
1336 @deffn {Function} invert (@var{M})
1338 Returns the inverse of the matrix @var{M}.
1339 The inverse is computed via the LU decomposition.
1341 When @mref{ratmx} is @code{true},
1342 elements of @var{M} are converted to canonical rational expressions (CRE),
1343 and the elements of the return value are also CRE.
1345 When @mref{ratmx} is @code{false},
1346 elements of @var{M} are not converted to a common representation.
1347 In particular, float and bigfloat elements are not converted to rationals.
1349 When @mref{detout} is @code{true}, the determinant is factored out of the inverse.
1350 The global flags @mref{doallmxops} and @mref{doscmxops} must be @code{false}
1351 to prevent the determinant from being absorbed into the inverse.
1352 @mref{xthru} can multiply the determinant into the inverse.
1354 @mref{invert} does not apply any simplifications to the elements of the inverse
1355 apart from the default arithmetic simplifications.
1356 @mref{ratsimp} and @mref{expand} can apply additional simplifications.
1357 In particular, when @var{M} has polynomial elements,
1358 @code{expand(invert(@var{M}))} might be preferable.
1360 @code{invert(@var{M})} is equivalent to @code{@var{M}^^-1}.
1362 @c NEED EXAMPLES HERE
1363 @opencatbox{Categories:}
1368 @c -----------------------------------------------------------------------------
1369 @anchor{list_matrix_entries}
1370 @deffn {Function} list_matrix_entries (@var{M})
1372 Returns a list containing the elements of the matrix @var{M}.
1377 @c list_matrix_entries(matrix([a,b],[c,d]));
1381 (%i1) list_matrix_entries(matrix([a,b],[c,d]));
1386 @opencatbox{Categories:}
1391 @c -----------------------------------------------------------------------------
1393 @defvr {Option variable} lmxchar
1394 Default value: @code{[}
1396 @code{lmxchar} is the character displayed as the left delimiter of a matrix.
1397 See also @mrefdot{rmxchar}
1403 (%i2) matrix ([a, b, c], [d, e, f], [g, h, i]);
1411 @opencatbox{Categories:}
1412 @category{Display flags and variables}
1417 @c -----------------------------------------------------------------------------
1419 @deffn {Function} matrix (@var{row_1}, @dots{}, @var{row_n})
1421 Returns a rectangular matrix which has the rows @var{row_1}, @dots{},
1422 @var{row_n}. Each row is a list of expressions. All rows must be the same
1425 The operations @code{+} (addition), @code{-} (subtraction), @code{*}
1426 (multiplication), and @code{/} (division), are carried out element by element
1427 when the operands are two matrices, a scalar and a matrix, or a matrix and a
1428 scalar. The operation @code{^} (exponentiation, equivalently @code{**})
1429 is carried out element by element if the operands are a scalar and a matrix or
1430 a matrix and a scalar, but not if the operands are two matrices.
1431 @c WHAT DOES THIS NEXT PHRASE MEAN EXACTLY ??
1432 All operations are normally carried out in full,
1433 including @code{.} (noncommutative multiplication).
1435 Matrix multiplication is represented by the noncommutative multiplication
1436 operator @code{.}. The corresponding noncommutative exponentiation operator
1437 is @code{^^}. For a matrix @code{@var{A}}, @code{@var{A}.@var{A} = @var{A}^^2}
1438 and @code{@var{A}^^-1} is the inverse of @var{A}, if it exists.
1439 @code{@var{A}^^-1} is equivalent to @code{invert(@var{A})}.
1441 There are switches for controlling simplification of expressions involving dot
1442 and matrix-list operations. These are
1443 @mrefcomma{doallmxops} @mrefcomma{domxexpt} @mrefcomma{domxmxops}@w{}
1444 @mrefcomma{doscmxops} and @mrefdot{doscmxplus}
1445 @c CHECK -- WE PROBABLY WANT EXHAUSTIVE LIST HERE
1447 There are additional options which are related to matrices. These are:
1448 @mrefcomma{lmxchar} @mrefcomma{rmxchar} @mrefcomma{ratmx}@w{}
1449 @mrefcomma{listarith} @mrefcomma{detout} @code{scalarmatrix} and
1451 @c CHECK -- WE PROBABLY WANT EXHAUSTIVE LIST HERE
1453 There are a number of functions which take matrices as arguments or yield
1454 matrices as return values.
1455 See @mrefcomma{eigenvalues} @mrefcomma{eigenvectors} @mrefcomma{determinant}@w{}
1456 @mrefcomma{charpoly} @mrefcomma{genmatrix} @mrefcomma{addcol}@w{}
1457 @mrefcomma{addrow} @mrefcomma{copymatrix} @mrefcomma{transpose}@w{}
1458 @mrefcomma{echelon} and @mrefdot{rank}
1459 @c CHECK -- WE PROBABLY WANT EXHAUSTIVE LIST HERE
1465 Construction of matrices from lists.
1468 (%i1) x: matrix ([17, 3], [-8, 11]);
1472 (%i2) y: matrix ([%pi, %e], [a, b]);
1479 Addition, element by element.
1489 Subtraction, element by element.
1499 Multiplication, element by element.
1509 Division, element by element.
1523 Matrix to a scalar exponent, element by element.
1533 Scalar base to a matrix exponent, element by element.
1545 Matrix base to a matrix exponent. This is not carried out element by element.
1546 See also @mrefdot{matrixexp}
1560 Noncommutative matrix multiplication.
1564 [ 3 a + 17 %pi 3 b + 17 %e ]
1566 [ 11 a - 8 %pi 11 b - 8 %e ]
1568 [ 17 %pi - 8 %e 3 %pi + 11 %e ]
1570 [ 17 a - 8 b 11 b + 3 a ]
1574 Noncommutative matrix exponentiation.
1575 A scalar base @var{b} to a matrix power @var{M}
1576 is carried out element by element and so @code{b^^m} is the same as @code{b^m}.
1594 A matrix raised to a -1 exponent with noncommutative exponentiation is the
1595 matrix inverse, if it exists.
1606 (%i15) x . (x ^^ -1);
1612 @opencatbox{Categories:}
1617 @c -----------------------------------------------------------------------------
1619 @deffn {Function} matrixexp @
1620 @fname{matrixexp} (@var{M}) @
1621 @fname{matrixexp} (@var{M}, @var{n}) @
1622 @fname{matrixexp} (@var{M}, @var{V})
1624 Calculates the matrix exponential
1641 . Instead of the vector @var{V} a number @var{n} can be specified as the second
1642 argument. If this argument is omitted @code{matrixexp} replaces it by @code{1}.
1644 The matrix exponential of a matrix @var{M} can be expressed as a power series:
1647 @math{e^M=\sum_{k=0}^\infty{{M^k}\over{k!}}}
1651 $$e^M=\sum_{k=0}^\infty{\left(\frac{M^k}{k!}\right)}$$
1655 @math{e^M=sum(M^k/k!,0,inf)}
1659 @math{e^M=sum(M^k/k!,0,inf)}
1662 @c NEED EXAMPLE HERE
1663 @opencatbox{Categories:}
1669 @c -----------------------------------------------------------------------------
1671 @deffn {Function} matrixmap (@var{f}, @var{M})
1673 Returns a matrix with element @code{i,j} equal to @code{@var{f}(@var{M}[i,j])}.
1675 See also @mrefcomma{map} @mrefcomma{fullmap} @mrefcomma{fullmapl} and
1678 @c NEED EXAMPLE HERE
1679 @opencatbox{Categories:}
1684 @c -----------------------------------------------------------------------------
1686 @deffn {Function} matrixp (@var{expr})
1688 Returns @code{true} if @var{expr} is a matrix, otherwise @code{false}.
1690 @opencatbox{Categories:}
1691 @category{Predicate functions}
1696 @c -----------------------------------------------------------------------------
1697 @anchor{matrix_element_add}
1698 @defvr {Option variable} matrix_element_add
1699 Default value: @code{+}
1701 @code{matrix_element_add} is the operation
1702 invoked in place of addition in a matrix multiplication.
1703 @code{matrix_element_add} can be assigned any n-ary operator
1704 (that is, a function which handles any number of arguments).
1705 The assigned value may be the name of an operator enclosed in quote marks,
1706 the name of a function,
1707 or a lambda expression.
1709 See also @mref{matrix_element_mult} and @mrefdot{matrix_element_transpose}
1714 (%i1) matrix_element_add: "*"$
1715 (%i2) matrix_element_mult: "^"$
1716 (%i3) aa: matrix ([a, b, c], [d, e, f]);
1720 (%i4) bb: matrix ([u, v, w], [x, y, z]);
1726 (%i5) aa . transpose (bb);
1734 @opencatbox{Categories:}
1739 @c -----------------------------------------------------------------------------
1740 @anchor{matrix_element_mult}
1741 @defvr {Option variable} matrix_element_mult
1742 Default value: @code{*}
1744 @code{matrix_element_mult} is the operation
1745 invoked in place of multiplication in a matrix multiplication.
1746 @code{matrix_element_mult} can be assigned any binary operator.
1747 The assigned value may be the name of an operator enclosed in quote marks,
1748 the name of a function,
1749 or a lambda expression.
1751 The dot operator @code{.} is a useful choice in some contexts.
1753 See also @mref{matrix_element_add} and @mrefdot{matrix_element_transpose}
1758 (%i1) matrix_element_add: lambda ([[x]], sqrt (apply ("+", x)))$
1759 (%i2) matrix_element_mult: lambda ([x, y], (x - y)^2)$
1760 (%i3) [a, b, c] . [x, y, z];
1762 (%o3) sqrt((c - z) + (b - y) + (a - x) )
1763 (%i4) aa: matrix ([a, b, c], [d, e, f]);
1767 (%i5) bb: matrix ([u, v, w], [x, y, z]);
1771 (%i6) aa . transpose (bb);
1773 [ sqrt((c - w) + (b - v) + (a - u) ) ]
1776 [ sqrt((f - w) + (e - v) + (d - u) ) ]
1779 [ sqrt((c - z) + (b - y) + (a - x) ) ]
1782 [ sqrt((f - z) + (e - y) + (d - x) ) ]
1785 @opencatbox{Categories:}
1790 @c -----------------------------------------------------------------------------
1791 @anchor{matrix_element_transpose}
1792 @defvr {Option variable} matrix_element_transpose
1793 Default value: @code{false}
1795 @code{matrix_element_transpose} is the operation
1796 applied to each element of a matrix when it is transposed.
1797 @mref{matrix_element_mult} can be assigned any unary operator.
1798 The assigned value may be the name of an operator enclosed in quote marks,
1799 the name of a function, or a lambda expression.
1801 When @code{matrix_element_transpose} equals @mrefcomma{transpose}
1802 the @code{transpose} function is applied to every element.
1803 When @code{matrix_element_transpose} equals @code{nonscalars},
1804 the @code{transpose} function is applied to every nonscalar element.
1805 If some element is an atom, the @code{nonscalars} option applies
1806 @code{transpose} only if the atom is declared nonscalar,
1807 while the @code{transpose} option always applies @code{transpose}.
1809 The default value, @code{false}, means no operation is applied.
1811 See also @mref{matrix_element_add} and @mrefdot{matrix_element_mult}
1816 (%i1) declare (a, nonscalar)$
1817 (%i2) transpose ([a, b]);
1821 (%i3) matrix_element_transpose: nonscalars$
1822 (%i4) transpose ([a, b]);
1826 (%i5) matrix_element_transpose: transpose$
1827 (%i6) transpose ([a, b]);
1831 (%i7) matrix_element_transpose: lambda ([x], realpart(x)
1833 (%i8) m: matrix ([1 + 5*%i, 3 - 2*%i], [7*%i, 11]);
1834 [ 5 %i + 1 3 - 2 %i ]
1837 (%i9) transpose (m);
1843 @opencatbox{Categories:}
1848 @c IS THIS THE ONLY MATRIX TRACE FUNCTION ??
1850 @c -----------------------------------------------------------------------------
1852 @deffn {Function} mattrace (@var{M})
1854 Returns the trace (that is, the sum of the elements on the main diagonal) of
1855 the square matrix @var{M}.
1857 @code{mattrace} is called by @mrefcomma{ncharpoly} an alternative to Maxima's
1859 @c UMM, HOW IS THAT RELEVANT HERE ??
1861 @code{load ("nchrpl")} loads this function.
1863 @opencatbox{Categories:}
1865 @category{Package nchrpl}
1869 @c -----------------------------------------------------------------------------
1871 @deffn {Function} minor (@var{M}, @var{i}, @var{j})
1873 Returns the @var{i}, @var{j} minor of the matrix @var{M}. That is, @var{M}
1874 with row @var{i} and column @var{j} removed.
1876 @opencatbox{Categories:}
1881 @c -----------------------------------------------------------------------------
1883 @deffn {Function} ncharpoly (@var{M}, @var{x})
1885 Returns the characteristic polynomial of the matrix @var{M}
1886 with respect to @var{x}. This is an alternative to Maxima's @mrefdot{charpoly}
1888 @code{ncharpoly} works by computing traces of powers of the given matrix,
1889 which are known to be equal to sums of powers of the roots of the
1890 characteristic polynomial. From these quantities the symmetric
1891 functions of the roots can be calculated, which are nothing more than
1892 the coefficients of the characteristic polynomial. @code{charpoly} works by
1893 @c SHOULD THAT BE "m" INSTEAD OF "a" IN THE NEXT LINE ??
1894 forming the determinant of @code{@var{x} * ident [n] - a}. Thus
1895 @code{ncharpoly} wins, for example, in the case of large dense matrices filled
1896 with integers, since it avoids polynomial arithmetic altogether.
1898 @code{load ("nchrpl")} loads this file.
1900 @opencatbox{Categories:}
1902 @category{Package nchrpl}
1906 @c -----------------------------------------------------------------------------
1908 @deffn {Function} newdet (@var{M})
1910 Computes the determinant of the matrix @var{M} by the Johnson-Gentleman tree
1911 minor algorithm. @code{newdet} returns the result in CRE form.
1913 @opencatbox{Categories:}
1918 @c -----------------------------------------------------------------------------
1920 @deffn {Function} permanent (@var{M})
1922 Computes the permanent of the matrix @var{M} by the Johnson-Gentleman tree
1923 minor algorithm. A permanent is like a determinant but with no sign changes.
1924 @code{permanent} returns the result in CRE form.
1926 See also @code{newdet}.
1928 @opencatbox{Categories:}
1933 @c -----------------------------------------------------------------------------
1935 @deffn {Function} rank (@var{M})
1937 Computes the rank of the matrix @var{M}. That is, the order of the
1938 largest non-singular subdeterminant of @var{M}.
1940 @c STATEMENT NEEDS CLARIFICATION
1941 @var{rank} may return the
1942 wrong answer if it cannot determine that a matrix element that is
1943 equivalent to zero is indeed so.
1945 @opencatbox{Categories:}
1950 @c -----------------------------------------------------------------------------
1952 @defvr {Option variable} ratmx
1953 Default value: @code{false}
1955 When @code{ratmx} is @code{false}, determinant and matrix
1956 addition, subtraction, and multiplication are performed in the
1957 representation of the matrix elements and cause the result of
1958 matrix inversion to be left in general representation.
1960 When @code{ratmx} is @code{true},
1961 the 4 operations mentioned above are performed in CRE form and the
1962 result of matrix inverse is in CRE form. Note that this may
1963 cause the elements to be expanded (depending on the setting of @mref{ratfac})
1964 which might not always be desired.
1966 @opencatbox{Categories:}
1968 @category{Rational expressions}
1972 @c -----------------------------------------------------------------------------
1974 @deffn {Function} row (@var{M}, @var{i})
1976 Returns the @var{i}'th row of the matrix @var{M}.
1977 The return value is a matrix.
1979 @opencatbox{Categories:}
1984 @c -----------------------------------------------------------------------------
1986 @defvr {Option variable} rmxchar
1987 Default value: @code{]}
1989 @code{rmxchar} is the character drawn on the right-hand side of a matrix.
1991 See also @mrefdot{lmxchar}
1993 @opencatbox{Categories:}
1994 @category{Display flags and variables}
1998 @c -----------------------------------------------------------------------------
1999 @anchor{scalarmatrixp}
2000 @defvr {Option variable} scalarmatrixp
2001 Default value: @code{true}
2003 When @code{scalarmatrixp} is @code{true}, then whenever a 1 x 1 matrix
2004 is produced as a result of computing the dot product of matrices it
2005 is simplified to a scalar, namely the sole element of the matrix.
2007 When @code{scalarmatrixp} is @code{all},
2008 then all 1 x 1 matrices are simplified to scalars.
2010 When @code{scalarmatrixp} is @code{false}, 1 x 1 matrices are not simplified
2013 @opencatbox{Categories:}
2015 @category{Simplification flags and variables}
2019 @c I WONDER WHAT THIS IS ABOUT
2021 @c -----------------------------------------------------------------------------
2022 @anchor{scalefactors}
2023 @deffn {Function} scalefactors (@var{coordinatetransform})
2025 Here the argument @var{coordinatetransform} evaluates to the form
2026 @code{[[expression1, expression2, ...], indeterminate1, indeterminat2, ...]},
2027 where the variables @var{indeterminate1}, @var{indeterminate2}, etc. are the
2028 curvilinear coordinate variables and where a set of rectangular Cartesian
2029 components is given in terms of the curvilinear coordinates by
2030 @code{[expression1, expression2, ...]}. @code{coordinates} is set to the vector
2031 @code{[indeterminate1, indeterminate2,...]}, and @code{dimension} is set to the
2032 length of this vector. SF[1], SF[2], @dots{}, SF[DIMENSION] are set to the
2033 coordinate scale factors, and @code{sfprod} is set to the product of these scale
2034 factors. Initially, @code{coordinates} is @code{[X, Y, Z]}, @code{dimension}
2035 is 3, and SF[1]=SF[2]=SF[3]=SFPROD=1, corresponding to 3-dimensional rectangular
2036 Cartesian coordinates. To expand an expression into physical components in the
2037 current coordinate system, there is a function with usage of the form
2038 @c SOME TEXT HAS GONE MISSING HERE
2040 @opencatbox{Categories:}
2041 @category{Package vect}
2045 @c -----------------------------------------------------------------------------
2047 @deffn {Function} setelmx (@var{x}, @var{i}, @var{j}, @var{M})
2049 Assigns @var{x} to the (@var{i}, @var{j})'th element of the matrix @var{M},
2050 and returns the altered matrix.
2052 @code{@var{M} [@var{i}, @var{j}]: @var{x}} has the same effect,
2053 but returns @var{x} instead of @var{M}.
2055 @opencatbox{Categories:}
2060 @c -----------------------------------------------------------------------------
2061 @anchor{similaritytransform}
2063 @deffn {Function} similaritytransform (@var{M})
2064 @deffnx {Function} simtran (@var{M})
2066 @code{similaritytransform} computes a similarity transform of the matrix
2067 @code{M}. It returns a list which is the output of the @code{uniteigenvectors}
2068 command. In addition if the flag @code{nondiagonalizable} is @code{false} two
2069 global matrices @code{leftmatrix} and @code{rightmatrix} are computed. These
2070 matrices have the property that @code{leftmatrix . @var{M} . rightmatrix} is a
2071 diagonal matrix with the eigenvalues of @var{M} on the diagonal. If
2072 @code{nondiagonalizable} is @code{true} the left and right matrices are not
2075 If the flag @code{hermitianmatrix} is @code{true} then @code{leftmatrix} is the
2076 complex conjugate of the transpose of @code{rightmatrix}. Otherwise
2077 @code{leftmatrix} is the inverse of @code{rightmatrix}.
2079 @code{rightmatrix} is the matrix the columns of which are the unit
2080 eigenvectors of @var{M}. The other flags (see @code{eigenvalues} and
2081 @code{eigenvectors}) have the same effects since
2082 @code{similaritytransform} calls the other functions in the package in order
2083 to be able to form @code{rightmatrix}.
2085 @code{load ("eigen")} loads this function.
2087 @code{simtran} is a synonym for @code{similaritytransform}.
2089 @opencatbox{Categories:}
2090 @category{Package eigen}
2094 @c -----------------------------------------------------------------------------
2096 @defvr {Option variable} sparse
2097 Default value: @code{false}
2099 When @code{sparse} is @code{true}, and if @code{ratmx} is @code{true}, then
2100 @code{determinant} will use special routines for computing sparse determinants.
2102 @opencatbox{Categories:}
2107 @c -----------------------------------------------------------------------------
2109 @deffn {Function} submatrix @
2110 @fname{submatrix} (@var{i_1}, @dots{}, @var{i_m}, @var{M}, @var{j_1}, @dots{}, @var{j_n}) @
2111 @fname{submatrix} (@var{i_1}, @dots{}, @var{i_m}, @var{M}) @
2112 @fname{submatrix} (@var{M}, @var{j_1}, @dots{}, @var{j_n})
2114 Returns a new matrix composed of the matrix @var{M} with rows @var{i_1},
2115 @dots{}, @var{i_m} deleted, and columns @var{j_1}, @dots{}, @var{j_n} deleted.
2117 @opencatbox{Categories:}
2122 @c -----------------------------------------------------------------------------
2124 @deffn {Function} transpose (@var{M})
2126 Returns the transpose of @var{M}.
2128 If @var{M} is a matrix, the return value is another matrix @var{N}
2129 such that @code{N[i,j] = M[j,i]}.
2131 If @var{M} is a list, the return value is a matrix @var{N}
2132 of @code{length (m)} rows and 1 column, such that @code{N[i,1] = M[i]}.
2134 Otherwise @var{M} is a symbol,
2135 and the return value is a noun expression @code{'transpose (@var{M})}.
2137 @opencatbox{Categories:}
2142 @c -----------------------------------------------------------------------------
2143 @anchor{triangularize}
2144 @deffn {Function} triangularize (@var{M})
2146 Returns the upper triangular form of the matrix @code{M},
2147 as produced by Gaussian elimination.
2148 The return value is the same as @code{echelon},
2149 except that the leading nonzero coefficient in each row is not normalized to 1.
2151 @code{lu_factor} and @code{cholesky} are other functions which yield
2152 triangularized matrices.
2155 @c M: matrix ([3, 7, aa, bb], [-1, 8, 5, 2], [9, 2, 11, 4]);
2156 @c triangularize (M);
2160 (%i1) M: matrix ([3, 7, aa, bb], [-1, 8, 5, 2], [9, 2, 11, 4]);
2168 (%i2) triangularize (M);
2171 (%o2) [ 0 - 74 - 56 - 22 ]
2173 [ 0 0 626 - 74 aa 238 - 74 bb ]
2177 @opencatbox{Categories:}
2178 @category{Linear equations}
2183 @c -----------------------------------------------------------------------------
2184 @anchor{uniteigenvectors}
2186 @deffn {Function} uniteigenvectors (@var{M})
2187 @deffnx {Function} ueivects (@var{M})
2189 Computes unit eigenvectors of the matrix @var{M}.
2190 The return value is a list of lists, the first sublist of which is the
2191 output of the @code{eigenvalues} command, and the other sublists of which are
2192 the unit eigenvectors of the matrix corresponding to those eigenvalues
2195 @c COPY DESCRIPTIONS OF THOSE FLAGS HERE
2196 The flags mentioned in the description of the
2197 @code{eigenvectors} command have the same effects in this one as well.
2199 When @code{knowneigvects} is @code{true}, the @code{eigen} package assumes
2200 that the eigenvectors of the matrix are known to the user and are
2201 stored under the global name @code{listeigvects}. @code{listeigvects} should
2202 be set to a list similar to the output of the @code{eigenvectors} command.
2204 @c FOLLOWING PARAGRAPH IS IN NEED OF SERIOUS CLARIFICATION
2205 If @code{knowneigvects} is set to @code{true} and the list of eigenvectors is
2206 given the setting of the flag @code{nondiagonalizable} may not be correct. If
2207 that is the case please set it to the correct value. The author assumes that
2208 the user knows what he is doing and will not try to diagonalize a matrix the
2209 eigenvectors of which do not span the vector space of the appropriate dimension.
2211 @code{load ("eigen")} loads this function.
2213 @code{ueivects} is a synonym for @code{uniteigenvectors}.
2215 @opencatbox{Categories:}
2216 @category{Package eigen}
2220 @c -----------------------------------------------------------------------------
2223 @deffn {Function} unitvector (@var{x})
2224 @deffnx {Function} uvect (@var{x})
2226 Returns @math{@var{x}/norm(@var{x})};
2227 this is a unit vector in the same direction as @var{x}.
2229 @code{load ("eigen")} loads this function.
2231 @code{uvect} is a synonym for @code{unitvector}.
2233 @opencatbox{Categories:}
2234 @category{Package eigen}
2240 @c -----------------------------------------------------------------------------
2241 @anchor{vectorpotential}
2242 @deffn {Function} vectorpotential (@var{givencurl})
2244 Returns the vector potential of a given curl vector, in the current coordinate
2245 system. @code{potentialzeroloc} has a similar role as for @code{potential}, but
2246 the order of the left-hand sides of the equations must be a cyclic permutation
2247 of the coordinate variables.
2249 @opencatbox{Categories:}
2250 @category{Package vect}
2254 @c NEEDS A LOT OF WORK: MAKE SURE THAT ALL VECTOR SIMPLIFICATION FLAGS HAVE A
2257 @c -----------------------------------------------------------------------------
2259 @deffn {Function} vectorsimp (@var{expr})
2261 Applies simplifications and expansions according to the following global flags:
2264 @code{expandall}, @code{expanddot}, @code{expanddotplus}, @code{expandcross}, @code{expandcrossplus},
2265 @code{expandcrosscross}, @code{expandgrad}, @code{expandgradplus}, @code{expandgradprod},
2266 @code{expanddiv}, @code{expanddivplus}, @code{expanddivprod}, @code{expandcurl}, @code{expandcurlplus},
2267 @code{expandcurlcurl}, @code{expandlaplacian}, @code{expandlaplacianplus},
2268 and @code{expandlaplacianprod}.
2271 All these flags have default value @code{false}. The @code{plus} suffix refers
2272 to employing additivity or distributivity. The @code{prod} suffix refers to the
2273 expansion for an operand that is any kind of product.
2276 @item expandcrosscross
2277 Simplifies @math{p ~ (q ~ r)} to @math{(p . r)*q - (p . q)*r}.
2278 @item expandcurlcurl
2279 Simplifies @math{curl curl p} to @math{grad div p + div grad p}.
2280 @item expandlaplaciantodivgrad
2281 Simplifies @math{laplacian p} to @math{div grad p}.
2283 Enables @code{expandcrossplus} and @code{expandcrosscross}.
2286 Enables @code{expanddotplus}, @code{expandcrossplus}, @code{expandgradplus},
2287 @code{expanddivplus}, @code{expandcurlplus}, and @code{expandlaplacianplus}.
2290 Enables @code{expandgradprod}, @code{expanddivprod}, and @code{expandlaplacianprod}.
2293 @c EXPLAIN THE IMPORT OF THIS STATEMENT
2294 These flags have all been declared @code{evflag}.
2296 @c SEEMS SOME TEXT HAS GONE MISSING HERE; COMMENT OUT FRAGMENT PENDING
2297 @c RECOVERY AND/OR RECONSTRUCTION OF THIS PARAGRAPH
2298 @c For orthogonal curvilinear coordinates, the global variables
2299 @c COORDINATES[[X,Y,Z]], DIMENSION[3], SF[[1,1,1]], and SFPROD[1] are set
2300 @c by the function invocation
2302 @opencatbox{Categories:}
2303 @category{Package vect}
2304 @category{Simplification functions}
2308 @c -----------------------------------------------------------------------------
2310 @defvr {Option variable} vect_cross
2311 Default value: @code{false}
2313 @c WHAT DOES THIS MEAN EXACTLY ??
2314 When @code{vect_cross} is @code{true}, it allows DIFF(X~Y,T) to work where
2315 ~ is defined in SHARE;VECT (where VECT_CROSS is set to @code{true}, anyway.)
2317 @opencatbox{Categories:}
2318 @category{Package vect}
2319 @category{Differential calculus}
2323 @c -----------------------------------------------------------------------------
2325 @deffn {Function} zeromatrix (@var{m}, @var{n})
2327 Returns an @var{m} by @var{n} matrix, all elements of which are zero.
2329 @opencatbox{Categories:}