Lecture 35 · Week 9· 17:18
Computing determinants
Row reduction, cofactor expansion.
Saved in this browser only. No account needed.
TranscriptThe full text of the lecture. Click any sentence to play the video from there.
Today: computing determinants
Welcome back. In lecture thirty four we defined the determinant of an n by n matrix A by the Leibniz formula. It is a sum over all permutations sigma of one up to n. Each term is the sign of sigma, times a product of n entries, one from each row and one from each column. We also proved its key properties. The determinant is linear in each row, when the other rows are fixed. Swapping two rows changes its sign. A matrix with two equal rows has determinant zero. And a matrix and its transpose have the same determinant. But the formula is slow. It has one term for every permutation, and there are n factorial of them. A three by three matrix has six terms. A ten by ten matrix has more than three and a half million terms, each a product of ten entries.
Today we compute determinants efficiently. First, we see what row operations do to the determinant, and why triangular matrices are easy. This gives the method of row reduction. Then we expand a determinant along any row or column, using cofactors.
Row operations and the determinant
Let A be an n by n matrix over a field F. What does each of the three row operations do to its determinant? Here is the theorem. A replacement, which adds c times row j to row i, with i different from j, does not change the determinant. A swap of two rows multiplies it by minus one. And scaling a row by c multiplies it by c. The last two are properties from lecture thirty four. Scaling row i by c multiplies the determinant by c, because the determinant is linear in row i. And a swap changes the sign.
The replacement takes one more step. After the replacement, row i is r i plus c times r j. By linearity in row i, the determinant splits into two parts. The first part is the determinant of A itself. The second part is c times the determinant of the matrix with r j in row i. But that matrix has r j in two places, in row i and in row j. A matrix with two equal rows has determinant zero. So the second part is zero, and the replacement does not change the determinant. Let's check this on a two by two matrix, with rows (two, one), and (four, five). Its determinant is two times five, minus one times four, which is six.
Subtract two times row one from row two. In the first entry, four minus four is zero. In the second, five minus two is three. So the new second row is (zero, three), and the determinant is two times three, minus one times zero. It is still six. Swapping the two rows gives four times one, minus five times two, which is minus six. Tripling the first row gives the row (six, three): three times two is six, and three times one is three. Its determinant is six times five, minus three times four, which is eighteen, three times six. In short: replacements are free, swaps flip the sign, and scaling a row scales the determinant.
Triangular, elementary matrices
Which matrices have an easy determinant? In lecture thirty four we proved that the determinant of an upper or lower triangular matrix is the product of its diagonal entries. Upper triangular means that every entry below the diagonal is zero. The reason is that every permutation other than the identity picks at least one entry from the zero side of the diagonal. So only the diagonal term survives. In particular, the identity matrix has determinant one. Now apply the row operation theorem to the identity matrix. An elementary matrix is the identity after one row operation, by lecture seventeen. So the matrix of a replacement has determinant one, the matrix of a swap has determinant minus one, and the matrix of scaling by c has determinant c.
Also by lecture seventeen, E times A performs that row operation on A. So the determinant of E A is the determinant of E, times the determinant of A, for every elementary matrix E. In lecture thirty six this becomes a rule for every product of two square matrices.
Determinants by row reduction
This gives a method. Reduce A to an echelon form U, using replacements and swaps only. By lecture eight this is always possible, because forward elimination never needs scaling. A square echelon form is upper triangular, by lecture fifteen. Replacements keep the determinant, and each swap changes its sign. So if s swaps were used, the determinant of A is minus one to the power s, times the product of the diagonal entries of U. Let's compute an example: the three by three matrix with first row (zero, one, two), second row (one, three, one), and third row (two, four, three).
The top left entry is zero, so we swap rows one and two. That is one swap, so we record a factor of minus one. Next, subtract two times row one from row three. In the first entry, two minus two is zero. In the second, four minus six is minus two. In the third, three minus two is one. So the new third row is (zero, minus two, one). Then add two times row two to row three. In the second entry, minus two plus two is zero. In the third, one plus four is five. So the new third row is (zero, zero, five).
This is an echelon form, with the diagonal entries one, one, and five. Their product is five. There was one swap, so the determinant of A is minus one times five, which is minus five. If an echelon form of A has a zero row, its last diagonal entry is zero, and so the determinant of A is zero. In lecture thirty six we will see that this happens exactly when A is not invertible. Row reduction is fast. By lecture eighteen, elimination on an n by n matrix takes at most n cubed minus n, over three, multiplications and divisions. A swap costs no arithmetic. For a ten by ten matrix that is at most three hundred and thirty for the elimination, and nine more for the diagonal: at most three hundred and thirty nine operations, instead of millions of terms. This is how computers find determinants.
Minors and cofactors
Now the second method. Let A be an n by n matrix, with n at least two. The minor A i j is the n minus one by n minus one matrix we get by deleting row i and column j of A. The cofactor C i j is minus one to the power i plus j, times the determinant of the minor A i j. The sign, minus one to the power i plus j, follows a checkerboard. It is plus in the top left corner, and it alternates along every row and every column.
Here is the theorem. For every row i, the determinant of A is the sum, over j, of a i j times C i j. This is the expansion along row i. And for every column j, the determinant of A is the sum, over i, of a i j times C i j. This is the expansion along column j. Let's try it on our matrix, along row one. Its first entry is zero, so we do not need its cofactor. The second entry is one. Deleting row one and column two leaves the rows (one, one), and (two, three). Their determinant is three minus two, which is one. The sign in this position is minus, so C one two is minus one.
The third entry is two. Deleting row one and column three leaves the rows (one, three), and (two, four). Their determinant is four minus six, which is minus two. The sign is plus, so C one three is minus two. So the determinant of A is zero, plus one times minus one, plus two times minus two. That is minus five, as row reduction gave. Column one gives the same. Its entries are zero, one and two. C two one is minus the determinant of the rows (one, two), and (four, three), so minus of minus five, which is five. C three one is the determinant of the rows (one, two), and (three, one), which is minus five. So the determinant is one times five, plus two times minus five, which is minus five again.
Why the expansion works
Why does the expansion work? Here is the plan first. The proof for rows has three steps, and each step uses the one before it. Then the columns follow from the transpose. Step one is the simplest case. If the first row of A is one, followed by zeros, then the determinant of A is the determinant of its minor A one one. Step two moves a single one into the top left corner. If row i of A is all zeros, except a one in column j, then the determinant of A is the cofactor C i j.
Step three is the expansion itself, for any row. It splits row i into rows of the kind in step two. Suppose for a moment that steps one and two are true. To see the idea, take a three by three matrix, and row two. This row is a two one times e one, plus a two two times e two, plus a two three times e three, written as rows. The determinant is linear in row two, so it splits into three determinants, one for each piece. In the second one, row two is e two, a one in column two. Step two says that if row i is e j, the determinant is the cofactor C i j. Deleting row two and column two leaves the same entries as in A, so this determinant is C two two. The same holds for the other two. So the determinant of A is the sum of a two j times C two j, the expansion along row two.
Now the general case, an n by n matrix and any row i. Row i is the sum, over j from one to n, of a i j times e j, written as a row. For each j, let A superscript j be A with row i replaced by e j. The determinant is linear in row i, so the determinant of A is the sum of a i j times the determinant of A superscript j. Row i is the only row that changed. So deleting row i and column j from A superscript j leaves exactly the minor A i j. And row i of A superscript j is e j, so step two applies: the determinant of A superscript j is C i j. So the determinant of A is the sum of a i j times C i j. This is the expansion along row i. Now we check step two, on a four by four example with i equal to three, and j equal to two. Take row i, with its one in column j. Swap it with the row above it, again and again, until it is the first row. Here that takes two swaps, and in general, i minus one. The other rows keep their order.
Each row swap changes the sign, so the row swaps give minus one to the power i minus one. Then swap column j with the column to its left, again and again, until it is the first column. That takes j minus one swaps, here one, and the other columns keep their order. By lecture thirty four, a column swap also changes the sign, so the column swaps give minus one to the power j minus one. Together, the sign is minus one to the power i minus one plus j minus one, which is minus one to the power i plus j. The one is now in the top left corner, with zeros beside it. Deleting its row and column leaves the other rows and columns of A, in their original order, so the rest is exactly the minor A i j. Now we use step one: when the first row is one followed by zeros, the determinant equals the determinant of the minor. So the determinant of A is minus one to the power i plus j, times the determinant of A i j. That is C i j. Last, step one, from the Leibniz formula. Each term is a sign, times one entry from every row and every column. Its entry from row one is a one sigma of one, which is zero unless sigma of one is one, and then it is one. So only the permutations with sigma of one equal to one remain.
Their other entries avoid row one and column one, so they are entries of the minor A one one. Entry k l of the minor is a k plus one, l plus one. So each remaining term picks one entry from every row and every column of the minor, by the permutation tau, with tau of k equal to sigma of k plus one, minus one. Each tau comes from exactly one sigma, found by adding one back. It remains to compare the signs. Take one surviving term, with sigma equal to one, three, four, two, and draw its strings. The first string goes straight down at the far left, so it crosses no other string. Remove it and renumber, and we get tau equal to two, three, one, with the same two crossings. The same holds for every sigma. A pair with position one is never an inversion, because sigma of one is one, the smallest value. And positions k plus one and l plus one are an inversion of sigma exactly when k and l are an inversion of tau, since subtracting one keeps the order. So sigma and tau have the same number of inversions, and the same sign. The sum is then the Leibniz formula for the minor, so the determinant of A is the determinant of A one one.
For the columns, use the transpose. Its determinant is the determinant of A, by lecture thirty four. Column j of A is row j of the transpose, and the minor there is the transpose of A i j, with the same determinant. So by step three, we can expand the transpose along row j, and that is expanding A along column j.
Choosing a method
Expansion pays off along a row or column with many zeros, because each zero entry saves a whole cofactor. Take this four by four matrix. Its second column has only one nonzero entry, a three in row three. So the determinant is three times C three two. The sign in row three, column two is minus. Deleting row three and column two leaves the matrix with first row (two, one, three), second row (one, zero, two), and third row (one, two, one). We expand this three by three determinant along its second row, which has a zero. The cofactor of its first entry is minus the determinant of the rows (one, three), and (two, one), which is minus of minus five, so five. The cofactor of its last entry is minus the determinant of the rows (two, one), and (one, two), which is minus three.
So the three by three determinant is one times five, plus two times minus three, which is minus one. And the determinant of the four by four matrix is three, times minus one, times minus one, which is three. The two methods combine well. Take the matrix with first row (one, two, one), second row (two, five, four), and third row (three, seven, two). Two replacements clear the first column below the top entry, and they do not change the determinant. Subtract two times row one from row two: two minus two is zero, five minus four is one, and four minus two is two. Then subtract three times row one from row three: three minus three is zero, seven minus six is one, and two minus three is minus one.
Now expand along column one. Only the top entry is left, and its sign is plus. So the determinant is one times the determinant of the rows (one, two), and (one, minus one). That is minus one minus two, which is minus three. Expansion alone is slow for large matrices: expanding all the way down gives back all n factorial terms. Row reduction stays fast. To sum up. Replacements keep the determinant, swaps change its sign, and scaling a row scales it. A triangular matrix has the product of its diagonal as its determinant, so row reduction computes any determinant. And the determinant expands along any row or any column, with cofactors.
Cofactors come back in lecture thirty six, where they build the inverse of a matrix and solve systems by Cramer's rule. Before the next lecture, read section seven point three of the course book, try the problems on sheet nine about computing determinants, and do the lecture check on this lecture's page at Open Semester dot com. Next time, we prove that the determinant of a product is the product of the determinants. See you there.
In this lecture
Materials
Check yourself
3 questions, from warm-up to stretch
Work each one out on paper, type your answer and press Check. Stuck? Open a hint; the worked solution is there when you need it.
- Question 1 of 3 Warm-up
Let be a matrix over with . Find the determinant of each matrix below, made from by one row operation. : swap rows and (). : add times row to row (). : multiply row by ().
Hint 1 of 2
Theorem 7.3.1 says what each kind of row operation does to the determinant: a replacement, a swap and scaling a row each have their own rule.
Hint 2 of 2
A swap multiplies the determinant by , a replacement leaves it unchanged, and multiplying one row by multiplies the determinant by .
Worked solution
- comes from a swap, which changes the sign (the swap rule of Theorem 7.3.1): .
- comes from a replacement, which does not change the determinant (the replacement rule of Theorem 7.3.1): .
- comes from multiplying one row by , which multiplies the determinant by (the scaling rule of Theorem 7.3.1): .
- Question 2 of 3 Core
Find for over by row reduction, as in Example 7.3.5: use only replacements and swaps, and start by swapping rows and . How many swaps did you use, and what is ?
Hint 1 of 2
The top left entry is , so swap rows and first. Then clear the first column below the top entry, and then the second column below the second pivot.
Hint 2 of 2
After , and you reach an echelon form . By Theorem 7.3.4, times the product of the diagonal entries of .
Worked solution
- Swap : . This is one swap, a factor .
- : the third row becomes . A replacement, no change.
- : the third row becomes . Now is upper triangular.
- By Theorem 7.3.4, .
- Check by cofactor expansion along column (Theorem 7.3.9): .
- Question 3 of 3 Stretch
Let over . Its second column has only one nonzero entry. Expand along that column, as in Example 7.3.13: find the sign of that position, the determinant of the minor , and .
Hint 1 of 2
Along column only is nonzero, so (Theorem 7.3.9, along a column). Delete row and column to get .
Hint 2 of 2
. Its second column again has one nonzero entry, a in row , in a position with sign .
Worked solution
- Column of is , so by Theorem 7.3.9 (along a column) .
- Deleting row and column leaves .
- Expand along its second column, where only the in row is nonzero, with sign : .
- So .
How did it go?