Matrices and matrix operations
| > | with(LinearAlgebra); |
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
![]()
Here are several ways to define matrices (actually it is the same matrix defined in sevral different ways)
| > | A1:=Matrix([[2,1,0,3],[-1,0,2,4],[4,-2,7,0]]); |
| > | A2:=Array([[2,1,0,3],[-1,0,2,4],[4,-2,7,0]]); |
| > | A3:=<<2,-1,4>|<1,0,-2>|<0,2,7>|<3,4,0>>; |
| > | A4:=Matrix(3,4,[[2,1,0,3],[-1,0,2,4],[4,-2,7,0]]); |
Notice a special matrix, the identity matrix that is a square matrix and has non-zero entries only on the main diagonal, on which it has only ones.
| > | I3:=IdentityMatrix(3); |
| > | I4:=IdentityMatrix(5); |
See what is special about multiplying by an identity matrix.
| > | Multiply(I3,A4); |
| > | Multiply(A4,I3); |
Error, (in LinearAlgebra:-MatrixMatrixMultiply) first matrix column dimension (4) <> second matrix row dimension (3)
Well, it looks like order does matter when we try to multiply matrices.
Finding the transpose of a matrix.
| > | A3t:=Transpose(A3); |
Let us multiply the matrix A3 with its transpose A3t, and also A3t with A3.
| > | B1:=Multiply(A3,A3t); |
| > | B2=Multiply(A3t,A3); |
As you can see the two products are not the same.
Let us also see what happens if we want to multiply the matrix A1 by itself:
| > | Multiply(A1,A1); |
Error, (in LinearAlgebra:-MatrixMatrixMultiply) first matrix column dimension (4) <> second matrix row dimension (3)
Oops, it did not work again!
Let us see more matrix operations such as mulitplication by a scalar and addition:
| > | C1:=Matrix([[-2,1,3],[-1,1,5],[1,-2,6]]); |
| > | C2:=Matrix([[-1,1,2],[0,1,2],[-1,-3,12]]); |
| > | C:=2*C1-5*C2; |
| > |