Lecture # 5 Math 221 

Gauss-Elimination and Gauss-Jordan for Equation with non Unique Solutions or No Solution 

We will apply Gauss elimination with back to determine if a system of equations has a solution.  If it has a solution but it not unique that we will use back substitution to find the general solution and also Gauss Jordan to obtain the non-unique solution.   Again, we must look at the element in the first row and first column to see if it is zero.  If it is not zero then the entries in the remainder of the first column are made zero.  Next go to the second row and move over to the second column if all the entries below  the entry in the second row and second column is not zero then you zero out the entries under the 2,2 position.  If all the entries in the second column below the first row are all zero after zeroing out the entry under the first row and first column  then you must move to the left to continue the elimination process.  See Example 2 to observe how this works.  Again, you need to work from top to bottom  and left to right.  Do not jump around to try to make the work easier in your eyes.  Gauss and Gauss-Jordan is an algorithm.  Algorithm must have a definite pattern.   

 

Example 1  No solution.   

Consider the following set of equations. 

                3x + 7y -3z =2 

                2x + 5y + z = -4 

                2x + 6y +10z = 3 

 

> with(linalg):
 

> with(LinearAlgebra):
 

> A:=<<3|7|-3>,<2|5|1>,<2|6|10>>;
 

Matrix(%id = 2407756)
 

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

Matrix(%id = 2424664)
 

> Ab:=<A|b>;
 

Matrix(%id = 2427696)
 

We are now ready to apply the row operations to find if the equation has a solution.  If it has a solution then we will find the solution. 

 

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

