Workspace IndexMath › Day 18

Vectors, Matrices, Matrix Multiplication, Inverse Matrices TODO

Math · Day 18 / 52 · September — Linear Algebra (Day 18-26)

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/.


한국어

벡터·행렬·행렬곱·역행렬 TODO

Math · Day 18 / 52 · 9월 — 선형대수 (Day 18–26)

개념

벡터는 좌표로 표현된 원소이고 행렬은 선형변환을 기저에 대해 좌표로 적은 것이다. 행렬곱은 변환의 합성이므로 결합법칙은 성립하지만 교환법칙은 일반적으로 성립하지 않으며, (m×n)과 (n×p)처럼 안쪽 차원이 맞아야 정의되고 순진한 계산 비용은 O(mnp)다. 역행렬은 정사각행렬이 가역일 때만 존재하고, 이는 행렬식이 0이 아니라는 것, 즉 열벡터들이 선형독립이라는 것과 동치다. 선형계 Ax=b를 풀 때 실제 수치계산에서는 역행렬을 명시적으로 구하기보다 LU 분해 같은 방법으로 바로 푸는 편이 빠르고 안정적이다. 조건수가 큰 행렬에서는 작은 입력 오차가 해에서 크게 증폭된다.

선형대수 표기를 못 읽으면 최적화·통계·암호학 문서를 통째로 못 읽고, 역행렬을 남용하면 수치적으로 불안정한 결과를 그대로 신뢰하게 된다.

코드 · 수식

# 벡터·행렬·행렬곱·역행렬 — 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가 권장 방식)")

연습

2×2와 3×3 행렬의 곱과 역행렬을 손으로 계산해 NumPy 결과와 대조하고, 조건수가 큰 행렬에서 역행렬 계산 오차가 얼마나 커지는지 실험하라.

실무 · Verex 연결

상태 전이 확률 행렬, 회귀를 통한 파라미터 추정, 마켓 메이커 파라미터 캘리브레이션에 직접 쓰이며, 유한체 위의 선형대수는 암호학과 소거 부호 구현의 기본기다.

공부한 날 원본 커리큘럼(docs/knowledge/math-50-curriculum.md)의 이 줄에 노트 링크와 ✅ 를 붙이면, 이 자리는 노트 본문으로 바로 이어집니다. 노트 없이 이 페이지에 바로 적어도 됩니다 — 다만 다시 생성하면 덮어쓰이므로, 남길 글은 docs/algorithms/ 의 마크다운으로 쓰는 편이 안전합니다.

← 17. 반복게임과 평판19. 내적·노름·코사인 유사도 →