matrix exponential code




I wrote a simple-minded matrix exponential function.  My file
mat_exp.mc is attached; here is a demonstration:

Maxima 5.5 Tue Dec 5 16:55:33 2000 (with enhancements by W. Schelter).
Licensed under the GNU Public License (see file COPYING)

(C1) load("e://mat_exp.mc");
(D1)                 e://mat_exp.mc
(C2) display2d : false;
(D2) FALSE
(C3) sq(x) := x^2$
(C4) cube(x) := x^3$
(C5) m : matrix([2,1],[1,5])$

/*  matrix_function(sq,m) squares the matrix m;  we've got a
    big mess without radcan!
*/

(C6) radcan(matrix_function(sq,m));
Warning - you are redefining the MACSYMA function EIGENVALUES
Warning - you are redefining the MACSYMA function EIGENVECTORS
(D6) MATRIX([5,7],[7,26])


/* Let's check.
*/
(C7) m.m;
(D7) MATRIX([5,7],[7,26])

/* This checks.  Let's compute the cube of m and check.
*/

(C8) radcan(matrix_function(cube,m));
(D8) MATRIX([17,40],[40,137])
(C9) m^^3;
(D9) MATRIX([17,40],[40,137])

/* This also checks.  The matrix needn't be real; let's try
*/

(C10) m : matrix([%i,0],[0,-%i]);
(D10) MATRIX([%I,0],[0,-%I])

/* matrix_exp(m) = id + m + m^2/2! + m^3 / 3! + .... is the matrix
exponential.  Since m is diagonal, we should get
matrix([exp(%i),0],[0,exp(-%i)]).
*/
(C11) matrix_exp(m);
(D11) MATRIX([%E^%I,0],[0,%E^-%I])


/* This is okay. We do require that m be diagonable.  If it isn't,
matrix_function returns FALSE.
*/

(C12) m : matrix([1,1],[0,1]);
(D12) MATRIX([1,1],[0,1])
(C13) matrix_function(sq,m);
(D13) FALSE


/* To verify that m isn't diagonable, evaluate NONDIAGONALIZABLE;
*/

(C14) NONDIAGONALIZABLE;
(D14) TRUE


Before you trust this code for something that matters, give it
a good test; I've only tested it on a few problems.  If your
matrices are large (3 by 3 might be "large") or if they
have many symbolic elements, you'll run into trouble.

Maybe this helps.

Barton Willis

Attached file: mat_exp.mc