Determinant of Order 2
For a matrix :
Determinant of Order 3
For a matrix :
Example: Compute 2Ã2 Determinant
Find the determinant of .
Example: Compute 3Ã3 Determinant
Find the determinant of .
Minors and Cofactors
Expansion Along Any Row
What a determinant measures
Take the columns of a matrix as two arrows drawn from the origin. The determinant is the signed area of the parallelogram those arrows span. For the area is square units. Swap the two columns and you get , whose determinant is : the same magnitude, opposite sign, because the orientation of the pair flipped.
In three dimensions the same idea gives the signed volume of the parallelepiped built on the three column vectors. Volume zero means the three vectors lie in a common plane, and that geometric collapse is precisely what makes the matrix singular. So is not just an arithmetic accident; it reports a flat, degenerate shape.
How row operations move the determinant
Three rules cover every elementary row operation, and each one has a checkable numeric effect. Start from , where .
- Swapping two rows multiplies the determinant by . Swap to get , and .
- Scaling one row by multiplies the determinant by . Doubling the first row gives , and .
- Adding a multiple of one row to another leaves the determinant untouched. Replace row 2 by row 2 plus twice row 1 to get , and , unchanged.
Rule 3 is the useful one: it is the only operation that lets you create zeros without paying for them, which is exactly how row reduction produces triangular forms whose determinant is just the product of the diagonal entries.
Computing determinants in Python
A quick check against the closed formulas saves marks on multi-digit problems. The script below builds a and a matrix, compares numpy's answer with the expansion formula, and prints both.
import numpy as np
A2 = np.array([[3, 5], [2, 7]])
manual2 = A2[0, 0] * A2[1, 1] - A2[0, 1] * A2[1, 0]
print("2x2:", np.linalg.det(A2), manual2) # 11.0 11
A3 = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
a, b, c = A3[0]
d, e, f = A3[1]
g, h, i = A3[2]
manual3 = a * (e * i - f * h) - b * (d * i - f * g) + c * (d * h - e * g)
print("3x3:", round(np.linalg.det(A3)), manual3) # 3x3: 0 0
print("singular:", abs(np.linalg.det(A3)) < 1e-9) # singular: True
Writing a determinant from first principles, without a library, means turning the matrix into an upper triangular form and multiplying the diagonal. Each row swap flips the sign, which the function below tracks explicitly.
def determinant(mat):
m = [row[:] for row in mat]
n = len(m)
sign, result = 1, 1.0
for col in range(n):
pivot = next((r for r in range(col, n) if abs(m[r][col]) > 1e-12), None)
if pivot is None:
return 0.0
if pivot != col:
m[col], m[pivot] = m[pivot], m[col]
sign *= -1
result *= m[col][col]
for r in range(col + 1, n):
factor = m[r][col] / m[col][col]
for c in range(col, n):
m[r][c] -= factor * m[col][c]
return sign * result
print(determinant([[3, 5], [2, 7]])) # 11.0
print(determinant([[2, 1], [3, 4]])) # 5.0
print(determinant([[1, 2], [2, 4]])) # 0.0
Choosing the cheapest row or column to expand
Expansion along any row or column gives the same number, so the choice should be driven by zeros. Take . Expanding along the first row costs three determinants: . The second column, whose entries are , , , is the cheapest of all, because only one term survives â the cofactor sign there is plus, so you get again. The third column is nearly as cheap, needing only .
Reading a zero determinant correctly
When , four statements become equivalent, and any one of them is enough to conclude the rest: the rows are linearly dependent, the columns are linearly dependent, the matrix has no inverse, and the system either has no solution or infinitely many. The worked example above ended at for because row 3 minus twice row 2 plus row 1 gives the zero row â a dependency you can see without any arithmetic at all.
Key Takeaways
- A determinant is a signed area in 2D and a signed volume in 3D, so a zero value means the column vectors collapse into a lower dimensional flat shape.
- Swapping rows flips the sign, scaling one row scales the determinant by the same factor, and adding a multiple of one row to another changes nothing.
- Expanding along whichever row or column holds the most zeros is always valid and usually cuts the number of 2 by 2 sub-determinants you must compute.
- A zero determinant is equivalent to linearly dependent rows, a missing inverse, and a system that either has no solution or infinitely many.
Common Mistakes
Applying the 2 by 2 rule ad - bc to a 3 by 3 matrix by crossing terms diagonally
Fix: Expand along a row or column with the sign pattern plus, minus, plus, and always factor the cofactor sign before multiplying.
Adding a multiple of one row to another and then multiplying the determinant by that multiple
Fix: Only scaling or swapping changes the determinant; a replacement operation such as row 2 plus three times row 1 leaves it exactly as it was.
Treating a floating-point determinant near zero as proof of invertibility
Fix: Compare against a tolerance such as 1e-9 rather than testing for exact equality, because decimal arithmetic rarely lands on zero.