Determinant by Pivots: A Python Algorithm
Implement an algorithm to compute determinants in Python.
We'll cover the following
Formulas for determinant
There are three formulas for calculating determinants.
- Determinant by pivots
- Determinant by permutations
- Determinant by cofactors and minors
Determinant by pivots
The pivot formula we’ll implement in this lesson is based on the property that the determinant of a triangular matrix is the product of its diagonal entries.
Elimination converts a matrix to an echelon matrix (triangular matrix). Every non-zero entry on the diagonal of the echelon matrix is the pivot. A diagonal entry equaling zero implies the following:
- The matrix has dependent columns. That is, the matrix is singular.
- The product of the diagonal entries is zero. That is, the determinant is zero.
The operations involved in elimination preserve the solution set system. However, not all operations preserve the determinant. As explained in the previous lesson, row sum has no effect on the determinant of the matrix. However, row swap and row scaling operations change the determinant. With each row swap operation, the sign of the determinant is toggled, whereas with every row scaling operation, the determinant is also scaled proportionally. If we track these changes during elimination, we can write the pivot formula as follows:
where is the number containing all sign reversals and scaling factors. For computing , we could keep an integer variable that’s initialized with , multiplied by for each row swap, and multiplied by a factor, , for each row scale.
The np.linalg.det()
Python function doesn’t rely on elimination to convert a matrix to a triangular form. For square matrices, we could convert them to their triangular matrix by using only the row sum operation. Let’s look at an example of this:
Get hands-on with 1400+ tech skills courses.