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 

Typesetting:-mrow(Typesetting:-mfenced(Typesetting:-mrow(Typesetting:-mi( and now look at a 2x3 matrix Typesetting:-mrow(Typesetting:-mfenced(Typesetting:-mrow(Typesetting:-mi(  

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=(Typesetting:-mrow(Typesetting:-msub(Typesetting:-mi( )  and B=(Typesetting:-mrow(Typesetting:-msub(Typesetting:-mi( } 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 =( Typesetting:-mrow(Typesetting:-msub(Typesetting:-mi() + (Typesetting:-mrow(Typesetting:-msub(Typesetting:-mi() ={Typesetting:-mrow(Typesetting:-mi() =(Typesetting:-mrow(Typesetting:-msub(Typesetting:-mi() = C 

Let us look at an example 

 

Typesetting:-mrow(Typesetting:-mi( = Typesetting:-mrow(Typesetting:-mfenced(Typesetting:-mrow(Typesetting:-mi(= Typesetting:-mrow(Typesetting:-mfenced(Typesetting:-mrow(Typesetting:-mi(  

 

> with(linalg):
 

> with(LinearAlgebra):
 

 

> A:=<<1|2|-3>,<2|3|4>>;
 

Typesetting:-mrow(Typesetting:-mverbatim(
 

 

> B:=<<1|-3|2>,<-2|3|-4>>;
 

Typesetting:-mrow(Typesetting:-mverbatim(
 

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)>>;
 

Typesetting:-mrow(Typesetting:-mverbatim( (1.1.1)
 

We now check it with the short cut.  The check will be call CC 

 

> CC:=A+B;
 

Typesetting:-mrow(Typesetting:-mverbatim( (1.1.2)
 

 

 

 

 

 

 

 

You can not add matrices of different dimensions. 

 

Typesetting:-mrow(Typesetting:-mfenced(Typesetting:-mrow(Typesetting:-mi( + Typesetting:-mrow(Typesetting:-mfenced(Typesetting:-mrow(Typesetting:-mi(  

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 Typesetting:-mrow(Typesetting:-mi(
 

 

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 = (Typesetting:-mrow(Typesetting:-mi() 

which means that we are multiplying the scalar c times each entry of the matrix. 

Let us look at an example 

 

          Typesetting:-mrow(Typesetting:-mi( = Typesetting:-mrow(Typesetting:-mfenced(Typesetting:-mrow(Typesetting:-mi( 

 

 

 

> C:=<<2|4/3|-2>,<-1|1/15|1/12>>;
 

Typesetting:-mrow(Typesetting:-mverbatim(
 

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>>;
 

Typesetting:-maction(Typesetting:-mverbatim( (1.2.1)
 

 

> 3*C;
 

Typesetting:-maction(Typesetting:-mverbatim(
 

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 Typesetting:-mrow(Typesetting:-mi( and Typesetting:-mrow(Typesetting:-mi( 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. Typesetting:-mrow(Typesetting:-mi( A  is an nxm matrix.  We say that the set of nxm matrices is closed under scalar multiplication 

7. ( Typesetting:-mrow(Typesetting:-mi( ) A = Typesetting:-mrow(Typesetting:-mi((Typesetting:-mrow(Typesetting:-mi( A)   

8.  (Typesetting:-mrow(Typesetting:-mi( ) A = ( Typesetting:-mrow(Typesetting:-mi( ) A + ( Typesetting:-mrow(Typesetting:-mi( ) B 

9.  Typesetting:-mrow(Typesetting:-mi( ( A + B ) = Typesetting:-mrow(Typesetting:-mi( A + Typesetting:-mrow(Typesetting:-mi( 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.   

Typesetting:-mrow(Typesetting:-mi( = Typesetting:-mrow(Typesetting:-mfenced(Typesetting:-mrow(Typesetting:-mi(
 

This time we will use numbers for the x, y and z 

 

Typesetting:-mrow(Typesetting:-mi(= Typesetting:-mrow(Typesetting:-mfenced(Typesetting:-mrow(Typesetting:-mi(= Typesetting:-mrow(Typesetting:-mfenced(Typesetting:-mrow(Typesetting:-mi(
 

 

 

 

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. 

                                      Typesetting:-mrow(Typesetting:-mi( = Typesetting:-mrow(Typesetting:-msub(Typesetting:-mi(   i=1..n  j=1..p 

Now let us look at an example 

 

A B= Typesetting:-mrow(Typesetting:-mi(=Typesetting:-mrow(Typesetting:-mfenced(Typesetting:-mrow(Typesetting:-mi(=Typesetting:-mrow(Typesetting:-mfenced(Typesetting:-mrow(Typesetting:-mi(
 

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 = Typesetting:-mrow(Typesetting:-mfenced(Typesetting:-mrow(Typesetting:-mi( = Typesetting:-mrow(Typesetting:-mfenced(Typesetting:-mrow(Typesetting:-mi(
 

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. 

 

Typesetting:-mrow(Typesetting:-mi( = Typesetting:-mrow(Typesetting:-mfenced(Typesetting:-mrow(Typesetting:-mi( while Typesetting:-mrow(Typesetting:-mi(= Typesetting:-mrow(Typesetting:-mfenced(Typesetting:-mrow(Typesetting:-mi(
 

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>>;
 

Typesetting:-mrow(Typesetting:-mverbatim(
 

> c:=<-3,2,-1>;
 

 

Typesetting:-mrow(Typesetting:-mverbatim(
 

>
 

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>;
 

Typesetting:-mrow(Typesetting:-mverbatim(
 

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);
 

Typesetting:-maction(Typesetting:-mverbatim( (1.5.1)
 

> Row(M,2);
 

Typesetting:-maction(Typesetting:-mverbatim( (1.5.2)
 

> Row(M,3);
 

Typesetting:-maction(Typesetting:-mverbatim( (1.5.3)
 

> Mc:=<Row(M,1).c,Row(M,2).c,Row(M,3).c>;
 

Typesetting:-mrow(Typesetting:-mverbatim( (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;
 

 

Typesetting:-maction(Typesetting:-mverbatim( (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>>;
 

Typesetting:-mrow(Typesetting:-mverbatim(
 

> B:=<<2|1|3>,<-1|3|1>>;
 

Typesetting:-mrow(Typesetting:-mverbatim(
 

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)>>;
 

Typesetting:-mrow(Typesetting:-mverbatim( (1.5.6)
 

Now we check our work by using the single Maple command.   

 

> A.B;
 

Typesetting:-maction(Typesetting:-mverbatim( (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;
 

Typesetting:-maction(Typesetting:-mverbatim(
 

> I3:=ToeplitzMatrix(<1,0,0>,3,symmetric);
 

Typesetting:-mrow(Typesetting:-mverbatim(
 

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;
 

Typesetting:-maction(Typesetting:-mverbatim(
 

> I3.M;
 

Typesetting:-maction(Typesetting:-mverbatim(
 

> Z3:=ToeplitzMatrix(<0,0,0>,3,symmetric);
 

 

Typesetting:-mrow(Typesetting:-mverbatim(
 

> Z3.M=M.Z3;
 

Typesetting:-mrow(Typesetting:-mverbatim(
 

Special Matrix Operations 

Transpose of a Matrix  

 

If A = ( Typesetting:-mrow(Typesetting:-msub(Typesetting:-mi( ) is an nxm matrix then we define Typesetting:-mrow(Typesetting:-msup(Typesetting:-mi( = (Typesetting:-mrow(Typesetting:-msub(Typesetting:-mi()  where Typesetting:-mrow(Typesetting:-mi(
Another way to think of Typesetting:-mrow(Typesetting:-msup(Typesetting:-mi( this is the matrix that is obtained by interchanging the row and columns of the matrix A.  
 

 

Example 

Typesetting:-mrow(Typesetting:-mi( then Typesetting:-mrow(Typesetting:-mi(
 

Another property of the transpose comes from taking the transpose of the product of two matrices. 

 

          Typesetting:-mrow(Typesetting:-mi(
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 Typesetting:-mrow(Typesetting:-mi( then Typesetting:-mrow(Typesetting:-mi( and Typesetting:-mrow(Typesetting:-mi(
and Typesetting:-mrow(Typesetting:-mi(= Typesetting:-mrow(Typesetting:-mfenced(Typesetting:-mrow(Typesetting:-mi(
 

You need to check that Typesetting:-mrow(Typesetting:-mi( is not equal to Typesetting:-mrow(Typesetting:-msup(Typesetting:-mfenced(Typesetting:-mrow(Typesetting:-mi(
 

A matrix is said to be symmetric if Typesetting:-mrow(Typesetting:-mi( and skew-symmetric if Typesetting:-mrow(Typesetting:-mi(
 

The following matrix is symmetric 

 

Typesetting:-mrow(Typesetting:-mfenced(Typesetting:-mrow(Typesetting:-mi( while the follow is skew-symmetric Typesetting:-mrow(Typesetting:-mfenced(Typesetting:-mrow(Typesetting:-mi(
 

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 Typesetting:-mrow(Typesetting:-msup(Typesetting:-mi( is 1xn then the product is 1x1 or a scalar 

 

For example 

Typesetting:-mrow(Typesetting:-mfenced(Typesetting:-mrow(Typesetting:-mi( and its transpose is Typesetting:-mrow(Typesetting:-mfenced(Typesetting:-mrow(Typesetting:-mi(  so the product is  

Typesetting:-mrow(Typesetting:-mi( = 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 Typesetting:-mrow(Typesetting:-mi(   

 

Consider the two column vectors 

 

Typesetting:-mrow(Typesetting:-mi( and Typesetting:-mrow(Typesetting:-mi(   so the inner product of a and b can be found by looking at the  

product Typesetting:-mrow(Typesetting:-mi(  which is Typesetting:-mrow(Typesetting:-mi(= 1*2 + 3*(-3) + (-2)*4 = 2-9-8=-15  

> A:=<<1|2>,<3|-1>,<4|-5>>;
 

Typesetting:-mrow(Typesetting:-mverbatim(
 

> AT:=A^%T;
 

Typesetting:-mrow(Typesetting:-mverbatim(
 

> B:=<<1|0|1>,<2|1|3>>;
 

Typesetting:-mrow(Typesetting:-mverbatim(
 

> BT:=B^%T;
 

Typesetting:-mrow(Typesetting:-mverbatim(
 

> AB:=A.B;
 

Typesetting:-mrow(Typesetting:-mverbatim(
 

> AB^%T;
 

Typesetting:-maction(Typesetting:-mverbatim(
 

> BT.AT;
 

Typesetting:-maction(Typesetting:-mverbatim(
 

> a:=<1,3,-2>;
 

Typesetting:-mrow(Typesetting:-mverbatim( (1.6.1)
 

> b:=<2,-3,4>;
 

Typesetting:-mrow(Typesetting:-mverbatim( (1.6.2)
 

> a^%T.b;
 

-15 (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;
 

Typesetting:-maction(Typesetting:-mverbatim( (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, -2, 1, 4] (1.6.5)
 

> Dd:=DiagonalMatrix(L);
 

Typesetting:-mrow(Typesetting:-mverbatim( (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>>;
 

Typesetting:-mrow(Typesetting:-mverbatim( (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>>;
 

Typesetting:-maction(Typesetting:-mverbatim( (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);
 

Typesetting:-mrow(Typesetting:-mverbatim( (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);
 

Typesetting:-mrow(Typesetting:-mverbatim( (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 = Typesetting:-mrow(Typesetting:-mfenced(Typesetting:-mrow(Typesetting:-mi( and the left hand side is given by Typesetting:-mrow(Typesetting:-mfenced(Typesetting:-mrow(Typesetting:-mi(
let Typesetting:-mrow(Typesetting:-mi( and Typesetting:-mrow(Typesetting:-mi( then the matrix T can be written as a matrix of a matrix in the following way
 

Typesetting:-mrow(Typesetting:-mi(
 and the temperature as Typesetting:-mrow(Typesetting:-mi( and Typesetting:-mrow(Typesetting:-mi( while the left hand side can be written as Typesetting:-mrow(Typesetting:-mi(  and Typesetting:-mrow(Typesetting:-mi(.  Using this notation we see that we can rewrite
 

the above system as  Typesetting:-mrow(Typesetting:-mi(
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>>;
 

Typesetting:-mrow(Typesetting:-mverbatim(
 

>
 

> I2:=ToeplitzMatrix([1,0],2,symmetric);
 

Typesetting:-mrow(Typesetting:-mverbatim(
 

> C:=blockmatrix(2,2,[S1,-I2,-I2,S1]);
 

`:=`(C, Typesetting:-mfenced(Typesetting:-mrow(Typesetting:-mtable(Typesetting:-mtr(Typesetting:-mtd(Typesetting:-mn(
 

> BT1:=<<45,80>>;
 

Typesetting:-mrow(Typesetting:-mverbatim(
 

> BT2:=<<40,70>>;
 

Typesetting:-mrow(Typesetting:-mverbatim(
 

> BT:=blockmatrix(2,1,[BT1,BT2]);
 

`:=`(BT, Typesetting:-mfenced(Typesetting:-mrow(Typesetting:-mtable(Typesetting:-mtr(Typesetting:-mtd(Typesetting:-mn(
 

> T11:=<<T1,T2>>;
 

Typesetting:-mrow(Typesetting:-mverbatim(
 

> T21:=<<T3,T4>>;
 

Typesetting:-mrow(Typesetting:-mverbatim(
 

> T:=blockmatrix(2,1,[T11,T21]);
 

`:=`(T, Typesetting:-mfenced(Typesetting:-mrow(Typesetting:-mtable(Typesetting:-mtr(Typesetting:-mtd(Typesetting:-mi(
 

> R1:=<<S,-I2>|<-I2,S>>;
 

Typesetting:-mrow(Typesetting:-mverbatim(
 

> TT:<<T11,T21>>;
 

Typesetting:-maction(Typesetting:-mverbatim(
 

>
 

>
 

> R1.T=<<BT1,BT2>>;
 

Typesetting:-mrow(Typesetting:-mverbatim(
 

>
 

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.