Module 1c: Linear Algebra Formula Sheet Mathematical Foundations | COMP 521
San Diego State University
Readings are reviewed and finalized at least one week before they are
assigned , so you will always have a settled version before you need it. Until
then, expect rough edges — wording, examples, and cross-references may change.
Where a reading disagrees with the syllabus, the syllabus is right. If something
here does not work, tell me: that is genuinely useful and I would rather hear it
from you than not.
Essential Vector Operations ¶ Dot Product:
a ⃗ ⋅ b ⃗ = a x b x + a y b y + a z b z = ∣ a ⃗ ∣ ∣ b ⃗ ∣ cos θ \vec{a} \cdot \vec{b} = a_x b_x + a_y b_y + a_z b_z = |\vec{a}||\vec{b}|\cos\theta a ⋅ b = a x b x + a y b y + a z b z = ∣ a ∣∣ b ∣ cos θ Physical Applications:
Work: W = F ⃗ ⋅ d ⃗ W = \vec{F} \cdot \vec{d} W = F ⋅ d
Power: P = F ⃗ ⋅ v ⃗ P = \vec{F} \cdot \vec{v} P = F ⋅ v
Projection of a ⃗ \vec{a} a onto b ⃗ \vec{b} b : proj b ⃗ a ⃗ = a ⃗ ⋅ b ⃗ ∣ b ⃗ ∣ 2 b ⃗ \text{proj}_{\vec{b}}\vec{a} = \frac{\vec{a} \cdot \vec{b}}{|\vec{b}|^2}\vec{b} proj b a = ∣ b ∣ 2 a ⋅ b b
Cross Product:
a ⃗ × b ⃗ = ( a y b z − a z b y a z b x − a x b z a x b y − a y b x ) \vec{a} \times \vec{b} = \begin{pmatrix} a_y b_z - a_z b_y \\ a_z b_x - a_x b_z \\ a_x b_y - a_y b_x \end{pmatrix} a × b = ⎝ ⎛ a y b z − a z b y a z b x − a x b z a x b y − a y b x ⎠ ⎞ Magnitude: ∣ a ⃗ × b ⃗ ∣ = ∣ a ⃗ ∣ ∣ b ⃗ ∣ sin θ |\vec{a} \times \vec{b}| = |\vec{a}||\vec{b}|\sin\theta ∣ a × b ∣ = ∣ a ∣∣ b ∣ sin θ
Physical Applications:
Angular momentum: L ⃗ = r ⃗ × p ⃗ \vec{L} = \vec{r} \times \vec{p} L = r × p
Torque: τ ⃗ = r ⃗ × F ⃗ \vec{\tau} = \vec{r} \times \vec{F} τ = r × F
Area of parallelogram: A = ∣ a ⃗ × b ⃗ ∣ A = |\vec{a} \times \vec{b}| A = ∣ a × b ∣
Vector Norms and Properties:
Magnitude: ∣ v ⃗ ∣ = v x 2 + v y 2 + v z 2 |\vec{v}| = \sqrt{v_x^2 + v_y^2 + v_z^2} ∣ v ∣ = v x 2 + v y 2 + v z 2
Unit vector: v ^ = v ⃗ / ∣ v ⃗ ∣ \hat{v} = \vec{v}/|\vec{v}| v ^ = v /∣ v ∣
Orthogonal if: a ⃗ ⋅ b ⃗ = 0 \vec{a} \cdot \vec{b} = 0 a ⋅ b = 0
Essential Matrix Operations ¶ Basic Operations:
Matrix multiplication: ( A B ) i j = ∑ k A i k B k j (AB)_{ij} = \sum_k A_{ik}B_{kj} ( A B ) ij = ∑ k A ik B kj
Transpose: ( A T ) i j = A j i (A^T)_{ij} = A_{ji} ( A T ) ij = A ji
Identity: I x ⃗ = x ⃗ I\vec{x} = \vec{x} I x = x for all x ⃗ \vec{x} x
Determinant:
2×2 Matrix:
det ( a b c d ) = a d − b c \det\begin{pmatrix} a & b \\ c & d \end{pmatrix} = ad - bc det ( a c b d ) = a d − b c Properties:
det ( A B ) = det ( A ) det ( B ) \det(AB) = \det(A)\det(B) det ( A B ) = det ( A ) det ( B )
det ( A T ) = det ( A ) \det(A^T) = \det(A) det ( A T ) = det ( A )
det ( A − 1 ) = 1 / det ( A ) \det(A^{-1}) = 1/\det(A) det ( A − 1 ) = 1/ det ( A )
Singular if det ( A ) = 0 \det(A) = 0 det ( A ) = 0
Matrix Inverse:
2×2 Matrix:
( a b c d ) − 1 = 1 a d − b c ( d − b − c a ) \begin{pmatrix} a & b \\ c & d \end{pmatrix}^{-1} = \frac{1}{ad-bc}\begin{pmatrix} d & -b \\ -c & a \end{pmatrix} ( a c b d ) − 1 = a d − b c 1 ( d − c − b a ) General Properties:
( A B ) − 1 = B − 1 A − 1 (AB)^{-1} = B^{-1}A^{-1} ( A B ) − 1 = B − 1 A − 1
( A T ) − 1 = ( A − 1 ) T (A^T)^{-1} = (A^{-1})^T ( A T ) − 1 = ( A − 1 ) T
( A − 1 ) − 1 = A (A^{-1})^{-1} = A ( A − 1 ) − 1 = A
Eigenvalues and Eigenvectors ¶ Definition:
A v ⃗ = λ v ⃗ A\vec{v} = \lambda\vec{v} A v = λ v Characteristic Equation:
det ( A − λ I ) = 0 \det(A - \lambda I) = 0 det ( A − λ I ) = 0 Properties:
Trace: tr ( A ) = ∑ i A i i = ∑ i λ i \text{tr}(A) = \sum_i A_{ii} = \sum_i \lambda_i tr ( A ) = ∑ i A ii = ∑ i λ i
Determinant: det ( A ) = ∏ i λ i \det(A) = \prod_i \lambda_i det ( A ) = ∏ i λ i
For symmetric matrices: all eigenvalues are real
Numerical Stability Quick Checks ¶ Condition Number ¶ κ ( A ) = ∣ ∣ A ∣ ∣ ⋅ ∣ ∣ A − 1 ∣ ∣ = σ max σ min \kappa(A) = ||A|| \cdot ||A^{-1}|| = \frac{\sigma_{\max}}{\sigma_{\min}} κ ( A ) = ∣∣ A ∣∣ ⋅ ∣∣ A − 1 ∣∣ = σ m i n σ m a x Interpretation:
κ < 10 \kappa < 10 κ < 10 : Excellent
10 < κ < 1 0 3 10 < \kappa < 10^3 10 < κ < 1 0 3 : Good
1 0 3 < κ < 1 0 6 10^3 < \kappa < 10^6 1 0 3 < κ < 1 0 6 : Use caution
κ > 1 0 6 \kappa > 10^6 κ > 1 0 6 : Ill-conditioned
Machine Epsilon ¶ Python/NumPy Quick Reference ¶ # Vectors
np.dot(a, b) # Dot product
np.cross(a, b) # Cross product
np.linalg.norm(v) # Vector magnitude
# Matrices
A @ B # Matrix multiplication
A.T # Transpose
np.linalg.inv(A) # Inverse (avoid!)
np.linalg.solve(A, b) # Solve Ax = b (preferred)
np.linalg.det(A) # Determinant
np.linalg.eig(A) # Eigenvalues & eigenvectors
np.linalg.cond(A) # Condition number
# Numerical fixes
A_sym = (A + A.T) / 2 # Force symmetry
A_reg = A + eps * I # RegularizationPositive Definite Matrices ¶ Definition
A symmetric matrix A A A is positive definite if:
x ⃗ T A x ⃗ > 0 ∀ x ⃗ ≠ 0 ⃗ \vec{x}^T A \vec{x} > 0 \quad \forall \vec{x} \neq \vec{0} x T A x > 0 ∀ x = 0 Tests for Positive Definiteness:
All eigenvalues > 0
All leading principal minors > 0
Cholesky decomposition exists
Can write as A = B T B A = B^TB A = B T B for invertible B B B
Quadratic Forms:
Q ( x ⃗ ) = x ⃗ T A x ⃗ = ∑ i , j A i j x i x j Q(\vec{x}) = \vec{x}^T A \vec{x} = \sum_{i,j} A_{ij} x_i x_j Q ( x ) = x T A x = i , j ∑ A ij x i x j Physical Examples:
Covariance and Statistical Matrices ¶ Covariance:
Cov ( X , Y ) = E [ ( X − μ X ) ( Y − μ Y ) ] = E [ X Y ] − E [ X ] E [ Y ] \text{Cov}(X,Y) = E[(X-\mu_X)(Y-\mu_Y)] = E[XY] - E[X]E[Y] Cov ( X , Y ) = E [( X − μ X ) ( Y − μ Y )] = E [ X Y ] − E [ X ] E [ Y ] Correlation:
ρ X Y = Cov ( X , Y ) σ X σ Y \rho_{XY} = \frac{\text{Cov}(X,Y)}{\sigma_X \sigma_Y} ρ X Y = σ X σ Y Cov ( X , Y ) Covariance Matrix:
Σ i j = Cov ( X i , X j ) \Sigma_{ij} = \text{Cov}(X_i, X_j) Σ ij = Cov ( X i , X j ) Properties:
Diagonal: Σ i i = Var ( X i ) \Sigma_{ii} = \text{Var}(X_i) Σ ii = Var ( X i )
Symmetric: Σ i j = Σ j i \Sigma_{ij} = \Sigma_{ji} Σ ij = Σ ji
Positive semi-definite: all eigenvalues ≥ 0
Sample Covariance:
Σ = 1 n − 1 ∑ i = 1 n ( x ⃗ i − x ⃗ ˉ ) ( x ⃗ i − x ⃗ ˉ ) T \Sigma = \frac{1}{n-1} \sum_{i=1}^n (\vec{x}_i - \bar{\vec{x}})(\vec{x}_i - \bar{\vec{x}})^T Σ = n − 1 1 i = 1 ∑ n ( x i − x ˉ ) ( x i − x ˉ ) T Or in matrix form:
Σ = 1 n − 1 X c T X c \Sigma = \frac{1}{n-1} X_c^T X_c Σ = n − 1 1 X c T X c where X c X_c X c is centered data matrix
Multivariate Gaussian Distribution ¶ Probability Density:
p ( x ⃗ ) = 1 ( 2 π ) n / 2 ∣ Σ ∣ 1 / 2 exp ( − 1 2 ( x ⃗ − μ ⃗ ) T Σ − 1 ( x ⃗ − μ ⃗ ) ) p(\vec{x}) = \frac{1}{(2\pi)^{n/2}|\Sigma|^{1/2}} \exp\left(-\frac{1}{2}(\vec{x}-\vec{\mu})^T\Sigma^{-1}(\vec{x}-\vec{\mu})\right) p ( x ) = ( 2 π ) n /2 ∣Σ ∣ 1/2 1 exp ( − 2 1 ( x − μ ) T Σ − 1 ( x − μ ) ) Mahalanobis Distance:
d M ( x ⃗ ) = ( x ⃗ − μ ⃗ ) T Σ − 1 ( x ⃗ − μ ⃗ ) d_M(\vec{x}) = \sqrt{(\vec{x}-\vec{\mu})^T\Sigma^{-1}(\vec{x}-\vec{\mu})} d M ( x ) = ( x − μ ) T Σ − 1 ( x − μ ) Log-likelihood (numerical stability)
log p ( x ⃗ ) = − n 2 log ( 2 π ) − 1 2 log ∣ Σ ∣ − 1 2 ( x ⃗ − μ ⃗ ) T Σ − 1 ( x ⃗ − μ ⃗ ) \log p(\vec{x}) = -\frac{n}{2}\log(2\pi) - \frac{1}{2}\log|\Sigma| - \frac{1}{2}(\vec{x}-\vec{\mu})^T\Sigma^{-1}(\vec{x}-\vec{\mu}) log p ( x ) = − 2 n log ( 2 π ) − 2 1 log ∣Σ∣ − 2 1 ( x − μ ) T Σ − 1 ( x − μ ) Matrix Decompositions ¶ Cholesky Decomposition
For positive definite A A A :
where L L L is lower triangular with positive diagonal
Applications:
Solving: A x ⃗ = b ⃗ A\vec{x} = \vec{b} A x = b via L y ⃗ = b ⃗ L\vec{y} = \vec{b} L y = b , then L T x ⃗ = y ⃗ L^T\vec{x} = \vec{y} L T x = y
Sampling: If z ⃗ ∼ N ( 0 , I ) \vec{z} \sim N(0,I) z ∼ N ( 0 , I ) , then μ ⃗ + L z ⃗ ∼ N ( μ ⃗ , Σ ) \vec{\mu} + L\vec{z} \sim N(\vec{\mu}, \Sigma) μ + L z ∼ N ( μ , Σ )
Singular Value Decomposition (SVD)
A = U Σ V T A = U\Sigma V^T A = U Σ V T Components:
U U U : Left singular vectors (orthonormal)
Σ \Sigma Σ : Singular values (diagonal, non-negative)
V T V^T V T : Right singular vectors (orthonormal)
Pseudoinverse:
A + = V Σ + U T A^+ = V\Sigma^+ U^T A + = V Σ + U T where Σ + \Sigma^+ Σ + inverts non-zero singular values
Advanced Topics ¶ Matrix Exponential
e A t = I + A t + ( A t ) 2 2 ! + ( A t ) 3 3 ! + ⋯ e^{At} = I + At + \frac{(At)^2}{2!} + \frac{(At)^3}{3!} + \cdots e A t = I + A t + 2 ! ( A t ) 2 + 3 ! ( A t ) 3 + ⋯ Solution to linear ODE:
d x ⃗ d t = A x ⃗ ⟹ x ⃗ ( t ) = e A t x ⃗ ( 0 ) \frac{d\vec{x}}{dt} = A\vec{x} \implies \vec{x}(t) = e^{At}\vec{x}(0) d t d x = A x ⟹ x ( t ) = e A t x ( 0 ) Jacobian Matrix
J i j = ∂ f i ∂ x j J_{ij} = \frac{\partial f_i}{\partial x_j} J ij = ∂ x j ∂ f i Linear approximation:
f ⃗ ( x ⃗ + δ x ⃗ ) ≈ f ⃗ ( x ⃗ ) + J δ x ⃗ \vec{f}(\vec{x} + \delta\vec{x}) \approx \vec{f}(\vec{x}) + J\delta\vec{x} f ( x + δ x ) ≈ f ( x ) + J δ x Schur Complement
For block matrix M = ( A B C D ) M = \begin{pmatrix} A & B \\ C & D \end{pmatrix} M = ( A C B D ) :
S = A − B D − 1 C S = A - BD^{-1}C S = A − B D − 1 C Matrix Norms ¶ Frobenius Norm
∣ ∣ A ∣ ∣ F = ∑ i , j ∣ a i j ∣ 2 = tr ( A T A ) ||A||_F = \sqrt{\sum_{i,j} |a_{ij}|^2} = \sqrt{\text{tr}(A^T A)} ∣∣ A ∣ ∣ F = i , j ∑ ∣ a ij ∣ 2 = tr ( A T A ) Spectral Norm
∣ ∣ A ∣ ∣ 2 = max ∣ ∣ x ⃗ ∣ ∣ = 1 ∣ ∣ A x ⃗ ∣ ∣ = σ max ||A||_2 = \max_{||\vec{x}||=1} ||A\vec{x}|| = \sigma_{\max} ∣∣ A ∣ ∣ 2 = ∣∣ x ∣∣ = 1 max ∣∣ A x ∣∣ = σ m a x Numerical Stability Patterns ¶ Safe Numerical Practices:
# Cholesky with automatic regularization
def safe_cholesky(A, jitter=1e-6):
try:
return np.linalg.cholesky(A + jitter * np.eye(len(A)))
except:
eigvals, eigvecs = np.linalg.eigh(A)
eigvals = np.maximum(eigvals, jitter)
A_fixed = eigvecs @ np.diag(eigvals) @ eigvecs.T
return np.linalg.cholesky(A_fixed)
# Work in log space
log_prob = multivariate_normal.logpdf(x, mu, Sigma)
# Stable parameterization
log_param = optimizer.param
param = np.exp(log_param) # Always positive
# Standardize data
X_std = (X - X.mean(axis=0)) / X.std(axis=0)Common Fixes:
Problem Solution Cholesky fails Add jitter: A + 1e-6 * I Not symmetric Force: (A + A.T) / 2 Ill-conditioned Regularize diagonal Probability underflow Use log space Negative eigenvalues Threshold: np.maximum(eigvals, 0)
Python/SciPy Quick Reference ¶ # Statistical
np.cov(X.T) # Covariance matrix
scipy.stats.multivariate_normal # Multivariate Gaussian
.logpdf(x, mean, cov) # Log probability
# Decompositions
np.linalg.cholesky(A) # Cholesky (A must be PD)
np.linalg.svd(A) # SVD
scipy.linalg.expm(A) # Matrix exponential
# Checks
np.linalg.eigvalsh(A).min() > 0 # Is positive definite?
np.allclose(A, A.T) # Is symmetric?
np.linalg.cond(A) # Condition number
# Solving systems
np.linalg.solve(A, b) # When A is square
np.linalg.lstsq(A, b) # Least squares
np.linalg.pinv(A) # Pseudoinverse