# MAPLE ASSIGNMENT 8
# MORE MATRIX ALGEBRA
> with(linalg):
> M1:=matrix(3,3,[1,0,-1,1,5,7,3,3,9]);
> M2:=matrix(3,3,[1,0,-1,3,6,21,3,3,9]);
# First the properties of transposes are illustrated.
> evalm(transpose(M1&*M2)); 
> evalm(transpose(M1)&*transpose(M2));
> evalm(transpose(M2)&*transpose(M1));
# Not all square matrices have an inverse matrix, for example M2. If a
# square matrix does have an inverse matrix, then it is said to be
# nonsingular.  The determinant of a matrix is used to test for
# nonsingularity.  A matix M is nonsingular if and only if  det(M) is
# not equal to zero. Apply this test to M1 and M2.
> det(M1);
# Now create your own nonsingular matrix M3 by filling in the 9 missing
# numbers in the next command. Use the determinant to see if you have
# been sucessful and if not edit your M3 until you are sucessful.
> M3:=matrix(3,3,[ , , , , , , , , ]);
> det(M3);
# The next commands illustrate the correct and the incorrect way to get
# the inverse of the product of two matrices.
> evalm((M1&*M3)^(-1));
> evalm((M3^(-1))&*(M1^(-1)));
> evalm((M1^(-1))*(M3^(-1)));
> evalm((M1^(-1))+(M3^(-1)));
> evalm((M1+M3)^(-1));
# The last two commands have illustrated a dumb arithmetical mistake you
# should not make even with numbers. Now check another property of the
# transpose.
> evalm(transpose(M1^(-1))-transpose(M1)^(-1));
# SOLVING SYSTEMS OF LINEAR EQUATIONS
# The exercise here is to see how Maple preforms when asked to solve a
# large system of linear equations. Please feel free to change the
# numbers in the matrices in any way you like.
> with(linalg):
> A:=matrix(6,6,[1,0,-1,1,5,7,3,3,9,9,3,3,7,5,1,-1,0,1,1,0,-1,3,6,21,3,3
> ,9,1,0,-1,1,5,7,3,3,9]);
> det(A); 
# Even though the vector of constants appears on the screen as a row
# vector, in Maple it is treated as a column vector if that is what the
# context calls for.
> b:=vector([1,3,0,-2,4,5]);
> x:=linsolve(A,b);
> evalm(A&*x);
> evalm(x&*A);
> x1:=A^(-1)&*b;
> evalm(x1-x);
# Maple uses the Gauss-Jordan method discussed in the text to do the
# calculations above. This means that as long as the entries in A & b
# are integers or rational numbers (integer/integer) the answer is given
# as rational numbers and so it is the exact answer. The method does not
# introduce rounding errors into the calculation.
# INVERSE MATRIX
# The next few commands illustrate calculating the inverse matrix of the
# 6x6 matrix above
> C:=array(1..6,1..6):
> for i to 6 do for j to 6 do C[i,j]:=(-1)^(i+j)*det(minor(A,i,j)) end
> end do :
> evalm(C);
# C is the matrix of cofactors of A. To illustrate the next three
# commands calculate the (2,5) minor of A.
> M25:=submatrix(A,[1,3,4,5,6],[1,2,3,4,6]);
> det(M25);
> C[2,5];
# Why is this cofactor minus the minor? Edit these commands to calculate
# some other minor and cofactor of A.
# Finally verify that the formula given in class for the inverse matrix
# was correct.
> adjA:=transpose(C);
> evalm((1/det(A))*adjA-A^(-1));
> 
