# MAPLE ASSIGNMENT 7
# MATRIX ALGEBRA
# 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);
> M5:=stackmatrix(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 arithmetic 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 again 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(M7);
> evalm((M1+M2)+M7);
> evalm(M1+(M2+M7));
> evalm((M1&*M2)&*M7);
> evalm(M1&*(M2&*M7));
> evalm((M1+M2)-(M2+M1));
# In Maple 0 represents both the number 0 and null matrices of any
# dimensions.
# 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.  The array
# command  can be used to create an identity matrix.
> diag(-3,2,Pi); 
> iden:=array(identity,1..3,1..3);
> evalm(iden);
# B is called an inverse martix of A if B&*A = A*&B = iden. 
# Inverse matrices are calculated either as A^(-1)  or as inverse(A). 
# The following
# commands 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);
> M9:=evalm(M8^(-1));
> evalm(M1-M9);
# 
# SOME AMUSING GRAPHICAL OBJECTS
# The following 3d plots are taken from the Maple V Learning Guide. They
# are included here purely for your entertainment and have nothing to do
# with Econ 331. They can be manipulated in the usual ways. Consider
# adding axes, changing the style or making the scaling constrained (on
# the projection menu).
> with(plottools):
> with(plots):
> display(dodecahedron());
> a:=stellate(dodecahedron()):
> display(a);
> b:=cutout(dodecahedron(),3/4):
> display(b);
> s1:=sphere([3/2,1/4,1/2],1/4,colour=red):
> display(s1);
> s2:=sphere([3/2,-1/4,1/2],1/4,colour=red):
> display(s1,s2);
> c:=cone([0,0,0],1/2,2,colour=khaki):
> display(c);
> c2:=rotate(c,0,Pi/2,0):
> display(c2);
> c3:=translate(c2,3,0,1/4):
> display(c3);
> cup:=hemisphere():
> display(cup);
> cap:=rotate(cup,Pi,0,0):
> display(cap);
> stelhs:=stellate(cap,2):
> display(stelhs);
> display([s1,s2,c3,stelhs]);
> 
> 
