Determinant and Rank TODO
Concept
The determinant is a scalar associated with a square matrix that expresses by what factor the linear transformation it represents scales volume, and whether it flips orientation. A determinant of zero means the transformation flattens the space into a lower dimension, which is equivalent to the inverse not existing. Rank is the dimension of the space spanned by the matrix's columns — the maximum number of linearly independent columns — and row rank always equals column rank. By the rank-nullity theorem, for a matrix with n columns, rank plus the dimension of the null space equals n, and this relationship determines whether a system of linear equations has a unique solution or infinitely many. In numerical computation, it's more stable to look at the condition number derived from the singular values than to check whether the determinant is zero, because the determinant is scale-sensitive and unsuitable as an indicator for detecting near-singular matrices.
Whether a linear system has a unique solution, whether the data effectively has redundant explanatory variables, and whether the numerical computation will become unstable — all of these are determined by rank and condition number.
Code & Formula
# 행렬식과 랭크 — det=0 <=> 열이 선형종속 <=> 역행렬 없음 <=> 랭크 부족, 을 수치로 확인한다.
import numpy as np
A_full_rank = np.array([[1.0, 2.0, 0.0],
[0.0, 1.0, 3.0],
[4.0, 0.0, 1.0]])
# 세 번째 열을 앞 두 열의 선형결합으로 만들어 일부러 랭크를 하나 부족하게 만든 행렬
A_deficient = A_full_rank.copy()
A_deficient[:, 2] = 2 * A_full_rank[:, 0] - A_full_rank[:, 1]
for name, A in [("full-rank 행렬", A_full_rank), ("랭크 부족 행렬 (열3 = 2*열1 - 열2)", A_deficient)]:
det = np.linalg.det(A)
rank = np.linalg.matrix_rank(A)
invertible = not np.isclose(det, 0)
print(f"[{name}]")
print(f" det(A) = {det:.6f}")
print(f" rank(A) = {rank} (정방행렬 크기 = {A.shape[0]})")
print(f" 역행렬 존재? {invertible}\n")
# 랭크-널리티 정리: rank(A) + dim(null(A)) = n (열 개수)
n = A_deficient.shape[1]
rank_deficient = np.linalg.matrix_rank(A_deficient)
# SVD로 영공간 차원을 구한다 (특이값이 ~0인 개수)
_, S, _ = np.linalg.svd(A_deficient)
nullity = np.sum(np.isclose(S, 0))
print(f"랭크-널리티 검증: rank({rank_deficient}) + nullity({nullity}) = {rank_deficient + nullity} = n({n})")
Exercise
Construct a rank-deficient 3x3 matrix, confirm its determinant is zero, then add a very small value to one entry and compare how the determinant and the condition number each change.
Practical Connection
When working with data whose columns are nearly linearly dependent — like a price correlation matrix or risk metrics across multiple markets — the solution becomes unstable, so checking rank and condition number before regression or covariance estimation needs to be a habit.
If you study this on a given day, add a note link and a ✅ to this line in the source curriculum (docs/knowledge/math-50-curriculum.md) and this spot will lead straight to the note body. You can also write directly on this page — but regenerating overwrites it, so it's safer to keep anything you want to save as markdown under docs/algorithms/.