# MAPLE ASSIGNMENT Matrix part 1 # 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): # Next define a few matrices. You can change the numbers to any numbers # you like. > 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]); # The next commands create some other matrices from M1 and M2. > M3:=submatrix(M2,2..3,1..2); > M4:=submatrix(M1,2..3,1..3); > ### WARNING: linalg[stack] has been renamed linalg[stackmatrix] to > avoid collision with mainline stack > M5:=stack(M2,M4); > M6:=concat(M3,M4); # The next command illustrates multiplication by a scalar. Evalm is # needed for the answer to appear # on the screen. Refer back to M6 to see what has happened > evalm(3*M6); # # The aritmetic operations for matrices are + , - , &* , ^ . For easier # reference the next command # brings M1 and M2 back on to the screen side by side in a 3X6 matrix. # Execute the next # command and after you are sure you understand what has happened # execute the command agaiin # with + changed first to - and then to &* . > concat(M1,M2); > evalm(M1+M2); # If you wish to check your understanding of matrix multiplication the # following command calculates the # [2,2] entry of the product matrix. Change the numbers in this command # to calculate some other # entries in the product matrix. If one of the numbers is negative put # it in brackets. > (1*0)+(5*6)+(7*3); # The next comand does a power of a matrix. You can check the answers # out in the same way the # product was checked. > evalm(M1^2); # The following illustrate some of the properties of matrix algebra. A # matrix is transposed when its # rows and columns are switched.. The properties are the associative , # commutative and distributive # properties. > M7:=transpose(M4)&*M4; > evalm(M4); > evalm(M7); > evalm((M1+M2)+M7); > evalm(M1+(M2+M7)); > evalm((M1&*M2)&*M7); > evalm(M1&*(M2&*M7)); > evalm((M1+M2)-(M2+M1)); # The commutative law does not however work with multiplication. > evalm((M1&*M2)-(M2&*M1)); # The final property illustrated here is one of the distributive laws. > evalm((M1+M2)&*M7); > evalm((M1&*M7)+(M2&*M7)); # Diagonal matrices are created with the diag command. This can be used # to create an identity matrix. > diag(-3,2,Pi); > iden:=diag(1,1,1); # Inverse matrices are either A^(-1) or inverse(A). The following # calculate the inverse, check that it # works and illustrate the properties of inverses. You should also try # to calculate the inverse of M2 . > M8:=M1^(-1); > evalm(%); > evalm(M1&*M8-iden); > evalm(M8&*M1-iden); > evalm(M8^(-1)); > M9:=evalm(M1+M7); # The next commands illustrate the correct and the incorrect way to get # the inverse of the product of twp matrices. > evalm((M1&*M9)^(-1)); > evalm((M9^(-1))&*(M1^(-1))); > evalm((M1^(-1))*(M9^(-1))); > evalm((M1^(-1))+(M9^(-1))); > evalm((M1+M9)^(-1)); > # The last two commands have illustrated a dumb artihmetical mistake you # should not make even with numbers.