MATH/APPM 4650
Class notes, April 13
Section 6.1: Linear equations


Recall from linear algebra that any system of linear equations
a11 x1 + a12 x2 + a13 x3 = b1
a21 x1 + a22 x2 + a23 x3 = b2
can be written as a matrix equation
or in even more reduced form as
A x = b.


In this example, A is a 2 x 3 matrix, while x and b are column vectors (or 3 x 1 matrices). Number of rows first, then number of columns.

Theoretically from linear algebra we know the following. The first step is to understand the homogeneous equation, then we use that to understand the general situation.

This is theoretical. Notice what can go wrong numerically.
So the computer may find solutions that don't actually exist, or may be unable to find the solutions that do exist, due to roundoff errors. This is one major issue we will address in this chapter.

The other main issue is that even if such things don't happen, the number of computations required to solve the system may be very large. It's common to have a 100x100 matrix, for example, which may require a million computations to solve. So we want to make the algorithms as efficient as possible.




If you don't know anything else about the matrix, the simplest algorithm is Gaussian elimination (with backward substitution).

We subtract off successive multiples of previous rows to clear out all lower-triangular terms. We are left with a general upper triangular matrix. We do not reduce the matrix to the identity or reduced row echelon form.

Given a[i,j] and b[i], solve for x[i].

% First make the matrix upper-triangular.
for k from 1 to n-1 do
   for i from k+1 to n do
      m = a[i,k] / a[k,k]
      for j from k+1 to n do
         a[i,j] = a[i,j] - m*a[k,j]
      end do
      b[i] = b[i] - m*b[k]
   end do
end do

% Now solve for the x[i].
x[n] = b[n] / a[n,n]
for i from 1 to n-1 do
   x[n-i] = b[n-i]
   for j from n-i+1 to n do
      x[n-i] = x[n-i] - a[n-i,j]*x[j]
   end do
   x[n-i] = x[n-i] / a[n-i,n-i]
end do


Of course, in the second set of loops, one can do a backward "for" loop if one's program allows it (which all of our software does).

Let's count the number of multiplications and divisions when solving for the matrix:
Similarly we can count the number of additions and subtractions in solving for the matrix, which is
Σk=1n-1 (n-k)(n-k+1) = (n3 - n)/3.

We also want to count the number of multiplications and divisions in solving for x:
Σi=1n-1 (i + n) = (n2+n)/2.

And the number of additions and subtractions in solving for x:
Σi=1n-1 i = (n2-n)/2.

Observe:
The number of computations in solving for x is smaller than the number in solving for the matrix:
O(n2) to solve for x, vs. O(n3) to solve for the matrix.

This is easy to understand, since there are three loops in the matrix computation and only two loops in the x computation.

Roughly the number of operations is n3/3.




If we try to eliminate also the upper triangular terms, we get the Gauss-Jordan method:
  1. Apply Gaussian elimination to reduce the matrix to upper triangular.
  2. Once you have the upper triangular matrix, apply the same row reduction algorithm backwards to eliminate the terms above the diagonal. (Note there are fewer computations than in the first step since some rows are known to have zeroes in both places.
  3. Stop when your matrix is diagonal.
You can write the same type of algorithm as above for this (and you will, for homework) and analyze the number of operations the same way.