# MAPLE ASIIGNMENT 6
# The first command loads the matrix algebra operations into Maple.
# Change the : to ; if you wish to see all the commands in this package.
> with(linalg):
Warning, new definition for norm
Warning, new definition for trace
# The arithmetic operations for matrices are + , - , &* , ^ .The
# following shows how Maple calculates a determinant. You can of course
# put any numbers that you like into M
> M:=matrix(3,3,[1,0,-1,3,6,2,3,-3,1]);

                              [1     0    -1]
                              [             ]
                         M := [3     6     2]
                              [             ]
                              [3    -3     1]

> det(M);
# The next command allows you to check that you can calculate a 3X3
# determinant by hand. Fill in the 4 missing terms.
> (1*6*1)-((-1)*6*3)
# Diagonal matrices are created with the diag command.  This can be used
# to create an identity matrix.
> iden:=diag(1,1,1);

                                [1    0    0]
                                [           ]
                        iden := [0    1    0]
                                [           ]
                                [0    0    1]

# Inverse matrices are either M^(-1)  or inverse(M).  The following
# calculate the inverse, check that it 
# works and illustrate the properties of inverses.  
> M1:=M^(-1);

                              M1 := 1/M

> evalm(");
> evalm(M&*M1-iden);
> evalm(M1&*M-iden);
> evalm(M1^(-1));
# To check that you understand how to calculate the inverse matrix by
# hand replace the ? in the command below by appropriate entries from M
> evalm(M);
> M1??:=((-1)^?)*det(matrix(2,2,[?,?,?,?]))/det(M);
> 
> evalm(M1);
# The next commands illustrate the correct and the incorrect way to get
# the inverse of the product of two matrices.
> M2:=evalm(M+M1);
> evalm((M&*M2)^(-1));
> evalm((M2^(-1))&*(M^(-1)));
> evalm((M^(-1))*(M2^(-1)));
> evalm((M^(-1))+(M2^(-1)));
> evalm((M+M2)^(-1));
# The last two commands have illustrated a dumb artihmetical mistake you
# should not make even with numbers.
# PROPERTIES OF DETERMINANTS
# The commands below check some of the properties of determinants. You
# should look to see that the new matrices being created are what you
# expect them to be.
> evalm(M);

                           [1     0    -1]
                           [             ]
                           [3     6     2]
                           [             ]
                           [3    -3     1]

> M3:=transpose(M);

                              [ 1    3     3]
                              [             ]
                        M3 := [ 0    6    -3]
                              [             ]
                              [-1    2     1]

> det(M3);

                                  39

> M4:=swaprow(M,1,3);

                              [3    -3     1]
                              [             ]
                        M4 := [3     6     2]
                              [             ]
                              [1     0    -1]

> det(M4);

                                 -39

> M5:=swapcol(M4,1,2);

                              [-3    3     1]
                              [             ]
                        M5 := [ 6    3     2]
                              [             ]
                              [ 0    1    -1]

> det(M5);

                                  39

> M6:=mulrow(M5,3,0.3);

                             [-3    3      1 ]
                             [               ]
                       M6 := [ 6    3      2 ]
                             [               ]
                             [ 0    .3    -.3]

> det(M6);

                                 11.7

> det(M5)*0.3;

                                 11.7

> M7:=mulcol(M6,2,3);

                             [-3    9      1 ]
                             [               ]
                       M7 := [ 6    9      2 ]
                             [               ]
                             [ 0    .9    -.3]

> det(M7);

                                 35.1

> det(M6)*3;

                                 35.1

> M8:=addrow(M7,1,3,.5);

                            [ -3      9     1 ]
                            [                 ]
                      M8 := [ 6       9     2 ]
                            [                 ]
                            [-1.5    5.4    .2]

> det(M8);

                                 35.1

> M9:=addcol(M8,3,2,1.5);

                            [ -3     10.5    1 ]
                            [                  ]
                      M9 := [ 6      12.0    2 ]
                            [                  ]
                            [-1.5    5.70    .2]

> det(M9);

                                35.10

# A matrix with two identical rows or two identical columns has a zero
# determinant. Change the ? below to create such a matrix and then check
# this property out.
> M10:=matrix(3,3,[?,?,?,?,?,?,?,?,?]);
> det(M10);
# M1 was the inverse matrix of M
> det(M);

                                  39

> det(M1);

                                 1/39

# The determinant of the product is the product of the determinants.
# This does not work with sums however. 
> det(M&*M9);

                              1368.9000

> det(M)*det(M9);

                               1368.90

> det(M+M9);

                                -72.00

> det(M)+det(M9);

                                74.10


