Online Lesson 3 -- section 8.3
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:
But we have no idea how this was done! Here are the equations we just solved:
We set up the "matrix" associated with these equations:
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.
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.
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.
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.
We want 1's on the diagonal (usually), so we multiply the second row by -1.
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.
Now divide the third row by 9...
...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
First we do back substitution. The second row represents the equation
> equation1:=y+4*z = 7: equation1;
Substitute in z = 14/9:
> y := 7-56/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:=evaln(x); y:=evaln(y); z:=evaln(z); #free up these variables for future work.
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:
We want to eliminate the 1and the 4 in the third column.
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
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.
x + 2y - 3z +4w = 11
5x +2y -z -2w = 3
x + y - z - w = -4
3x -2y +4z +4w = 39
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.
Subtract row 1 from row 2.
Subtract three times row 1 from row 3 and we are done with the first column.
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.
Now we need to eliminate the two -8's below the diagonal in the second column.
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!
Now we eliminate the last nonzero entry below the diagonal, by adding three times row 3 to row 4.
Now we ready ourselves for back-substitution by dividing row 4 by 6:
The last equation reads w = 4.
The second equation from the bottom reads z-9w = -34. Maple knows what w is and carries out the substitution.
The third equation from the bottom reads y-2z+5w = 15. Maple knows what z and w are and carries out the substitutions.
The fourth equation from the bottom reads x+2y-3z+4w = 11. Maple knows the values of y,z,w and substitutes.
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
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.
x + y - 2z = 4
2x +y-z = -2
5x +3y-4z = 3
Write out for yourself what the row operations are at each stage.
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.
2x-y-z = 3
4x+2y-4z = -2
2x+7y-5z = -13
Make sure you understand what row operations I do at each stage.
> M1:=mulrow(M0,1,1/2); #this is Maple -- we are not scared of fractions :-)
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;
> y:=-2+(1/2)*z; #we know how to solve for y.
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.
> x:=3/2-1+(3/4)*z; #apply familiar algebra to the previous equation
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.
> x:=evaln(x); y:=evaln(y); z:=evaln(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.
> equation1:=y+(14/5)*z = 16;
> evalf(x); evalf(y); evalf(z);
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);