Online Lesson 3 -- section 8.3

> with(linalg);

[BlockDiagonal, GramSchmidt, JordanBlock, LUdecomp,...
[BlockDiagonal, GramSchmidt, JordanBlock, LUdecomp,...
[BlockDiagonal, GramSchmidt, JordanBlock, LUdecomp,...
[BlockDiagonal, GramSchmidt, JordanBlock, LUdecomp,...
[BlockDiagonal, GramSchmidt, JordanBlock, LUdecomp,...
[BlockDiagonal, GramSchmidt, JordanBlock, LUdecomp,...
[BlockDiagonal, GramSchmidt, JordanBlock, LUdecomp,...

The previous command loads Maple's "linear algebra" package, which enables us to use operations on matrices.

Maple can solve systems of linear equations on its own:

> solve({3*x+2*y-z=5,x+y+z=4,2*x-y-z=1},{x,y,z});

{x = 5/3, y = 7/9, z = 14/9}

But we have no idea how this was done! Here are the equations we just solved:

> 3*x+2*y-z=5,x+y+z=4,2*x-y-z=1;

3*x+2*y-z = 5, x+y+z = 4, 2*x-y-z = 1

We set up the "matrix" associated with these equations:

> M:=array(1..3,1..4,[[3,2,-1,5],[1,1,1,4],[2,-1,-1,1]]);

M := matrix([[3, 2, -1, 5], [1, 1, 1, 4], [2, -1, -...

Each row of the matrix consists of the coefficients on the left side of one of the equations, followed by the number on the right side of the equation.

We are allowed to carry out certain operations on the rows of this matrix, which correspond to operations we can carry out on the equations themselves

without changing their solution set.

1. We can interchange two rows. This corresponds to interchanging two equations, which certainly won't change the solutions of the system!

2. We can multiply a row by a nonzero constant. This corresponds to multiplying both sides of one of the equations by a nonzero constant, which

won;t change the solution set. Notice that multiplying both sides of an equation by zero is excluded: this does change the solutions (an equation

true of only some values of the variables becomes true of all values of the variables if both sides are multiplied by zero!)

3. We can add a nonzero multiple of one row to another row. This corresponds to "adding equations", and it does not change the solutions of the

system of equations. We can see this by first noticing that if the equations are true for given values of the variables, the modified equations where

a multiple of one equation is added to another will remain true (we don't _lose_ any solutions) and then observing that this operation is reversible:

if the modified equations were true, we could subtract a multiple of a row from a row to show that the original equations were true.

Maple functions:

addrow(A,m,n,r) means add r times row m to row n

mulrow(A,m,r) means multiply row m of A by r

swaprow(A,m,n) means swap rows m and n of A.

Now we will solve the equation. Our strategy is to convert the matrix to a form with zeroes everywhere below the diagonal: this will have the effect

of allowing us to solve the equation by "back-substitution" at the end of the process.

As you read the lesson, it is probably a good idea to do hand calculations of your own for some or all of the elementary row operations that

I have Maple do for me: this will help you to make certain that you understand what is going on.

> matrix(M);

matrix([[3, 2, -1, 5], [1, 1, 1, 4], [2, -1, -1, 1]...

We prefer to have a 1 in the top left corner, so we interchange rows 1 and 2. If there were a 0 in the top left corner, it would be mandatory to exchange

a nonzero number into this position.

> M2:=swaprow(M,1,2);

M2 := matrix([[1, 1, 1, 4], [3, 2, -1, 5], [2, -1, ...

Our next goal is to eliminate the 3 and the 2 in the first column. We do this by subtracting 3 times the first row from the second row, then

subtracting two times the first row from the third row.

> M3:=addrow(M2,1,2,-3);

M3 := matrix([[1, 1, 1, 4], [0, -1, -4, -7], [2, -1...

> M4:=addrow(M3,1,3,-2);

M4 := matrix([[1, 1, 1, 4], [0, -1, -4, -7], [0, -3...

We want 1's on the diagonal (usually), so we multiply the second row by -1.

> M5:=mulrow(M4,2,-1);

M5 := matrix([[1, 1, 1, 4], [0, 1, 4, 7], [0, -3, -...

Now we want to eliminate the -3 at the bottom of the second column (which is the last nonzero element remaining below the diagonal); we do this

by adding 3 times the second row to the third row.

> M6:=addrow(M5,2,3,3);

M6 := matrix([[1, 1, 1, 4], [0, 1, 4, 7], [0, 0, 9,...

Now divide the third row by 9...

> M7:=mulrow(M6,3,1/9);

M7 := matrix([[1, 1, 1, 4], [0, 1, 4, 7], [0, 0, 1,...

...and we can read off z = 14/9.

There are two ways to proceed at this point. One is to do back substitution, and the other is to continue with row operations. I will

demonstrate both.

First we do back substitution. The second row represents the equation

> equation1:=y+4*z = 7: equation1;

y+4*z = 7

Substitute in z = 14/9:

> z:=14/9:equation1;

y+56/9 = 7

> y := 7-56/9;

y := 7/9

The first row represents the equation x + y + z = 4:

> equation2:=x+y+z=4:equation2; #Maple knows what y and z are at this point, so it evaluates y+z.

x+7/3 = 4

> x:=4-7/3;

x := 5/3

> x:=evaln(x); y:=evaln(y); z:=evaln(z); #free up these variables for future work.

x := 'x'

y := 'y'

z := 'z'

If we think in terms of back substitution, it is easy to justify our strategy: it should be clear that if we have zeroes everywhere below the diagonal,

it will be possible to solve by back substitution, because the last equation will involve only the last variable, the second to last equation will involve

only the last two variables (and so can be solved using the last equation) and so forth.

Now we show how to solve this equation by continuing with row operations. The idea is to eliminate zeroes above the diagonal as well as below

the diagonal, using the lower equations first:

> matrix(M7);

matrix([[1, 1, 1, 4], [0, 1, 4, 7], [0, 0, 1, 14/9]...

We want to eliminate the 1and the 4 in the third column.

> M8:=addrow(M7,3,2,-4);

M8 := matrix([[1, 1, 1, 4], [0, 1, 0, 7/9], [0, 0, ...

> M9:=addrow(M8,3,1,-1);

M9 := matrix([[1, 1, 0, 22/9], [0, 1, 0, 7/9], [0, ...

The only nonzero entry above the diagonal that remains is the 1 in the first row, second column. Eliminate it with the help of the

second equation.

> M10:=addrow(M9,2,1,-1);

M10 := matrix([[1, 0, 0, 5/3], [0, 1, 0, 7/9], [0, ...

The system of equations corresponding to this matrix is x = 5/3, y = 7/9, z = 14/9: the solution!

This technique can be used to solve n equations in n unknowns for any n. We present a worked out system of 4 equations in 4 unknowns.

Solve:

x + 2y - 3z +4w = 11

5x +2y -z -2w = 3

x + y - z - w = -4

3x -2y +4z +4w = 39

> M0:=array(1..4,1..5,[[1,2,-3,4,11],[5,2,-1,-2,3],[1,1,-1,-1,-4],[3,-2,4,5,39]]);

M0 := matrix([[1, 2, -3, 4, 11], [5, 2, -1, -2, 3],...

First we subtract multiples of the first row from the other rows so that we have zeroes below the diagonal in the first column. You might want

to do these calculations by hand to check that you understand what Maple is doing.

Subtract 5 times row 1 from row 2.

> M1:=addrow(M0,1,2,-5);

M1 := matrix([[1, 2, -3, 4, 11], [0, -8, 14, -22, -...

Subtract row 1 from row 2.

> M2:=addrow(M1,1,3,-1);

M2 := matrix([[1, 2, -3, 4, 11], [0, -8, 14, -22, -...

Subtract three times row 1 from row 3 and we are done with the first column.

> M3:=addrow(M2,1,4,-3);

M3 := matrix([[1, 2, -3, 4, 11], [0, -8, 14, -22, -...

On Maple it doesn't make much difference, but working on paper it would be appealing to swap row 2 and row 3 here to get a 1 to work with.

We will take this approach.

> M4:=swaprow(M3,2,3);

M4 := matrix([[1, 2, -3, 4, 11], [0, -1, 2, -5, -15...

> M5:=mulrow(M4,2,-1);

M5 := matrix([[1, 2, -3, 4, 11], [0, 1, -2, 5, 15],...

Now we need to eliminate the two -8's below the diagonal in the second column.

> M6:=addrow(M5,2,3,8);

M6 := matrix([[1, 2, -3, 4, 11], [0, 1, -2, 5, 15],...

> M7:=addrow(M6,2,4,8);

M7 := matrix([[1, 2, -3, 4, 11], [0, 1, -2, 5, 15],...

At this point we would like to have a 1 in the third row, third column, and fortunately dividing by -2 does not introduce any fractions!

> M8:=mulrow(M7,3,-1/2);

M8 := matrix([[1, 2, -3, 4, 11], [0, 1, -2, 5, 15],...

Now we eliminate the last nonzero entry below the diagonal, by adding three times row 3 to row 4.

> M9:=addrow(M8,3,4,3);

M9 := matrix([[1, 2, -3, 4, 11], [0, 1, -2, 5, 15],...

Now we ready ourselves for back-substitution by dividing row 4 by 6:

> M10:=mulrow(M9,4,1/6);

M10 := matrix([[1, 2, -3, 4, 11], [0, 1, -2, 5, 15]...

The last equation reads w = 4.

> w:=4;

>

w := 4

The second equation from the bottom reads z-9w = -34. Maple knows what w is and carries out the substitution.

> equation1:=z-9*w=-34:equation1;

z-36 = -34

> z:=-34+36;

z := 2

The third equation from the bottom reads y-2z+5w = 15. Maple knows what z and w are and carries out the substitutions.

> equation2:=y-2*z+5*w=15;

equation2 := y+16 = 15

> y:=15-16;

y := -1

The fourth equation from the bottom reads x+2y-3z+4w = 11. Maple knows the values of y,z,w and substitutes.

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

equation3 := x+8 = 11

> x:=11-8;

x := 3

We have solved the equation: x = 3, y = -1, z = 2, w = 4.

I will not ask you to do complete 4x4 systems of equations on an exam (at least not by hand) because they are too time consuming.

But you should know how to do them!

This system could also be solved by reducing the matrix to one with zeroes eliminated above the diagonal (as we did last time), but

I won't work this out here.

> x:=evaln(x); y:=evaln(y); z:=evaln(z); w:=evaln(w); #free up variables

x := 'x'

y := 'y'

z := 'z'

w := 'w'

We still need to look at systems with infinitely many solutions, or with no solutions at all.

The signal of a system with no solutions or with infinitely many solutions is the presence of a row of zeroes (except possibly for the

far right entry) in the reduced matrix. This corresponds to an equation 0x + 0y + 0z ... = c, which will be true for _all_ x,y,z... if c = 0

or for none if c =/= 0.

Solve

x + y - 2z = 4

2x +y-z = -2

5x +3y-4z = 3

Write out for yourself what the row operations are at each stage.

> M0:=array(1..3,1..4,[[1,1,-2,4],[2,1,-1,-2],[5,3,-4,3]]);

M0 := matrix([[1, 1, -2, 4], [2, 1, -1, -2], [5, 3,...

> M1:=addrow(M0,1,2,-2);

M1 := matrix([[1, 1, -2, 4], [0, -1, 3, -10], [5, 3...

> M2:=addrow(M1,1,3,-5);

M2 := matrix([[1, 1, -2, 4], [0, -1, 3, -10], [0, -...

> M3:=mulrow(M2,2,-1);

M3 := matrix([[1, 1, -2, 4], [0, 1, -3, 10], [0, -2...

> M4:=addrow(M3,2,3,2);

M4 := matrix([[1, 1, -2, 4], [0, 1, -3, 10], [0, 0,...

Here the final equation is 0x+0y+0z=3, which cannot be true for any values of x,y,z, so there are no solutions.

Solve

2x-y-z = 3

4x+2y-4z = -2

2x+7y-5z = -13

Make sure you understand what row operations I do at each stage.

> M0:=array(1..3,1..4,[[2,-1,-1,3],[4,2,-4,-2],[2,7,-5,-13]]);

M0 := matrix([[2, -1, -1, 3], [4, 2, -4, -2], [2, 7...

> M1:=mulrow(M0,1,1/2); #this is Maple -- we are not scared of fractions :-)

M1 := matrix([[1, -1/2, -1/2, 3/2], [4, 2, -4, -2],...

> M2:=addrow(M1,1,2,-4);

M2 := matrix([[1, -1/2, -1/2, 3/2], [0, 4, -2, -8],...

> M3:=addrow(M2,1,3,-2);

M3 := matrix([[1, -1/2, -1/2, 3/2], [0, 4, -2, -8],...

> M4:=mulrow(M3,2,1/4);

M4 := matrix([[1, -1/2, -1/2, 3/2], [0, 1, -1/2, -2...

> M5:=addrow(M4,2,3,-8);

M5 := matrix([[1, -1/2, -1/2, 3/2], [0, 1, -1/2, -2...

The final equation is 0x+0y+0z, which does not allow us to solve for a specific z but certainly does have solutions!

But this does not mean that all x,y,z are solutions of the original system: we find the solutions by back substitution, as before.

We let z take on any value. The preceding equation is y-(1/2)z = -2.

> equation1:=y-(1/2)*z = -2;

equation1 := y-1/2*z = -2

> y:=-2+(1/2)*z; #we know how to solve for y.

y := -2+1/2*z

The first equation is x -(1/2)y-(1/2)z = 3/2. Maple will simplify this using the expression for y we have already derived --

it would be a good idea for you to verify Maple's simplification by hand.

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

x+1-3/4*z = 3/2

> x:=3/2-1+(3/4)*z; #apply familiar algebra to the previous equation

x := 1/2+3/4*z

I verify that the original equations hold for our solution x=(1/2)+(3/4)y, y = -2+(1/2)z, z=z. You might want to check this by

hand as an algebra exercise: you can see that Maple knows that the solution works, but you can't see how Maple verifies it.

> 2*x-y-z;

3

> 4*x+2*y-4*z;

-2

> 2*x+7*y-5*z;

-13

> x:=evaln(x); y:=evaln(y); z:=evaln(z);

x := 'x'

y := 'y'

z := 'z'

A word problem:

A man walks at 3 miles per hour, runs at 4 miles per hour, and cycles at 10 miles per hour. He participates in an event in which running, walking, and cycling

are all components. You know that he completes the course of 7 miles in 1 hour, and you know that the walking part of the course is twice as long (in distance) as

the running part of the course. Determine how far he ran, how far he walked, and how far he cycled.

Solution: There are three unknowns:

x = distance he walked (in miles)

y = distance he ran (in miles)

z = distance he cycled (in miles)

The _time_ he walked is x/3 hours, the _time_ he ran is y/4 hours, the _time_ he cycled in z/10 hours.

We remind ourselves of this using distance = rate times time. For example

distance walked (x) = rate of walking (3) * time walked

so x/3 = time walked

Now we can set up three equations:

x+y+z = 7 (the total length of the course is 7 miles)

x/3+y/4+z/10=1 (the total time is 1 hour)

x - 2y = 0 (the walking course is twice as long as the running course, so x = 2y, from which x-2y = 0)

Now we solve it.

> M0:=array(1..3,1..4,[[1,1,1,7],[1/3,1/4,1/10,1],[1,-2,0,0]]);

M0 := matrix([[1, 1, 1, 7], [1/3, 1/4, 1/10, 1], [1...

> M1:=addrow(M0,1,2,-1/3);

M1 := matrix([[1, 1, 1, 7], [0, -1/12, -7/30, -4/3]...

> M2:=addrow(M1,1,3,-1);

>

M2 := matrix([[1, 1, 1, 7], [0, -1/12, -7/30, -4/3]...

> M3:=mulrow(M2,2,-12);

M3 := matrix([[1, 1, 1, 7], [0, 1, 14/5, 16], [0, -...

> M4:=addrow(M3,2,3,3);

M4 := matrix([[1, 1, 1, 7], [0, 1, 14/5, 16], [0, 0...

> M5:=mulrow(M4,3,5/37);

M5 := matrix([[1, 1, 1, 7], [0, 1, 14/5, 16], [0, 0...

> z:=205/37;

z := 205/37

> equation1:=y+(14/5)*z = 16;

equation1 := y+574/37 = 16

> y:=16-574/37;

y := 18/37

> equation2:=x+y+z=7;

equation2 := x+223/37 = 7

> x:=7-223/37;

x := 36/37

> evalf(x); evalf(y); evalf(z);

.9729729730

.4864864865

5.540540541

>

The last line gives "calculator approximations". The man walked about .97 miles, ran about .49 miles and covered the remaining 5.54 miles on the bicycle.

> x:=evaln(x); y:=evaln(y); z:=evaln(z);

x := 'x'

y := 'y'

z := 'z'

>

>