Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Module 1c: Linear Algebra Formula Sheet

Mathematical Foundations | COMP 521

San Diego State University

Module 0a Quick Formula Sheet

Essential Vector Operations

Dot Product:

a⃗⋅b⃗=axbx+ayby+azbz=∣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

Physical Applications:

Cross Product:

a⃗×b⃗=(aybz−azbyazbx−axbzaxby−aybx)\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}

Magnitude: ∣a⃗×b⃗∣=∣a⃗∣∣b⃗∣sin⁡θ|\vec{a} \times \vec{b}| = |\vec{a}||\vec{b}|\sin\theta

Physical Applications:

Vector Norms and Properties:

Essential Matrix Operations

Basic Operations:

Determinant:

2×2 Matrix:

det⁡(abcd)=ad−bc\det\begin{pmatrix} a & b \\ c & d \end{pmatrix} = ad - bc

Properties:

Matrix Inverse:

2×2 Matrix:

(abcd)−1=1ad−bc(d−b−ca)\begin{pmatrix} a & b \\ c & d \end{pmatrix}^{-1} = \frac{1}{ad-bc}\begin{pmatrix} d & -b \\ -c & a \end{pmatrix}

General Properties:

Eigenvalues and Eigenvectors

Definition:

Av⃗=λv⃗A\vec{v} = \lambda\vec{v}

Characteristic Equation:

det⁡(A−λI)=0\det(A - \lambda I) = 0

Properties:

Numerical Stability Quick Checks

Condition Number

κ(A)=∣∣A∣∣⋅∣∣A−1∣∣=σmax⁡σmin⁡\kappa(A) = ||A|| \cdot ||A^{-1}|| = \frac{\sigma_{\max}}{\sigma_{\min}}

Interpretation:

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       # Regularization

Module 0b Quick Formula Sheet

Positive Definite Matrices

Definition A symmetric matrix AA is positive definite if:

x⃗TAx⃗>0∀x⃗≠0⃗\vec{x}^T A \vec{x} > 0 \quad \forall \vec{x} \neq \vec{0}

Tests for Positive Definiteness:

  1. All eigenvalues > 0

  2. All leading principal minors > 0

  3. Cholesky decomposition exists

  4. Can write as A=BTBA = B^TB for invertible BB

Quadratic Forms:

Q(x⃗)=x⃗TAx⃗=∑i,jAijxixjQ(\vec{x}) = \vec{x}^T A \vec{x} = \sum_{i,j} A_{ij} x_i x_j

Physical Examples:

Covariance and Statistical Matrices

Covariance:

Cov(X,Y)=E[(X−μX)(Y−μY)]=E[XY]−E[X]E[Y]\text{Cov}(X,Y) = E[(X-\mu_X)(Y-\mu_Y)] = E[XY] - E[X]E[Y]

Correlation:

ρXY=Cov(X,Y)σXσY\rho_{XY} = \frac{\text{Cov}(X,Y)}{\sigma_X \sigma_Y}

Covariance Matrix:

Σij=Cov(Xi,Xj)\Sigma_{ij} = \text{Cov}(X_i, X_j)

Properties:

Sample Covariance:

Σ=1n−1∑i=1n(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

Or in matrix form:

Σ=1n−1XcTXc\Sigma = \frac{1}{n-1} X_c^T X_c

where XcX_c is centered data matrix

Multivariate Gaussian Distribution

Probability Density:

p(x⃗)=1(2π)n/2∣Σ∣1/2exp⁡(−12(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)

Mahalanobis Distance:

dM(x⃗)=(x⃗−μ⃗)TΣ−1(x⃗−μ⃗)d_M(\vec{x}) = \sqrt{(\vec{x}-\vec{\mu})^T\Sigma^{-1}(\vec{x}-\vec{\mu})}

Log-likelihood (numerical stability)

log⁡p(x⃗)=−n2log⁡(2π)−12log⁡∣Σ∣−12(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})

Matrix Decompositions

Cholesky Decomposition For positive definite AA:

A=LLTA = LL^T

where LL is lower triangular with positive diagonal

Applications:

Singular Value Decomposition (SVD)

A=UΣVTA = U\Sigma V^T

Components:

Pseudoinverse:

A+=VΣ+UTA^+ = V\Sigma^+ U^T

where Σ+\Sigma^+ inverts non-zero singular values

Advanced Topics

Matrix Exponential

eAt=I+At+(At)22!+(At)33!+⋯e^{At} = I + At + \frac{(At)^2}{2!} + \frac{(At)^3}{3!} + \cdots

Solution to linear ODE:

dx⃗dt=Ax⃗  ⟹  x⃗(t)=eAtx⃗(0)\frac{d\vec{x}}{dt} = A\vec{x} \implies \vec{x}(t) = e^{At}\vec{x}(0)

Jacobian Matrix

Jij=∂fi∂xjJ_{ij} = \frac{\partial f_i}{\partial x_j}

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}

Schur Complement For block matrix M=(ABCD)M = \begin{pmatrix} A & B \\ C & D \end{pmatrix}:

S=A−BD−1CS = A - BD^{-1}C

Matrix Norms

Frobenius Norm

∣∣A∣∣F=∑i,j∣aij∣2=tr(ATA)||A||_F = \sqrt{\sum_{i,j} |a_{ij}|^2} = \sqrt{\text{tr}(A^T A)}

Spectral Norm

∣∣A∣∣2=max⁡∣∣x⃗∣∣=1∣∣Ax⃗∣∣=σmax⁡||A||_2 = \max_{||\vec{x}||=1} ||A\vec{x}|| = \sigma_{\max}

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:

ProblemSolution
Cholesky failsAdd jitter: A + 1e-6 * I
Not symmetricForce: (A + A.T) / 2
Ill-conditionedRegularize diagonal
Probability underflowUse log space
Negative eigenvaluesThreshold: 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