Lecture 4 Math 221 

Block Matrices  

Here is another example of how to build a matrix using the blockmatix command.  

 

> with(linalg):
 

> with(LinearAlgebra):
 

 

> A11:=<<1|2|1>,<3|2|1>>;
 

Typesetting:-mrow(Typesetting:-mverbatim(
 

> A12:=<<1|3>,<2|1>>;
 

Typesetting:-mrow(Typesetting:-mverbatim(
 

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

Typesetting:-mrow(Typesetting:-mverbatim(
 

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

Typesetting:-mrow(Typesetting:-mverbatim(
 

The 2,2 in the following blockmatrix command is used because we want a 2x2 block construction.  The entries are tne enteried by rows starting with the first row and followed by the second row.  The notation used is to illustrated that A11 is the block matrix in the 1,1 position followed by the A12 which is the block in the first row and second column.  The second row is then labeled in a similar manner.  

> A:=blockmatrix(2,2,[A11,A12,A21,A22]);
 

Typesetting:-mrow(Typesetting:-mverbatim(
 

> B11:=<<1|2>,<2|1>,<3|2>>;
 

Typesetting:-mrow(Typesetting:-mverbatim(
 

> B21:=<<-1|1>,<2|2>>;
 

Typesetting:-mrow(Typesetting:-mverbatim(
 

> B12:=<<2|1>,<-2|2>,<-1|1>>;
 

Typesetting:-mrow(Typesetting:-mverbatim(
 

> B22:=<<1|1>,<1|-2>>;
 

Typesetting:-mrow(Typesetting:-mverbatim(
 

> B:=blockmatrix(2,2,[B11,B12,B21,B22]);
 

Typesetting:-mrow(Typesetting:-mverbatim(
 

> C:=evalm(A&*B);
 

Typesetting:-mrow(Typesetting:-mverbatim(
 

We have not run into a problems using the new command for mutiplication.  The evalm command is from the with(linalg) package and must be used when we use the blockmatrix command from the with(linearalg): package.  You must use the &* with the package for matrix multiplication.    

> CA:=blockmatrix(2,2,[A11&*B11+A12&*B21,A11&*B12+A12&*B22,A21&*B11+A22&*B21,A21&*B12+A22&*B22]);
 

Typesetting:-mrow(Typesetting:-mverbatim(
 

Gauss Elimination (Unique Solutions) 

 

We will now start to solve the systems of equation introduced in section 2  

Consider two straight lines in two space. 

 

2x + 3y = 5 

3x + 2y = 6  

 

You could solve the first equation for x and then plug the value into the second. 

Typesetting:-mrow(Typesetting:-mi(  and then Typesetting:-mrow(Typesetting:-mi(   which leads to  Typesetting:-mrow(Typesetting:-mi(  of y = 3/5 

 

Now we go back to the first equation and have Typesetting:-mrow(Typesetting:-mi(  and then solve for x 

 

Another way is to go back to the equations and try to find two equation that go through the same point . 

     Typesetting:-mrow(Typesetting:-mfrac(Typesetting:-mrow(Typesetting:-mn( = 15/2             or     (-1)   ( Typesetting:-mrow(Typesetting:-mi(    

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

  The negative sign means to multiply the first equation (every term) and now we add replacing the second equation by the results of the addition. 

 

  Typesetting:-mrow(Typesetting:-mi(                or     Typesetting:-mrow(Typesetting:-mi(      
         Typesetting:-mrow(Typesetting:-mi(                              y = 3/5
 

 

The equation on the right comes from the one on the left by multiplying both sides by -2/5.  We can now use matrix notation to really get at what is going on. 

 

 

> A:=<<2|3>,<3|2>>;
 

Typesetting:-mrow(Typesetting:-mverbatim(
 

> b:=<<5,6>>;
 

Typesetting:-mrow(Typesetting:-mverbatim(
 

> Ab:=<A|b>;
 

Typesetting:-mrow(Typesetting:-mverbatim(
 

> Ab1:=addrow(Ab,1,2,-3/2);
 

Typesetting:-mrow(Typesetting:-mverbatim(
 

The addrow command comes from the with(linalg): package and is more descriptive of what is going on than the similar command in the with(LinearAlgebra) package. 

The addrow is read as follows:  multipliy row 1 by -3/2 and add to row 2.  The row 1 is the first entry after the matrix Ab.   

> Ab2:=mulrow(Ab1,2,-2/5);
 

Typesetting:-mrow(Typesetting:-mverbatim( (2.1)
 

We now see that y=3/5 since the entry in the 2,2 position is 1 and this is then the coefficient of y .  Now to find the value of x 

 

> x:=1/2*(5-3*(3/5));
 

`/`(8, 5) (2.2)
 

The value of x is obtained by taking 3* y=3*(3/5) and moving it to the right hand of the equation and then we have 2*x=(5-3*(3/5)).  We want the value of x so the final calculation would be x=1/2*(5-3*(3/5)); 

The following is a short cut using Maple.  

> X:=backsub(Ab1);
 

Typesetting:-mrow(Typesetting:-mverbatim(
 

Notice that the way we are working is to make all entries under the 1,1 position zero.  We will illustrate this with a 3x3.  You need to read the next exmaple very carefully.  Follow the pattern do not jump around.  This is an algorithm and needs to be done in the correct order.   

Exmaple 2 

We will now look at a three by three to see what is going on.   

Typesetting:-mrow(Typesetting:-mi(Typesetting:-mrow(Typesetting:-mi( and x + 3y +3z =3
      or        Typesetting:-mrow(Typesetting:-mi(  
 

 

Augmenting the coefficient matrix with the right hand side we obtain the matrix 

 

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

We will now do row operations to get the coefficient matrix into upper triangular form.  We will make the entries under the entry in the 1,1 position zero by using the addrow command then we will go to the entry in the 2,2 position and repeat the process.   

 

 

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

Typesetting:-mrow(Typesetting:-mverbatim(
 

> e:=<<5,1,2>>;
 

Typesetting:-mrow(Typesetting:-mverbatim(
 

> Ee:=<E|e>;
 

Typesetting:-mrow(Typesetting:-mverbatim(
 

> Ee1:=addrow(Ee,1,2,2);
 

Typesetting:-mrow(Typesetting:-mverbatim(
 

> Ee2:=addrow(Ee1,1,3,-1);
 

Typesetting:-mrow(Typesetting:-mverbatim(
 

Now move to the entry in the 2,2 position and then zero out the entries below it.  Here there is only the 5 in the 3,2 position.   

> Ee3:=addrow(Ee2,2,3,5);
 

Typesetting:-mrow(Typesetting:-mverbatim(
 

> Ee4:=mulrow(Ee3,3,1/16);
 

Typesetting:-mrow(Typesetting:-mverbatim(
 

> sol:=backsub(Ee4);
 

Typesetting:-mrow(Typesetting:-mverbatim(
 

Let us do the back substitution one step at a time. 

 

> z:=13/4;
 

`/`(13, 4) (2.3)
 

> y:=3*z -11;
 

-`/`(5, 4) (2.4)
 

> x:=2*y -z +5;
 

-`/`(3, 4) (2.5)
 

Unless the entry in the first row and first column is zero we will always work from the upper left hand corner to the lower right hand corner.  This is an algorithm and you should never jump around in trying to obtain zeros when doing Gauss elimination.  Sometimes we need to switch row when we encounter a zero as a pivot element.  Using Maple with the addrow commands should help you with the process since you will not have to worry about using fractions.  Students when doing problems by hand will try a lot of things to avoid using fractions.  Again remember to always work from top to bottom and from left to right.  You always want to zero out the elements under a pivot element.   

We would like to consider the following system 

 

 

 

Example  3.   

> C:=<<1|2|3|4>,<2|3|1|4>,<2|4|6|9>,<-1|3|2|1>>;
 

Typesetting:-mrow(Typesetting:-mverbatim(
 

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

Typesetting:-mrow(Typesetting:-mverbatim(
 

> Cc:=<C|c>;
 

Typesetting:-mrow(Typesetting:-mverbatim(
 

> Cc1:=addrow(Cc,1,2,-2);
 

Typesetting:-mrow(Typesetting:-mverbatim(
 

> Cc2:=addrow(Cc1,1,3,-2);
 

Typesetting:-mrow(Typesetting:-mverbatim(
 

> Cc3:=addrow(Cc2,1,4,1);
 

Typesetting:-mrow(Typesetting:-mverbatim(
 

> Cc4:=addrow(Cc3,2,4,5);
 

Typesetting:-mrow(Typesetting:-mverbatim(
 

> Cc5:=swaprow(Cc4,3,4);
 

Typesetting:-mrow(Typesetting:-mverbatim(
 

 

> x:=backsub(Cc5);
 

Typesetting:-mrow(Typesetting:-mverbatim(
 

Notice that when we a zero as a pivot element in Cc4   i.e. (3.3) position above we used the swaprow command to get a non-zero element in the pivot position.  The backsub command is a short cut for doing a step by step back substitution.  Lets look at how we can carry out the process in a step by step method. 

 

> w:=-3;
 

-3 (2.6)
 

> z:=-(15*w +8)/20;
 

`/`(37, 20) (2.7)
 

> y:=-5*z +(-4*w) -1;
 

`/`(7, 4) (2.8)
 

> x:= -2*y - 3*z -4*w +1;
 

`/`(79, 20) (2.9)
 

As you can see we are assuming there is an equal sign before the last column and then moving the element to the left and changing sign and multiplying by the coefficient of the diagonal element to find the unknowns.  Maple makes it easy to check that you have made no mistakes.   

 

Gauss-Jordan 

Another way to obtain the solutions to a system of equations is to continue past the row echelon form and convert the coefficient matrix to the identity.  The solution will then be the last column of the augmented matrix.  Let us return to Ee4 

Example 2 Looked at again startin with Ee4 

> evalm(Ee4);
 

Typesetting:-mfenced(Typesetting:-mrow(Typesetting:-mtable(Typesetting:-mtr(Typesetting:-mtd(Typesetting:-mn(
 

> Ee5:=addrow(Ee4,3,2,-3);
 

Typesetting:-mrow(Typesetting:-mverbatim(
 

> Ee6:=addrow(Ee5,3,1,-1);
 

Typesetting:-mrow(Typesetting:-mverbatim(
 

> Ee7:=mulrow(Ee6,2,-1);
 

Typesetting:-mrow(Typesetting:-mverbatim(
 

> Ee8:=addrow(Ee7,2,1,2);
 

Typesetting:-mrow(Typesetting:-mverbatim(
 

As you can see we do not need to use the back substitution to find the solution. 

We can also apply the Gauss-Jordan technique to the matrix Cc5; to finish the problem 

 

Example 3 looked at again starting after Cc5.   

> Cc6:=addrow(addrow(addrow(Cc5,4,3,15),4,2,4),4,1,-4);
 

Typesetting:-mrow(Typesetting:-mverbatim(
 

> Cc7:=mulrow(Cc6,3,-1/20);
 

Typesetting:-mrow(Typesetting:-mverbatim(
 

> Cc8:=addrow(addrow(Cc7,3,2,5),3,1,-3);
 

Typesetting:-mrow(Typesetting:-mverbatim(
 

> Cc9:=mulrow(Cc8,2,-1);
 

Typesetting:-mrow(Typesetting:-mverbatim(
 

> CC10:=addrow(Cc9,2,1,-2);
 

Typesetting:-mrow(Typesetting:-mverbatim(
 

Again look at each step.  There is definite pattern to doing the operation.  This is the shortest way to the answer.  Just doing random row operations will cause you all kinds of problems.  If you get this down correctly at this point you will have no problem when we get to the LU decomposition.  If you jump around all over the place like at least one student does every term then you will have not hope when it comes to the LU decompostion.     

If you computer can work in parallel the number of operation counts used for a Gauss-Jordan process will be the same or a little less than doing Gauss.  If you computer does not use parallel processing then the number of operations counts for Gauss with backsub is considered better.  (Time to each step)  

 

Exercises 

Problems to be turned in by email or a hard copy handed in by September 15,  2008 

Problem 1.4,15, 1.4.23,  1.4.29 (For the problems 1.4.15 and 1.429 with Gauss carry out the back substitution one step at a time and then check by using the backsub command.  1.4.23  use the gausselim command and then the backsub command for this problem.  1.4.44 (you turned in this model in the previous assignment).  Work the last problem again by using gausselim and backsub command.  Look at the Maple manual of your text if you have any question about how to do the last two problems.  I will be in the lab if you need any help with this assignment as with any other assignment.