array( 1 .. 3, 1 .. 4, [( 1, 1 ) = 3, ( 2, 3 ) = 3, ( 3, 3 ) = 12, ( 2, 2 ) = `/`(1, 3), ( 1, 2 ) = 7, ( 3, 1 ) = 0, ( 2, 1 ) = 0, ( 1, 4 ) = 2, ( 3, 4 ) = `/`(5, 3), ( 3, 2 ) = `/`(4, 3), ( 2, 4 ) = ...
 

> Ab2:=addrow(Ab1,2,3,-4);
 

array( 1 .. 3, 1 .. 4, [( 1, 1 ) = 3, ( 2, 3 ) = 3, ( 3, 3 ) = 0, ( 2, 2 ) = `/`(1, 3), ( 1, 2 ) = 7, ( 3, 1 ) = 0, ( 2, 1 ) = 0, ( 1, 4 ) = 2, ( 3, 4 ) = 23, ( 3, 2 ) = 0, ( 2, 4 ) = -`/`(16, 3), ( 1...
 

Since the last row has all zeros except the final column then there is no way that 0*z=23 

hence there is no solution. 

 

Example 2 

We now consider another system.  This system is exactly the same as above but the right hand side is changed. 

 

                 3x + 7y -3z = 2 

                 2x + 5y + z = -4 

                 2x + 6y + 10z = -20 

 

The coefficient matrix A remains the same but the b matrix changes.  This can be done as follows 

> b[3,1]:=-20;
 

-20
 

> b;
 

Matrix(%id = 2424664)
 

> Aba:=<A|b>;
 

Matrix(%id = 2530584)
 

> Aba1:=addrow(addrow(Aba,1,2,-2/3),1,3,-2/3);
 

array( 1 .. 3, 1 .. 4, [( 1, 1 ) = 3, ( 2, 3 ) = 3, ( 3, 3 ) = 12, ( 2, 2 ) = `/`(1, 3), ( 1, 2 ) = 7, ( 3, 1 ) = 0, ( 2, 1 ) = 0, ( 1, 4 ) = 2, ( 3, 4 ) = -`/`(64, 3), ( 3, 2 ) = `/`(4, 3), ( 2, 4 ) ...
 

> Aba2:=addrow(Aba1,2,3,-4);
 

array( 1 .. 3, 1 .. 4, [( 1, 1 ) = 3, ( 2, 3 ) = 3, ( 3, 3 ) = 0, ( 2, 2 ) = `/`(1, 3), ( 1, 2 ) = 7, ( 3, 1 ) = 0, ( 2, 1 ) = 0, ( 1, 4 ) = 2, ( 3, 4 ) = 0, ( 3, 2 ) = 0, ( 2, 4 ) = -`/`(16, 3), ( 1,...
 

We need to look at what we have now.   To make things look better we will multiply the last row by 3 which will make the coefficient of the second variable y be one.  This was not necessary but it makes solving for y easier.   

 

> Aba3:=mulrow(Aba2,2,3);
 

array( 1 .. 3, 1 .. 4, [( 1, 1 ) = 3, ( 2, 3 ) = 9, ( 3, 3 ) = 0, ( 2, 2 ) = 1, ( 1, 2 ) = 7, ( 3, 1 ) = 0, ( 2, 1 ) = 0, ( 1, 4 ) = 2, ( 3, 4 ) = 0, ( 3, 2 ) = 0, ( 2, 4 ) = -16, ( 1, 3 ) = -3 ] )
 

We can solve for x and y in terms of z in the following way. 

From the second equation we have  y+9z = -16 or y= -16 -9z.  Now put this into the first equation of y and solve for x.     3x +7(-16 -9z) -3z = 2 or x = 38 + 33z .  Maple will substitute the variable  

Typesetting:-mrow(Typesetting:-msub(Typesetting:-mi( for the variable z  lets look at the maple commands 

 

The following are the maple commands to find x and y.  By using the addrow and mulrow commands from the with(linalg) package you are forced to use the convert command.   The last command will combine the backsub and the convert command.  This is the one I would use. 

> y:=-16-9*z;
 

`+`(`-`(16), `-`(`*`(9, `*`(z)))) (3.1)
 

> x:=(1/3)*(2+3*z-7*y);
 

`+`(38, `*`(22, `*`(z))) (3.2)
 

> sol:=backsub(Aba3);
 

array( 1 .. 3, [( 1 ) = `+`(38, `*`(22, `*`(_t[1]))), ( 2 ) = `+`(`-`(16), `-`(`*`(9, `*`(_t[1])))), ( 3 ) = _t[1] ] )
 

> colsol:=convert(%,matrix);
 

array( 1 .. 3, 1 .. 1, [( 1, 1 ) = `+`(38, `*`(22, `*`(_t[1]))), ( 3, 1 ) = _t[1], ( 2, 1 ) = `+`(`-`(16), `-`(`*`(9, `*`(_t[1])))) ] )
 

> colsol:=convert(backsub(Aba3),matrix);
 

array( 1 .. 3, 1 .. 1, [( 1, 1 ) = `+`(38, `*`(22, `*`(_t[1]))), ( 3, 1 ) = _t[1], ( 2, 1 ) = `+`(`-`(16), `-`(`*`(9, `*`(_t[1])))) ] ) (3.3)
 

We will now a closer look at the different components of this general solution.  If we set arbitrary constant equal to zero we will obtain what is call  a particular solution Typesetting:-mrow(Typesetting:-msub(Typesetting:-mi(If we subtract the particular solution from the general solution we will obtain the general solution to the homogeneous equation.  i.e. the solution where the right hand side is equal to the zero vector.  The next few commands in Maple will illustrate what we are talking about.  The convert command appears to be the way to get the with(LinearAlgebra) package to work with the xp column matrix.   

> xp:=convert(subs(_t[1]=0,evalm(colsol)),matrix);
 

array( 1 .. 3, 1 .. 1, [( 1, 1 ) = 38, ( 3, 1 ) = 0, ( 2, 1 ) = -16 ] ) (3.4)
 

> A.xp;
 

Matrix(%id = 2797784) (3.5)
 

As you can see this is the b vector or the right hand side. 

> xh:=convert(evalm(colsol-xp),matrix);
 

array( 1 .. 3, 1 .. 1, [( 1, 1 ) = `+`(`*`(22, `*`(_t[1]))), ( 3, 1 ) = _t[1], ( 2, 1 ) = `+`(`-`(`*`(9, `*`(_t[1])))) ] ) (3.6)
 

> A.xh;
 

Matrix(%id = 2916960) (3.7)
 

The solution can then be written as x = xp +xh.  Again I have found no way around the evalm command that followis.   

 

> x:=evalm(xh+xp);
 

array( 1 .. 3, 1 .. 1, [( 1, 1 ) = `+`(38, `*`(22, `*`(_t[1]))), ( 3, 1 ) = _t[1], ( 2, 1 ) = `+`(`-`(16), `-`(`*`(9, `*`(_t[1])))) ] ) (3.8)
 

We will now look at continuing with Aba3 to obtain a Gauss-Jordan form for a non-unique solutns 

> Aba4:=addrow(Aba3,2,1,-7);
 

array( 1 .. 3, 1 .. 4, [( 1, 1 ) = 3, ( 2, 3 ) = 9, ( 3, 3 ) = 0, ( 2, 2 ) = 1, ( 1, 2 ) = 0, ( 3, 1 ) = 0, ( 2, 1 ) = 0, ( 1, 4 ) = 114, ( 3, 4 ) = 0, ( 3, 2 ) = 0, ( 2, 4 ) = -16, ( 1, 3 ) = -66 ] )
 

> Aba5:=mulrow(Aba4,1,1/3);
 

array( 1 .. 3, 1 .. 4, [( 1, 1 ) = 1, ( 2, 3 ) = 9, ( 3, 3 ) = 0, ( 2, 2 ) = 1, ( 1, 2 ) = 0, ( 3, 1 ) = 0, ( 2, 1 ) = 0, ( 1, 4 ) = 38, ( 3, 4 ) = 0, ( 3, 2 ) = 0, ( 2, 4 ) = -16, ( 1, 3 ) = -22 ] )
 

Maple uses Typesetting:-mrow(Typesetting:-msub(Typesetting:-mi( for the arbitrary constant i.e. Typesetting:-mrow(Typesetting:-msub(Typesetting:-mi( = z.   As you can see the solution for x in terms of z and y in terms of z.  Gauss-Jordan makes it easier for see the solution but you have to work more to find the answer.   

Example 3  Three equation and Five Unknowns 

 

Consider the following system 

 

x + 2 y + 2 v -w = 4 

2x +4y + 2z + 4 v -6w = 6 

-x -2y + 3 z -2v + 6 w = 4 

We will write this as an augmented matrix and solve  by gauss elimination. 

 

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

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

 

Matrix(%id = 2999480)
Matrix(%id = 3003308)
 

> B:=<C|b>;
 

Matrix(%id = 3006664) (4.1)
 

> B1:=addrow(addrow(B,1,2,-2),1,3,1);
 

array( 1 .. 3, 1 .. 6, [( 1, 1 ) = 1, ( 2, 3 ) = 2, ( 3, 3 ) = 3, ( 1, 6 ) = 4, ( 2, 5 ) = -4, ( 2, 2 ) = 0, ( 1, 2 ) = 2, ( 3, 1 ) = 0, ( 2, 1 ) = 0, ( 1, 4 ) = 2, ( 1, 5 ) = -1, ( 3, 6 ) = 8, ( 3, 4...
 

> B2:=mulrow(B1,2,1/2);
 

array( 1 .. 3, 1 .. 6, [( 1, 1 ) = 1, ( 2, 3 ) = 1, ( 3, 3 ) = 3, ( 1, 6 ) = 4, ( 2, 5 ) = -2, ( 2, 2 ) = 0, ( 1, 2 ) = 2, ( 3, 1 ) = 0, ( 2, 1 ) = 0, ( 1, 4 ) = 2, ( 1, 5 ) = -1, ( 3, 6 ) = 8, ( 3, 4...
 

> B3:=addrow(B2,2,3,-3);
 

array( 1 .. 3, 1 .. 6, [( 1, 1 ) = 1, ( 2, 3 ) = 1, ( 3, 3 ) = 0, ( 1, 6 ) = 4, ( 2, 5 ) = -2, ( 2, 2 ) = 0, ( 1, 2 ) = 2, ( 3, 1 ) = 0, ( 2, 1 ) = 0, ( 1, 4 ) = 2, ( 1, 5 ) = -1, ( 3, 6 ) = 11, ( 3, ...
 

> B4:=mulrow(B3,3,1/11);
 

array( 1 .. 3, 1 .. 6, [( 1, 1 ) = 1, ( 2, 3 ) = 1, ( 3, 3 ) = 0, ( 1, 6 ) = 4, ( 2, 5 ) = -2, ( 2, 2 ) = 0, ( 1, 2 ) = 2, ( 3, 1 ) = 0, ( 2, 1 ) = 0, ( 1, 4 ) = 2, ( 1, 5 ) = -1, ( 3, 6 ) = 1, ( 3, 4...
 

> convert(backsub(B4),matrix);
 

array( 1 .. 5, 1 .. 1, [( 1, 1 ) = `+`(5, `-`(`*`(2, `*`(_t[2]))), `-`(`*`(2, `*`(_t[1])))), ( 4, 1 ) = _t[1], ( 3, 1 ) = 1, ( 2, 1 ) = _t[2], ( 5, 1 ) = 1 ] )
 

The above solution tells us that w=1, z =1, v and y are arbitrary and then x will be in terms of the two arbitrary constants. 

 

We could have carried out a form of Gauss-Jordan on each of the examples. 

Let us start with example 2   

 

> Aba4:=addrow(Aba3,2,1,-7);
 

array( 1 .. 3, 1 .. 4, [( 1, 1 ) = 3, ( 2, 3 ) = 9, ( 3, 3 ) = 0, ( 2, 2 ) = 1, ( 1, 2 ) = 0, ( 3, 1 ) = 0, ( 2, 1 ) = 0, ( 1, 4 ) = 114, ( 3, 4 ) = 0, ( 3, 2 ) = 0, ( 2, 4 ) = -16, ( 1, 3 ) = -66 ] )
 

> Aba5:=mulrow(Aba4,1,1/3);
 

array( 1 .. 3, 1 .. 4, [( 1, 1 ) = 1, ( 2, 3 ) = 9, ( 3, 3 ) = 0, ( 2, 2 ) = 1, ( 1, 2 ) = 0, ( 3, 1 ) = 0, ( 2, 1 ) = 0, ( 1, 4 ) = 38, ( 3, 4 ) = 0, ( 3, 2 ) = 0, ( 2, 4 ) = -16, ( 1, 3 ) = -22 ] )
 

The answer is easier to see.  

 

 

  Let us look at the matrix B4  and try to apply Gauss-Jordan.   The pivots are in the 3,5 position, the 2,3 position and the 1,1 position. 

 

> B5:= addrow(addrow(B4,3,2,2),3,1,1);
 

array( 1 .. 3, 1 .. 6, [( 1, 1 ) = 1, ( 2, 3 ) = 1, ( 3, 3 ) = 0, ( 1, 6 ) = 5, ( 2, 5 ) = 0, ( 2, 2 ) = 0, ( 1, 2 ) = 2, ( 3, 1 ) = 0, ( 2, 1 ) = 0, ( 1, 4 ) = 2, ( 1, 5 ) = 0, ( 3, 6 ) = 1, ( 3, 4 )...
 

Again, the answer is much clearer than it was before the last series of steps.   

 

> rxs:=convert(backsub(B5),matrix);
 

array( 1 .. 5, 1 .. 1, [( 1, 1 ) = `+`(5, `-`(`*`(2, `*`(_t[2]))), `-`(`*`(2, `*`(_t[1])))), ( 4, 1 ) = _t[1], ( 3, 1 ) = 1, ( 2, 1 ) = _t[2], ( 5, 1 ) = 1 ] )
 

The current problem has two unknowns so to find the particular solution we will nee to set both unknowns equal to zero.  The general homogenous solution will then contain two unknowns.  We will continue with the Maple commands necessary to illustrate this fact. 

 

>
 

> xp:=subs(_t[1]=0,_t[2]=0,evalm(rxs));
 

array( 1 .. 5, 1 .. 1, [( 1, 1 ) = 5, ( 4, 1 ) = 0, ( 3, 1 ) = 1, ( 2, 1 ) = 0, ( 5, 1 ) = 1 ] ) (4.2)
 

> xh:=evalm(rxs-xp);
 

array( 1 .. 5, 1 .. 1, [( 1, 1 ) = `+`(`-`(`*`(2, `*`(_t[2]))), `-`(`*`(2, `*`(_t[1])))), ( 4, 1 ) = _t[1], ( 3, 1 ) = 0, ( 2, 1 ) = _t[2], ( 5, 1 ) = 0 ] ) (4.3)
 

> C.xp;
 

Matrix(%id = 3368556) (4.4)
 

> C.xh;
 

Matrix(%id = 3393884) (4.5)
 

We have again illustrate that the solution xs can be written as xs = xp +xh.   

>
 

>
 

Example 4  Solve The First Problem on Last Exercise Assignment 

 

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

Matrix(%id = 3398600)
 

> b:=<<5,4,-15,10>>;
 

Matrix(%id = 3403204)
 

> Ab:=<A|b>;
 

Matrix(%id = 3409984)
 

When you do not use row operations you can use the Gauss elimination command in with(LinearAlgebra).  It is as follows 

> Ab1:=GaussianElimination(Ab);
 

Matrix(%id = 3455532)
 

The command for the Gauss Jordan command is not so straight forward.  It goes back to an equivalent name with is ReducedRowEchelon form 

> Ab1a:=ReducedRowEchelonForm(Ab);
 

Matrix(%id = 3518996)
 

The advantage of this command is that you do not have do to a convert command as follows 

> solAb1:=BackwardSubstitute(Ab1a);
 

Vector[column](%id = 3596640)
 

> solAb2:=BackwardSubstitute(Ab1);
 

Vector[column](%id = 819652)
 

The Gauss-Jordan form has four diagonal elements and an extra column before the constants we see that first four variables in terms of the fifth variables.   

 

Example 5.  Street Problem from Lecture 2 

 

We will look at the street problem of lecture 2.  Recall that the traffic on Elm street was given by the variable x1.  The traffic on 1st Street by x2 while the traffic on 2nd Street was given by x3.  Finally, the traffic on Oak Street was given by x4.   The system of equation for the traffic flow is the following 

x1+x2=80 

x1+x3 = 65 

x2 + x4 = 75 

x3 + x4 = 60 

The coefficient matrix is then  

 

> T:= <<1|1|0|0>,<1|0|1|0>,<0|1|0|1>,<0|0|1|1>>;
 

Matrix(%id = 1053068) (6.1)
 

The right hand side is given by  

 

> b:=<<80,65,75,60>>;
 

Matrix(%id = 3593256) (6.2)
 

We will now solve the system using the shorthand notation of gausselim 

> Tb:=GaussianElimination(<T|b>);
 

Matrix(%id = 2224016) (6.3)
 

As you know by know with the row of zeros at the end we have an infinite number of solution with an unknown parameter. 

> x:=BackwardSubstitute(Tb);
 

Vector[column](%id = 1614552) (6.4)
 

Since this is a real world problem and the flows on each street must be non-negative then we need to take a closer look at each component.  First notice that the first and last component will be non-negative it the unknown is non-negative.  while the second component tell us that the unknown must be less than of equal to 75 while the third component tell us that the unknown must be less or equal to 60.  This tell us that the real world solution means that the flow on Oak Street must be greater than or equal to 0 and less than or equal to 60.   

 

>
 

Exercises:   

Section 1.5 

 

The Problems below are to be worked as Maple 11 worksheets and printed out or e-mailed to me by the end of class on September 17 , 2008 

Problems 1.5.17, 1.5.23, 1.5.27, 1.5.45 

>