




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





The version of gausselim.m posted along with this lecture is updated slightly from Lecture #12. First off, the statement
if maxval > 0
has been replaced with
if maxval > 1e-
This fixes a problem I overlooked the first time through. Rounding errors will produce small numbers very close zero instead of exact zeros. This statement says that, for all of our concerns, anything with magnitude < 10 −^10 is zero. (You could probably get away with a smaller tolerance than this, as rounding errors are generally on the order of 10−^16. This is just be being really, excessively safe.) The other change is a number of statement that make the program pause after each step of Gaussian elimination and say what it just did. This is just so you can follow the process step-by-step if you want to.
The other two scripts for today are random unsolvable.m and random solvable.m. These produce A and b so I can use the system Ax = b to illustrate certain things.
Last time we figured out how to program Gaussian elimination, but we didn’t look too hard at its output. Let’s fix that little problem now. Set up a system with the following commands. Use the first statement to get the exact same numbers I’m using here. Or leave it out (or change the 1000 to a different number) to try out some different numbers.
rand(’twister’, 1000) A = rand(4,4); b = rand(4,1); aug = [A b] aug = 0.6536 0.8725 0.2331 0.3922 0. 0.1150 0.2123 0.8417 0.1823 0. 0.9503 0.0407 0.2071 0.7435 0. 0.4822 0.3972 0.7425 0.0696 0.
The array aug stores the augmented matrix for this system of equations:
Now go back to the command line, and enter
aug2 = gausselim(aug)
After a detailed run-through of the operations, you’ll end up with
aug2 = 1.0000 0.0428 0.2179 0.7824 0. 0 1.0000 0.1074 -0.1412 0. 0 0.0000 1.0000 0.1530 0. 0 -0.0000 0 1.0000 2.
Just like aug, this new augmented matrix is shorthand for a linear system of equa- tions: x 1 + 0. 0428 x 2 + 0. 2179 x 3 + 0. 7824 x 4 = 0. 9799 x 2 + 0. 1074 x 3 − 0. 1412 x 4 = 0. 2900 x 3 + 0. 1530 x 4 = 0. 9816 x 4 = 2. 1748
And, since only Gaussian operations were used in getting from sytem (1) to system (2), the two are completely equivalent. That is, any solution to system (1) is a solution to system (2), and vice versa. The point of this, of course, is that system (2) is a lot easier to solve. The last equation gives me a value for x 4. I can take this value and plug it into the third
aug2 = pivot(aug2, 3, -aug2(2,3), 2); aug2 = pivot(aug2, 3, -aug2(1,3), 1) aug2 = 1.0000 0.0428 0 0 -0. 0 1.0000 0 0 0. 0 0.0000 1.0000 0 0. 0 -0.0000 0 1.0000 2.
Finally, I’ll eliminate that one last element above row 2, column 2:
aug2 = pivot(aug2, 2, -aug2(1,2), 1)
aug2 = 1.0000 0.0000 0 0 -0. 0 1.0000 0 0 0. 0 0.0000 1.0000 0 0. 0 -0.0000 0 1.0000 2.
This final augmented matrix still represents a linear system of equations, only now it’s a system that just plain hands the answer to me:
x 1 = − 0. 8858 x 2 = 0. 5274 x 3 = 0. 6488 x 4 = 2. 1748
The special types of matrices that come out of Gaussian elimination and Gauss- Jordan elimination have their own names. While we’ve seen examples of these already, they’re a bit more interesting in the cases where there isn’t exactly one solution to the system. So it might be worth glancing back at these definitions after seeing the examples in the rest of this lecture.
Definition. A matrix is in echelon form if it has the following two properties:
Say that I apply Gaussian elimination to the augmented matrix [ A
∣ (^) b ], and I
obtain the reduced augmented matrix [ Ared
∣ (^) bred ]. Then Ared is in echelon form. A matrix in echelon form typically looks something like this, with • ’s representing nonzero elements, and empty space representing zeros:
1 • • • • • • • • 1 • • • • • • 1 • • • • • 1 • •
Definition. A matrix is in reduced echelon form if it is in echelon form, with one additional condition:
Say that I apply the Jordan step of Gauss-Jordan elimination to [ Ared
∣ (^) bred ],
and I get back [ Ared
∣ (^) bred2 ]. Then Ared2 is in reduced echelon form. If my ‘generic’ matrix in echelon from from above is converted to reduced echelon form, it looks like this:
1 • 0 0 • • 0 • • 1 0 • • 0 • • 1 • • 0 • • 1 • •
Gaussian elimination makes it really easy to spot an unsolvable system of equations, with no need for the Jordan step. Use these commands to get an example. Again, you can omit the first line to get different numbers.
rand(’twister’, 1000) [A,b] = random_unsolvable; aug = [A b]
Now let’s check out a system with infinitely many solutions. First set up the exam- ple.
rand(’twister’, 1003) [A,b] = random_solvable; aug = [A b] aug = 1 -25 9 6 -19 -2 - -15 -15 -5 -4 20 -1 81 12 63 -13 -29 28 -6 - 8 22 -2 6 -35 -5 - -10 7 -9 24 -53 -5 5
And then reduce the system:
aug2 = 1.0000 1.0000 0.3333 0.2667 -1.3333 0.0667 -5. 0 1.0000 -0.3333 -0.6314 0.8627 -0.1333 0. 0 0 -0.0000 1.0000 -2.1658 -0.0553 -1. 0 0 0.0000 0 1.0000 0.3333 4. 0 0 0.0000 0 0 0.0000 0
This augmented matrix corresponds to the system of equations
x 1 + 1. 0000 x 2 + 0. 3333 x 3 + 0. 2667 x 4 − 1. 3333 x 5 + 0. 0667 x 6 = − 5. 4000 x 2 − 0. 3333 x 3 − 0. 6314 x 4 + 0. 8627 x 5 − 0. 1333 x 6 = 0. 8980 x 4 − 2. 1658 x 5 − 0. 0553 x 6 = − 1. 7184 x 5 + 0. 3333 x 6 = 4. 3333 0 = 0
This time around, there are two different types of variables. First of all, there are the ones that have a ‘leading 1’ as a coefficient in one of the equations. These are the exact same variables that were used to pivot when Gaussian elimination was taking place. So these are called pivot variables. Second, there are... well... , all the other variables. These are called free vari- ables because their values are ‘free.’ I can pick any values I like for these, and I’ll still be able to find a solution. In this case, x 1 , x 2 , x 4 , and x 5 are the pivot variables. Meanwhile, x 3 and x 6 are the free variables.
If you were to make a solution to this system, you could start with the bottom equation and work your way to the top, following this sequence of events:
Free variables Pivot variables Pick a value for x 6 Solve for x 5 Solve for x 4 Pick a value for x 3 Solve for x 2 Solve for x 1
Pivot variables and free variables are closely tied with the range and null space of the original matrix A. We’ll look at that in the next lecture.