Lecture 3 Math 221
Matrix Operations
In this section, we will be concerned with different operations on rectangular array of objects all matrices. We will say a matrix A is nxm if it has n row and m columns
For example the following is a 3x2 matrix
and now look at a 2x3 matrix
Addition
At this time, we will look at defining the addition of two matrices. First the matrices must both have the same number of row and columns. i.e. they must be both n x m.
A=(
) and B=(
} where i=1..n and j=1..m. The index i stands for the rows place holder and the j will stand for the column place holder. Taking our lead from vectors in n space we define addition in the following way.
A + B =(
) + (
) ={
) =(
) = C
Let us look at an example
=
=
| > | with(linalg): |
| > | with(LinearAlgebra): |
| > | A:=<<1|2|-3>,<2|3|4>>; |
| > | B:=<<1|-3|2>,<-2|3|-4>>; |
We will first carry out the addition one elemet at a time and them use the shortcut. You need to do a few additions one element at a time to better understand the operation.
| > | C:=<<1+1|2+(-3)|-3+2>,<2+(-2)|3+3|4+(-4)>>; |
| (1.1.1) |
We now check it with the short cut. The check will be call CC
| > | CC:=A+B; |
| (1.1.2) |
You can not add matrices of different dimensions.
+
You are not at liberty to add zeros since two matrices are equal if and only if every entry of one matrix equal that of the other.
A = B if and only if
Scalar Multiplication
Again, following the lead of vectors in n space we can define an operation of scalar multiplication
Let c be a real or complex number and A an nxm matrix of real or complex numbers then
cA = (
)
which means that we are multiplying the scalar c times each entry of the matrix.
Let us look at an example
=
| > | C:=<<2|4/3|-2>,<-1|1/15|1/12>>; |
![]() |
We will again carry out the scalar multiplication one element at a time and then use command in Maple to carryout the operation.
| > | <<3*2|3*4/3|3*(-2)>,<3*(-1)|3*1/15|3*1/12>>; |
![]() |
(1.2.1) |
| > | 3*C; |
![]() |
Addition and Scalar Multiplication Properties
With addition and scalar multiplication defined it now easy to verify that the set of all nxm matrices satisfy the following set of properties
Let A, B and C be n x m matrices and
and
be scalars
1. A + B is an nxm matrix. We say that the set of nxm matrices is closed under addition.
2. A + B = B+ A Addition is commutative
3. (A + B) + C = A + (B + C) addition is associative
4. There is a Zero n x m matrix such that A + O = A
5. A + (-A) = O note here O is an nxm matrix not a scalar.
6.
A is an nxm matrix. We say that the set of nxm matrices is closed under scalar multiplication
7. (
) A =
(
A)
8. (
) A = (
) A + (
) B
9.
( A + B ) =
A +
B
10. 1 A = A
You may have thought for a few minutes that vectors were a special case of matrices but it turns out that the set of all nxm matrices from a vector space so they can be thought of as vectors.
Multiplication of n x m matrices by m x p matrices
We will now return to the way we through of as writing a system of equation as a matrix by a column vector or matrix.
=
This time we will use numbers for the x, y and z
=
=
Notice that a 3x3 matrix times a 3x1 matrix is a 3x1 matrix. The entry in the first row and first column of the matrix is the inner product of the first row of A times the first column of b and the entry in the second row is the inner product of second row of A times the first column of b.
Finally the third row of the product is the inner product of the third row of A times the first column of b. We are now ready to expand the definition of multiplication of two matrices to a matrix B that has more than one column.
Let A be n x m and B be m x p then the product will be a matrix C which is n x p where
the entry in i, j position of C is the inner product of the ith row of A times the jth column of B.
=
i=1..n j=1..p
Now let us look at an example
A B=
=
=
We should also check the dimension. 3x2 times a 2x3 should lead to a 3x3 which is what we obtained.
Notice that we can also find BA, which may not always be possible
BA =
=
It is quite obvious that AB is not equal to BA. You may ask about what if we have two nxn matrices or square matrices.
=
while
=
There are very few matrices that commute with a given matrix. We must never assume that matrices commute in general when it comes to multiplication.
If A is square i.e. nxn then the nxn matrix with all ones on the diagonal i=j and zero every place else is call the identity I and we see that I will commute with all square matrices
A*I = I*A
Also, if O is an nxn square matrix will all zeros we have:
A*O=O*A
For square matrices. we also have that A*(B*C)=(A*B)*C and we write it as A*B*C
Also A*(B+C)=A*B +A*C See Theorem 1.22 in text.
The following are the Maple commands to carry out the about matrix multiplications
| > | M:=<<1|-2|3>,<2|1|3>,<3|-1|1>>; |
![]() |
| > | c:=<-3,2,-1>; |
![]() |
| > |
We will now do the product one element at a time and check it with the maple short cut. The product will be named Mc.
| > | Mc:=<0,0,0>; |
![]() |
We will look at a set of commands to extract the rows for the matrix M. After this example we will not be extracting the row one step at a time.
| > | Row(M,1); |
| (1.5.1) |
| > | Row(M,2); |
| (1.5.2) |
| > | Row(M,3); |
| (1.5.3) |
| > | Mc:=<Row(M,1).c,Row(M,2).c,Row(M,3).c>; |
![]() |
(1.5.4) |
We will now check using a single Maple command. You need to do several problems one element at a time so you better understand Matrix multiplication.
| > | M.c; |
| (1.5.5) |
The next example will multiply a 3x2 matrix and a 2x3 matrix. The resulting matrix will be a 3x3 matrix.
| > | A:=<<1|2>,<2|1>,<3|1>>; |
![]() |
| > | B:=<<2|1|3>,<-1|3|1>>; |
The matrix product will now be calcuated one element at a time and put in the location AB
| > | AB:=<<Row(A,1).Column(B,1)|Row(A,1).Column(B,2)|Row(A,1).Column(B,3)>,<Row(A,2).Column(B,1)|Row(A,2).Column(B,2)|Row(A,2).Column(B,3)>,<Row(A,3).Column(B,1)|Row(A,3).Column(B,2)|Row(A,3).Column(B,3)>>; |
![]() |
(1.5.6) |
Now we check our work by using the single Maple command.
| > | A.B; |
![]() |
(1.5.7) |
You need to work out several matrix multiplications the long way so you understand completely matrix multiplication.
| (1.5.8) |
To show that multiplication does not commute we will use the short cut to find the product of B times A.
| > | B.A; |
| > | I3:=ToeplitzMatrix(<1,0,0>,3,symmetric); |
![]() |
The letter I is reserved in Maple for the complex number that is the square root of -1. This is why I3 was used for the 3x3 identity.
| > | M.I3; |
![]() |
| > | I3.M; |
![]() |
| > | Z3:=ToeplitzMatrix(<0,0,0>,3,symmetric); |
![]() |
| > | Z3.M=M.Z3; |
![]() |
Special Matrix Operations
Transpose of a Matrix
If A = (
) is an nxm matrix then we define
= (
) where
Another way to think of
this is the matrix that is obtained by interchanging the row and columns of the matrix A.
Example
then
Another property of the transpose comes from taking the transpose of the product of two matrices.
You must remember this property for the remainder of the time you work with matrices. If you take the transpose of the product than it is equal to the product of the individual matrices in reverse order.
Let
then
and
and
=
You need to check that
is not equal to
A matrix is said to be symmetric if
and skew-symmetric if
The following matrix is symmetric
while the follow is skew-symmetric
What do you know about the diagonal of any skew-symmetric matrix? Then only way that a diagonal element can be equal to is negative is if the element is zero.
There is a relationship between the product of the transpose of a columns matrix and itself and the norm.
If a is nx1 then
is 1xn then the product is 1x1 or a scalar
For example
and its transpose is
so the product is
= 13 which is the square of the two norm of the column vector or column matrix. The inner product of a b
can be obtain by looking at the following matrix product
Consider the two column vectors
and
so the inner product of a and b can be found by looking at the
product
which is
= 1*2 + 3*(-3) + (-2)*4 = 2-9-8=-15
| > | A:=<<1|2>,<3|-1>,<4|-5>>; |
![]() |
| > | AT:=A^%T; |
| > | B:=<<1|0|1>,<2|1|3>>; |
| > | BT:=B^%T; |
![]() |
| > | AB:=A.B; |
![]() |
| > | AB^%T; |
![]() |
| > | BT.AT; |
![]() |
| > | a:=<1,3,-2>; |
![]() |
(1.6.1) |
| > | b:=<2,-3,4>; |
![]() |
(1.6.2) |
| > | a^%T.b; |
| (1.6.3) |
This is the scalar that we are looking for. Now reverse the vectors of matrices and see what we get. Will we get the same answer?
| > | a.b^%T; |
![]() |
(1.6.4) |
Again recall that a is 3x1 and the transpose of b is 1x3 so we should have obtained a 3x3 as illustrated above.
A diagonal matrix must have all entries not on the diagonal equal to zero. Diagonal entries are that in the same row and column. i.e. (1,1),(2,2),...(n,n) entries.
The diagonal elements can be zero. In fact the zero matrix is considered a diagonal matrix.
| > |
| > | L:=[1,-2,1,4]; |
| (1.6.5) |
| > | Dd:=DiagonalMatrix(L); |
![]() |
(1.6.6) |
We will now illustrate upper and lower triangular matrices. An upper triangular matrix must have zeros below the diagonal and a lower triangular matrix must have zero above the diagonal. Putting the two ideas together we see that a matrix that is both lower triangular and upper triangular is a diagonal matrix.
| > | U:=<<3,0,0,0>|<2,1,0,0>|<4,2,1,0>|<-2,1,-3,1>>; |
![]() |
(1.6.7) |
I have not found a good way to create an upper or lower triangular matrix.
| > | L:<<4|0|0|0>,<3|1|0|0>,<-3|2|5|0>,<6|2|-3|1>>; |
![]() |
(1.6.8) |
The following will give you a nonsymmetric Toeplitz matrix This will be followed by the symmetric Toeplitz command. You need to notice the difference.
| > | NST:=ToeplitzMatrix([2,1,4,-5,3,6,-3],4); |
![]() |
(1.6.9) |
A Toeplitz matrix as discussed in you text is constant along all diagonals starting in the southwest corner or the matrix and working to the northeast corner.
| > | T:=ToeplitzMatrix([2,-3,1,4],4,symmetric); |
![]() |
(1.6.10) |
Notice that the toeplitz command starts with the first entry on the main diagonal and works its way across the first row and then makes the matrix symmetric.
| > |
| > |
Block Matrices
The temperature matrix is given by
C =
and the left hand side is given by
let
and
then the matrix T can be written as a matrix of a matrix in the following way
and the temperature as
and
while the left hand side can be written as
and
. Using this notation we see that we can rewrite
the above system as
which is a 2x2 block matrix times a 2x1 block equals a 2x1 block.
We can carry out matrix multiplication by using block matrices.
| > | S1:=<<4,-1>|<-1,4>>; |
| > |
| > | I2:=ToeplitzMatrix([1,0],2,symmetric); |
| > | C:=blockmatrix(2,2,[S1,-I2,-I2,S1]); |
![]() |
| > | BT1:=<<45,80>>; |
| > | BT2:=<<40,70>>; |
| > | BT:=blockmatrix(2,1,[BT1,BT2]); |
![]() |
| > | T11:=<<T1,T2>>; |
| > | T21:=<<T3,T4>>; |
| > | T:=blockmatrix(2,1,[T11,T21]); |
![]() |
| > | R1:=<<S,-I2>|<-I2,S>>; |
![]() |
| > | TT:<<T11,T21>>; |
| > |
| > |
| > | R1.T=<<BT1,BT2>>; |
![]() |
| > |
Exercises
Problems to be turned in by email or a hard copy on September 10, 2008 are problems 1.3.9,1.3.11, 1.3.12, 1.3.23, 1.3,24 The problems are to be done in a Maple worksheet.
Problems to be turned in by email or a hard copy on September 12, 2008 1.3.39, 1.3.44, 1.3.49, 1.3.56
Section 1.3
Problems 1.3.12, (Work this problem the long way finding each element as in the lecture when I found the matrix AB) 1.3.23, 1.3.24, (Do you get the same answer in problems 1.3.23 and 1.3.24? Why or why not. You may use . command here ). 1.3.39 (Use the Row and Column commands for this problem), 1.3.44 (Use the row and column commands for this problem), 1.3.49, 1.3.56 The last two problems can be worked using the short cuts.