We are going to handle equations of type Ax = b in this chapter. Let’s see how linear systems of equations can be represented as a matrix and a vector. Let our LSE in n unknowns (xi) and m equations (the rows) be as in the following:
This suspiciously looks similar to a matrix vector multiplication! If it is not clear to you how, notice that each row i of coefficients ai1…ain gets multiplied with our unknown variables xi. Seeing the matrix-vector picture might help:
This way of writing linear systems of equations lets us argue about the properties of the equations using the properties of the matrix A. For example, we know that Ax calculates a linear combination of A‘s columns where the coefficients are the elements of the vector x. This means we are trying to write b as a linear combination of A‘s columns. This is possible if and only if b∈C(A), ie if b is in the column space of the matrix A.
Gauss Elimination
We can represent linear systems of equations in form of Ax=b using matrix vector multiplication. But how about solving the LSE? Our first algorithm is Gauss Elimination, which actually is the classic algorithm for solving linear systems of equations. It consists of two steps: elimination and back substitution. For this week we assume that our coefficient matrix is m×m, which means that we have a linear system of equations in m equations and m variables. This is the nice case, we will deal with different number of equations and variables later.
If you find a step difficult to understand, go to the subsection below 2.3 Example: Solving Ax=b using Gaussian Elimination to see the theory in practice.
Elimination
We want to generate an upper triangular matrix U using our initial matrix A and the vector b. We want to transform the equation Ax=b into another equation Ux=c where U is an upper triangular matrix and x, the solutions are the same for both systems. In other words we want to create equivalent systems.
It is going to become obvious why we want an upper triangular matrix when we handle back substitution.
There are two main row operations to perform the elimination:
row subtraction
row exchange
These operations do not change the solution of the system when applied on both A and b. This is why we usually concatenate A and b when we perform these elimination steps as follows:
A∣∣∣b
Both operations can be represented as linear transformations!
In the following there are the matrices that represent these linear transformations in the general case:
Eij=⋱1−c↑j⋱1↑i⋱⋱←j⋱←i⋱↑j
(a) Elimination: all diagonal entries are 1, row i, col j is −c and everything else is 0
Pjk=⋱01↑j⋱10↑k⋱⋱←j⋱←k⋱↑j
(b) Permutation: all diagonal entries except jth and kth are equal to 1. jth and kth diagonal entries are 0 and row j col k and row k col j are 1.
The permutation matrix Pjk swaps rows j and k and Eij represents the elimination matrix. When multiplied with the original matrix A as EijA, it subtracts c times row j from row i. To better convince yourself to this you can think of the matrix multiplication EijA as linear combinations of the rows of A using the row vectors of Eij as the coefficients. The i-th row of EijA is −c times the jth row of A plus 1 times the ith row of A.
When do we use the row operations?
We try to generate an upper triangular matrix with nonzero elements on the diagonal. So if we have a nonzero element under the diagonal, we subtract one row from the other to get rid of it. We exchange rows when we get a zero element on the diagonal, i.e. when we have a pivot that is equal to 0.
The diagonal entry of the current column is called the pivot.
After completing the elimination we are left with the equation Ux=c that has the same solutions as our initial equation Ax=b. We are going to prove this but first let’s continue solving the LSE with back substitution:
Back Substitution
After we get to an upper triangular matrix, we have our equation suitable for back substitution. This step is not different than what you would do in high school to solve a linear system of equations. Let’s see it in a 3×3 example. Here we name the matrix U and the right hand side vector c to stress that they are transformed and not the same as the initial A and b at this point. As mentioned in previous paragraph, the solution is still the same.
And we are done! The vector x∈R3 that satisies Ax=b is:
x=−2182110211.
We found a solution! However this is not always the case. Depending on the particular LSE there might be infinitely many solutions or no solutions at all and our algorithm might fail in some cases. To be more precise, we get stuck if we can’t make the pivot nonzero using row exchanges. You can see the pdf on my website What does failure actually mean in Gaussian Elimination? to gain a little more insight on what might happen when the algorithm fails.
Row Operations: the general picture
There are important lemmas that formalize our intuition about the algorithm and actually prove that the solution to the transformed LSE Ux=c is the same as the solution for Ax=b. The most important one is:
Lemma
3.2
(Invariance of solutions)
Let A be an m×n matrix, M an invertible m×m matrix and b∈Rm. Then the two systems Ax=b and MAx=Mb have the same solutions x.
Lemma 3.2 justifies that Gauss elimination with back substitution finds the solution of the actual LSE and does not change it with row subtractions and permutations. Note that both row subtractions and permutations are repreented with invertible matrices. To invert them simply add the row back or swap the two rows back!
Lemma
3.3
(Invariance of the nullspace)
Let A be an m×n matrix and M an invertible m×m matrix. Then A and MA have the same nullspace, N(A)=N(MA).
Lemma
3.4
(Invariance of linear independence)
Let A be an m×n matrix and M an invertible m×m matrix. Then the following is true: A has linearly independent columns if and only if MA has linearly independent columns.
You can use Lemma 3.3 to prove Lemma 3.4
Lemma
3.5
(Invariance of the row space)
Let A be an m×n matrix and M an invertible m×m matrix. Then A and MA have the same row space, R(A)=R(MA).
The row space is the column space of the transpose by its definition. Hence we need to show C(A⊤)=C(A⊤M⊤). Note that M⊤ is also invertible (by Lemma 2.59 ∼ “transpose of invertible matrix is invertible”). Now we argue about the equality of two sets by showing if a vector is an element of one, then it is also an element of the other:
For C(A⊤)⊆C(A⊤M⊤):
v∈C(A⊤)⇒v=A⊤x for some x∈Rm⇒v=A⊤M⊤x′ for some x′∈Rm(x′=(M⊤)−1x)⇒v∈C(A⊤M⊤)
For C(A⊤M⊤)⊆C(A⊤) :
v∈C(A⊤M⊤)⇒v=A⊤M⊤x for some x∈Rm⇒v=A⊤x′ for some x′∈Rm(x′=M⊤x)⇒v∈C(A⊤)
□
The key element that enables this proof is that M⊤ is invertible. This is why we could find x′ for arbitrary x in the first part of the proof such that x=M⊤x′.
This proof is written in a more compact way in the lecture notes and I recommend to read the proofs of all lemmas in this section from there.
One must be careful as the same property does NOT hold for the column space. In general C(A) is not equal to C(MA). Here is a counterexample:
A=[0100],M=[0110]
M is invertible, in fact it is self-inverse ie.M2=I. We have
MA=[1000]
Now look at C(A) and C(MA):
C(A)C(MA)={λ⋅(01)∣λ∈R}={λ⋅(10)∣λ∈R}
which are different from each other. (01)⊤∈C(MA) and (10)⊤∈C(A).
The column spaces of A and MA are not the same, however their ranks are the same. In particular we can make the following statement:
Lemma
3.6
(Invariance of independent column indices and rank)
Let A be an m×n matrix, M an invertible m×m matrix. Then the following is true for all j∈[n]: column j of A is independent if and only if column j of MA is independent. In particular, A and MA have the same number of independent columns and therefore also the same rank.
Finally, we can say when the elimination fails and when it succeeds. This is the case when the columns of A are linearly independent. This makes sense since m linearly independent vectors can span the whole Rm so there exists a unique x∈Rm for every b∈Rm such that Ax=b, given that the columns of A are linearly independent. The following theorem formalizes this. You can find a beautiful proof in the lecture notes.
Theorem
3.8
(Solving A𝐱 = 𝐛 with Gauss elimination)
Let Ax=b be a system of m linear equations in m variables. If A has linearly independent columns, then Gauss elimination with back substitution computes the unique solution x of the system. If A has linearly dependent columns, then Gauss elimination fails.
Runtime
It is always good to know the runtime of an algorithm you use. Here it is for Gauss Elimination. You can find the full runtime analysis in the lecture notes.
For m equations and m unknowns:
Gauss Elimination: O(m3)
Back Substitution: O(m2)
Gauss Elimination with Back Substitution: O(m3)
Calculating the inverse of an invertible m×m matrix as in Algorithm 3 from the lecture notes: O(m3)
Algorithm: Calculating the Inverse
We can use Gauss elimination with back substitution to calculate the inverse of a matrix. Let’s put the problem of calculating the inverse in terms of solving LSE’s. We want to find the inverse of a matrix A∈Rm×m. Call A−1=B for sake of simplicity in notation. We look for B∈Rm×m with columns b1,…,bm∈Rm such that:
AB=I
Taking a closer look into the matrix multiplication, we can formulate this expression as follows:
∣Ab1∣∣Ab2∣⋯∣Abm∣=∣e1∣∣e2∣⋯∣em∣
The equality of two matrices means their columns must match. So we want the columns of B to satisfy:
Ab1=Ab2=⋮Abm=e1e2em
There we have m linear systems of equations, all of which we can try to solve using Gauss elimination with back substitution. If Gauss elimination fails we know by Theorem 3.7 and Theorem 3.8 that the matrix A has linearly dependent columns and hence is not invertible. Therefore we can assume that Gauss elimination succeeds for the following computations.
Applying Gauss elimination transforms A into an upper triangular form and all ei‘s are also modified during the process. For upper triangular U we have:
Ub1=Ub2=⋮Ubm=c1c2cm
Now we can do back substitution to find the individual columns bi. We will have calculated the inverse once we have all the columns.
Runtime Optimization: m right hand sides
If you try to do the Gauss elimination (that has runtime O(m3)) step from scratch for all m equations we get a runtime of O(m4). We do not want this. You probably agree that calculating the U from scratch is not necessary since U is determined only by the matrix A. What we can do to improve this is to apply the algorithm for m right hand side vectors.
We usually write the matrix in augmented form as [A∣y] when we try to solve one linear system of equation Ax=y. We do the same here, but for all right hand sides. To continue with the example from above we have:
∣a1∣∣a2∣⋯∣am∣∣e1∣∣e2∣⋯∣em∣.
Now you can apply row subtractions and row swaps to A and at the same time to all m right hand side vectors. In the end you have:
∣u1∣∣u2∣⋯∣um∣∣c1∣∣c2∣⋯∣cm∣.
where ui‘s are the columns of the upper triangular matrix U and cj‘s are the right hand side vectors after elimination. This operation takes O(m3) time since we apply the elimination to all right hand sides at the same time. To convince yourself to this fact you can read section 3.2.6 from the lecture notes.
Now we have our upper triangular matrix U on the left side and the vectors cj from before on the right side. We can do back substitution 3 times to get the inverse:
A is invertible if and only if Ax=0 for all x=0. Use it and show that one of the entries of the vector Ax can not be equal to 0.
This one is very similar to the in class exercise. Make a linear system of equations out of the given data points. Remember, the variables you want to find are a,b,c.
Try to represent AA−1=I as three separate systems of equations. Be careful with division. You can divide by a variable μwith the constraint thatμ=0 and afterwards you must specify what happens when that variable is zero. In other words make a small case distinction.
You can first guess the inverse and then verify that AA−1=I by direct computation or calculate the inverse using Gauss elimination with back substitution. b) Assume that the pattern from A holds in general. Try to generalize it by writing the columns of the inverse using unit vectors. Then show that the matrix you described is actually the inverse.
Try to write the equations using matrices as in W=VM.