Vectors, Matrices, Matrix Multiplication, Inverse Matrices TODO
Concept
A vector is an element expressed in coordinates, and a matrix is a linear transformation written in coordinates with respect to a basis. Matrix multiplication is composition of transformations, so it's associative but generally not commutative; for an (m×n) matrix times an (n×p) matrix, the inner dimensions must match, and the naive computation cost is O(mnp). An inverse exists only for a square matrix that is invertible, which is equivalent to having a nonzero determinant — equivalently, to the columns being linearly independent. When solving a linear system Ax=b in actual numerical computation, it's faster and more stable to solve it directly via a method like LU decomposition rather than explicitly computing the inverse. For matrices with a large condition number, small input errors get amplified significantly in the solution.
If you can't read linear algebra notation, you effectively can't read optimization, statistics, or cryptography material at all — and overusing matrix inversion means blindly trusting numerically unstable results.
Code & Formula
# 벡터·행렬·행렬곱·역행렬 — numpy로 기본 연산과, AB != BA(비교환성), A@A^-1=I 를 확인한다.
import numpy as np
A = np.array([[1.0, 2.0], [3.0, 4.0]])
B = np.array([[0.0, 1.0], [1.0, 0.0]])
v = np.array([1.0, 2.0])
print("A =\n", A)
print("A @ v (선형변환으로서의 행렬-벡터곱) =", A @ v)
AB = A @ B
BA = B @ A
print("\nA@B =\n", AB)
print("B@A =\n", BA)
commute = np.allclose(AB, BA)
print(f"A@B == B@A ? {commute} → 이 예처럼 행렬곱은 일반적으로 교환법칙이 성립하지 않는다")
det_A = np.linalg.det(A)
print(f"\ndet(A) = {det_A:.4f} (0이 아니므로 A는 가역)")
A_inv = np.linalg.inv(A)
identity_check = A @ A_inv
print("A @ A_inv =\n", np.round(identity_check, 10), "→ 단위행렬 I 확인")
# Ax = b 를 풀 때는 명시적 역행렬보다 solve()가 수치적으로 더 안정적이고 빠르다
b = np.array([5.0, 10.0])
x_via_solve = np.linalg.solve(A, b)
x_via_inv = A_inv @ b
print(f"\nAx=b 해: solve()={x_via_solve}, inv()@b={x_via_inv} (둘 다 일치, solve가 권장 방식)")
Exercise
Compute the product and inverse of a 2x2 and a 3x3 matrix by hand and check them against NumPy's output, then experiment with how much the error in the computed inverse grows for matrices with a large condition number.
Practical Connection
This is used directly in state-transition probability matrices, parameter estimation via regression, and market-maker parameter calibration; linear algebra over finite fields is also fundamental to cryptography and erasure-code implementations.
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/.