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 1a: Core Linear Algebra for Computational Astrophysics

Mathematical Foundations | ASTR 596: Modeling the Universe

San Diego State University

Quick Navigation Guide

📚 Choose Your Learning Path

🏃 Fast Track

Just starting the course? Read only sections marked with 🔴

🚶 Standard Path

Preparing for projects? Read 🔴 and 🟡 sections

🧗 Complete Path

Want deep understanding? Read all sections including 🟢

  • Complete module with:

  • Historical contexts

  • Mathematical proofs

  • All worked examples

🎯 Navigation by Project Needs


Prerequisites Self-Check


Learning Objectives

By the end of this module, you will be able to:


Prerequisites Review


Module Overview

This module builds your understanding from first principles, following the progression of Projects 1-3. We start with scalars and vectors describing individual stellar properties and positions (Project 1), build to matrices transforming entire systems (Project 2), and explore how eigenvalues reveal stability and oscillation modes (Project 3). Module 0b will extend these foundations to statistical methods and machine learning.


Part 1: The Opening - A Globular Cluster as a Mathematical Universe

Priority: 🟡 Important - Provides physical context for abstract concepts

1.1 The Physical System That Motivates Everything

Consider Omega Centauri, the most massive globular cluster orbiting our galaxy. It contains approximately 10 million stars, all gravitationally bound, orbiting their common center of mass for the past 12 billion years. At its core, stellar densities reach thousands of stars per cubic parsec – if Earth orbited a star there, our night sky would blaze with thousands of stars brighter than Venus.

To simulate this cluster, we need to track for each star:

That’s 6 million numbers evolving according to Newton’s laws. The gravitational force on star ii is:

Fi=Gmijimj(rirj)rirj3\vec{F}_i = -G m_i \sum_{j \neq i} \frac{m_j (\vec{r}_i - \vec{r}_j)}{|\vec{r}_i - \vec{r}_j|^3}

Each star feels forces from all others. For N=107N = 10^7 stars (Omega Centauri’s estimated count), the number of unique pairwise interactions is N(N1)/25×1013N(N-1)/2 ≈ 5×10^{13}. That’s approximately 50 trillion unique force pair calculations per timestep! Without linear algebra, this would be impossible. With it, we can organize these calculations efficiently, identify conserved quantities, and understand the cluster’s long-term evolution.

1.2 Conservation Laws: The Hidden Structure

Priority: 🟡 Important - Fundamental for understanding physical constraints

The cluster’s apparent chaos hides profound order. Despite the complex individual stellar orbits, certain quantities never change:

Here are the updated equations with terms properly introduced at first appearance:

Total Energy:

E=i12mivi2Gi<jmimjrirjE = \sum_i \frac{1}{2} m_i |\vec{v}_i|^2 - G \sum_{i<j} \frac{m_i m_j}{|\vec{r}_i - \vec{r}_j|}

where mim_i is the mass of star ii, vi\vec{v}_i is its velocity vector, GG is the gravitational constant, and rirj|\vec{r}_i - \vec{r}_j| is the distance between stars ii and jj. The first term is the total kinetic energy and the second term is the total gravitational potential energy (summed over all unique pairs).

Total Momentum:

P=imivi\vec{P} = \sum_i m_i \vec{v}_i

This vector sum represents the net momentum of the entire cluster.

Total Angular Momentum:

L=imi(ri×vi)\vec{L} = \sum_i m_i (\vec{r}_i \times \vec{v}_i)

where ri\vec{r}_i is the position vector of star ii from the cluster center and ×\times denotes the cross product. This measures the total rotational momentum of the system.

These conservation laws aren’t accidents – they arise from fundamental symmetries of space and time. Emmy Noether proved that every continuous symmetry implies a conservation law:

SymmetryConservation LawMathematical Structure
Time translation invarianceEnergyQuadratic forms
Space translation invarianceMomentumVector addition
Rotational invarianceAngular momentumCross products, orthogonal matrices

These symmetries manifest mathematically as properties of vectors and matrices. Translation invariance means physics doesn’t change when we add the same vector to all positions. Rotational invariance means physics is preserved under orthogonal transformations.

1.3 The Phase Space Perspective

Priority: 🟡 Important - Conceptual foundation for Projects 2-6

Here’s the profound insight that changes everything: the million-star cluster isn’t really moving through 3D space. It’s tracing a trajectory through a 6-million-dimensional phase space where each axis represents one position or velocity component. The system’s entire state is a single point in this vast space, and its time evolution is a trajectory through it.

This perspective reveals hidden simplicities:


Part 2: Vectors - The Atoms of Physical Description

Priority: 🔴 Essential - Foundation for everything that follows

2.1 From Scalars to Vectors: Building Deep Understanding {#part-2-vectors}

The simplest quantities in physics are scalars – single numbers that have magnitude but no direction. Mass (2×10332×10^{33} g), temperature (5800 K), luminosity (3.8×10333.8×10^{33} erg/s), and density (1.4 g/cm³) are all scalars. They tell us “how much” but not “which way.” For many physical quantities, however, magnitude alone is insufficient – we need direction too. This is where vectors enter.

A vector is simultaneously three complementary things, and masterful computational scientists fluidly shift between these perspectives:

v=(15.225.80.0) km/s (in ecliptic coordinates)\vec{v} = \begin{pmatrix} -15.2 \\ 25.8 \\ 0.0 \end{pmatrix} \text{ km/s (in ecliptic coordinates)}

But here’s the crucial insight: these numbers are not the vector itself – they’re just one representation. The vector exists independently of any coordinate system.

2.2 Vector Spaces: The Mathematical Framework

Priority: 🟡 Important - Theoretical foundation

A vector space is a set equipped with two operations (vector addition and scalar multiplication) that satisfy eight axioms. These axioms aren’t arbitrary mathematical rules – each captures an essential physical property:

AxiomMathematical StatementPhysical Meaning
Closure under additionu+vV\vec{u} + \vec{v} \in VAdding velocities gives velocity
Commutativityu+v=v+u\vec{u} + \vec{v} = \vec{v} + \vec{u}Order of displacements doesn’t matter
Associativity(u+v)+w=u+(v+w)(\vec{u} + \vec{v}) + \vec{w} = \vec{u} + (\vec{v} + \vec{w})Grouping of forces doesn’t affect total
Zero vector0:v+0=v\exists \vec{0}: \vec{v} + \vec{0} = \vec{v}State of no motion or displacement
Additive inversev,v:v+(v)=0\forall \vec{v}, \exists -\vec{v}: \vec{v} + (-\vec{v}) = \vec{0}Every motion has an opposite
Scalar closurecvVc\vec{v} \in VScaling a force gives another force
Distributivityc(u+v)=cu+cvc(\vec{u} + \vec{v}) = c\vec{u} + c\vec{v}Scaling preserves addition
Identity1v=v1 \cdot \vec{v} = \vec{v}Multiplying by 1 changes nothing

Linear independence means vectors cannot be written as combinations of each other - they represent truly independent directions in space.

2.3 The Dot Product: Projection, Angle, and Energy

Priority: 🔴 Essential - Used constantly throughout all projects

The dot product is perhaps the most important operation in physics because it answers a fundamental question: “How much does one vector contribute in the direction of another?”

Definition and Formula:

ab=axbx+ayby+azbz=abcosθ\vec{a} \cdot \vec{b} = a_x b_x + a_y b_y + a_z b_z = |\vec{a}||\vec{b}|\cos\theta

But why are these two formulas equal? Let’s derive this connection from first principles.

Physical Applications of the Dot Product:

Work Done by a Force:

W=Fd=FdcosθW = \vec{F} \cdot \vec{d} = |\vec{F}||\vec{d}|\cos\theta

Only the component of force along the displacement does work. A force perpendicular to motion (like the normal force on a sliding block) does zero work.

Power from Solar Panels:

P=Sn^=ScosθP = \vec{S} \cdot \hat{n} = |\vec{S}|\cos\theta

where S\vec{S} is the solar flux vector and n^\hat{n} is the panel’s normal. Maximum power when facing the sun (θ=0\theta = 0), zero when edge-on (θ=90°\theta = 90°).

2.4 The Cross Product: Creating Perpendicularity

Priority: 🔴 Essential - Critical for angular momentum in Project 2

The cross product creates a vector perpendicular to two input vectors:

a×b=(aybzazbyazbxaxbzaxbyaybx)\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}

Memory Aid - The Determinant Method:

The cross product can be computed as a determinant:

a×b=i^j^k^axayazbxbybz\vec{a} \times \vec{b} = \begin{vmatrix} \hat{i} & \hat{j} & \hat{k} \\ a_x & a_y & a_z \\ b_x & b_y & b_z \end{vmatrix}

Expanding this determinant along the first row:

a×b=i^(aybzazby)j^(axbzazbx)+k^(axbyaybx)\vec{a} \times \vec{b} = \hat{i}(a_y b_z - a_z b_y) - \hat{j}(a_x b_z - a_z b_x) + \hat{k}(a_x b_y - a_y b_x)

Alternative Pattern Method:

Notice the pattern: each component uses the two coordinates that aren’t its own, and the j-component has a negative sign (this comes from the alternating signs in determinant expansion).

Geometric Intuition: To find the direction of a×b\vec{a} \times \vec{b}, use the right-hand rule: curl your right hand’s fingers from the first vector a\vec{a} toward the second vector b\vec{b} through the smaller angle. Your thumb points in the direction of the cross product. This isn’t arbitrary - it ensures consistency with our choice of right-handed coordinate systems.

Key Properties:

Physical Meaning - Angular Momentum:

For a star at position r\vec{r} with momentum p=mv\vec{p} = m\vec{v}:

L=r×p\vec{L} = \vec{r} \times \vec{p}

This vector is perpendicular to the orbital plane. Its magnitude equals twice the rate of area swept out—this is Kepler’s second law!

2.5 Orthogonality: When Vectors Don’t Talk

Priority: 🟡 Important - Essential for understanding basis vectors

Two vectors are orthogonal (perpendicular) when their dot product is zero: ab=0\vec{a} \cdot \vec{b} = 0. This isn’t just a geometric curiosity - orthogonality is why we can decompose complex systems into independent components.

Why Orthogonal Bases Are Special:

When basis vectors are orthonormal (orthogonal AND unit length), calculations become dramatically simpler:

Physical Example: In quantum mechanics, energy eigenstates are orthogonal. This means measuring one energy level doesn’t affect the probability of finding the system in another level. The orthogonality of spherical harmonics is why we can decompose the cosmic microwave background into independent multipole moments!

Astrophysical Application: When tracking stellar proper motions, observations often come in non-orthogonal coordinate systems (right ascension, declination, radial velocity). Orthogonalization creates independent velocity components where each represents truly independent motion - essential for understanding 3D stellar kinematics and discovering moving groups in the solar neighborhood.

2.6 Basis Vectors and Coordinate Systems

Priority: 🟡 Important - Needed when changing coordinate systems

A basis is a set of linearly independent vectors that span the entire space. The familiar Cartesian basis:

x^=(100),y^=(010),z^=(001)\hat{x} = \begin{pmatrix} 1 \\ 0 \\ 0 \end{pmatrix}, \quad \hat{y} = \begin{pmatrix} 0 \\ 1 \\ 0 \end{pmatrix}, \quad \hat{z} = \begin{pmatrix} 0 \\ 0 \\ 1 \end{pmatrix}

These are orthonormal: mutually perpendicular and unit length.

Any vector can be decomposed:

v=vxx^+vyy^+vzz^\vec{v} = v_x \hat{x} + v_y \hat{y} + v_z \hat{z}

The coefficients are found by projection (via the dot product):

vx=vx^,vy=vy^,vz=vz^v_x = \vec{v} \cdot \hat{x}, \quad v_y = \vec{v} \cdot \hat{y}, \quad v_z = \vec{v} \cdot \hat{z}

Progressive Problems: Vectors


Part 3: Matrices - Transformations That Preserve Structure

Priority: 🔴 Essential - Core to all computational methods

3.1 Matrices ARE Linear Transformations

You’ve mastered vectors - quantities with magnitude and direction. But what happens when you need to transform many vectors simultaneously? This is where matrices emerge naturally. A matrix isn’t just a grid of numbers - it’s a machine that transforms entire vector spaces. When you multiply a matrix by a vector, you’re asking: “Where does this vector go under this transformation?” This perspective transforms matrices from abstract number arrays into concrete geometric operations. When we multiply matrix AA by vector v\vec{v}, we get a new vector AvA\vec{v}. The crucial property is linearity:

A(αu+βv)=αAu+βAvA(α\vec{u} + β\vec{v}) = α A\vec{u} + β A\vec{v}

3.2 Building Intuition with Concrete Examples

Priority: 🔴 Essential - Recognize these patterns in your code

Let’s see actual matrices and understand what they do:

The Identity Matrix (the “do nothing” transformation):

I=(100010001)I = \begin{pmatrix} \boxed{1} & 0 & 0 \\ 0 & \boxed{1} & 0 \\ 0 & 0 & \boxed{1} \end{pmatrix}

Notice the diagonal of ones! For any vector: Iv=vI\vec{v} = \vec{v}. Visually, this leaves all vectors exactly where they are - no rotation, no scaling, no shearing.

A Rotation Matrix (30° around z-axis):

R30°=(cos(30°)sin(30°)0sin(30°)cos(30°)0001)=(3212012320001)R_{30°} = \begin{pmatrix} \cos(30°) & -\sin(30°) & 0 \\ \sin(30°) & \cos(30°) & 0 \\ 0 & 0 & 1 \end{pmatrix} = \begin{pmatrix} \frac{\sqrt{3}}{2} & -\frac{1}{2} & 0 \\ \frac{1}{2} & \frac{\sqrt{3}}{2} & 0 \\ 0 & 0 & 1 \end{pmatrix}

Note: 320.866\frac{\sqrt{3}}{2} \approx 0.866 and 12=0.5\frac{1}{2} = 0.5. The zz-component is unchanged (last row is [0, 0, 1]) because we rotate around zz. Imagine looking down the zz-axis: this matrix spins everything counterclockwise by 30° like a record player, preserving all lengths.

A Diagonal Matrix (scaling transformation):

D=(200030001)D = \begin{pmatrix} \boxed{2} & 0 & 0 \\ 0 & \boxed{3} & 0 \\ 0 & 0 & \boxed{1} \end{pmatrix}

Doubles xx, triples yy, leaves zz unchanged. Only diagonal elements are non-zero! This stretches space non-uniformly - imagine stretching a rubber sheet more in one direction than another.

A Symmetric Matrix (moment of inertia):

I=(520281016)I = \begin{pmatrix} 5 & \boxed{2} & 0 \\ \boxed{2} & 8 & \boxed{1} \\ 0 & \boxed{1} & 6 \end{pmatrix}

Notice Iij=IjiI_{ij} = I_{ji} (boxed elements show symmetry). Symmetric matrices represent reciprocal relationships - if xx affects yy, then yy affects xx equally.

The Transpose Matrix:

The transpose swaps rows and columns: (AT)ij=Aji(A^T)_{ij} = A_{ji}.

Critical for covariance matrices where Σ=ΣT\Sigma = \Sigma^T (symmetry). The transpose appears everywhere in physics:

3.3 Matrix Multiplication: Composition of Transformations

Priority: 🔴 Essential - Fundamental operation

Matrix multiplication encodes function composition. The element in row ii, column jj of product ABAB is:

(AB)ij=kAikBkj(AB)_{ij} = \sum_k A_{ik}B_{kj}

This seemingly weird formula ensures that:

(AB)v=A(Bv)(AB)\vec{v} = A(B\vec{v})

Why Order Matters:

Consider rotating 90° around x-axis, then 90° around z-axis, versus the opposite order:

Different orders give different results! This is why ABBAAB \neq BA in general.

Understanding Determinants - Three Levels:

Level 1 (Concrete): Det = 0 means “information is lost”

Level 2 (Geometric): Det measures volume scaling

Level 3 (Abstract): Det is the product of eigenvalues

3.4 The Determinant: Volume, Orientation, and Information

Priority: 🟡 Important - Helps understand singularity and numerical stability

The determinant tells us three crucial things:

det(A)\det(A)MeaningPhysical Interpretation
det(A)|\det(A)|Volume scaling factorHow much the transformation stretches/shrinks space
det(A)>0\det(A) > 0Preserves orientationRight-handed stays right-handed
det(A)<0\det(A) < 0Flips orientationRight-handed becomes left-handed
det(A)=0\det(A) = 0Singular (non-invertible)Information is lost, dimension collapses

When det(A)=0\det(A) = 0, the matrix is singular and has rank less than its dimension. Let’s understand what this really means:

Intuitive Understanding of Rank:

Physical Example: Consider measuring stellar properties:

# Columns: [mass, luminosity, log(luminosity)]
data = np.array([
    [1.0,  1.0,  0.0],
    [2.0,  8.0,  0.9],
    [0.5,  0.125, -0.9]
])

This matrix has rank 2, not 3! The third column (log luminosity) is completely determined by the second column. We’re really only measuring 2 independent quantities, not 3. The covariance matrix of this data would be singular—we can’t invert it because one dimension is redundant.

Geometric Interpretation:

Specifically, an n×nn \times n matrix with rank r<nr < n maps nn-dimensional space onto an rr-dimensional subspace, losing (nr)(n-r) dimensions of information.

For a 2×2 matrix:

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

Geometric interpretation: For 2×2 matrices, the determinant equals the (signed) area of the parallelogram formed by the column vectors. For 3×3 matrices, it’s the (signed) volume of the parallelepiped.

For a 3×3 matrix, the determinant can be computed by cofactor expansion along any row or column. The pattern extends to larger matrices, though computation becomes expensive (O(n!)O(n!) operations).

3.5 The Inverse: Undoing Transformations

Priority: 🟡 Important - Critical for solving systems

The inverse matrix A1A^{-1} satisfies:

A1A=AA1=IA^{-1}A = AA^{-1} = I

For a 2×2 matrix:

A=(abcd)    A1=1det(A)(dbca)A = \begin{pmatrix} a & b \\ c & d \end{pmatrix} \implies A^{-1} = \frac{1}{\det(A)}\begin{pmatrix} d & -b \\ -c & a \end{pmatrix}

Notice you divide by the determinant – this is why singular matrices (det = 0) have no inverse!

Bridge to Module 0b: These matrix operations become statistical in Module 0b, where ATAA^T A creates covariance matrices encoding correlations. The transpose operation you learned here will be essential for understanding how data matrices generate covariance structures.

Progressive Problems: Matrices


Part 4: Eigenvalues and Eigenvectors - Finding Invariant Structure

Priority: 🟡 Important - Critical for stability analysis and convergence

4.1 The Eigenvalue Equation: Directions That Don’t Rotate {#part-4-eigenvalues}

Some special vectors are only scaled by a transformation:

Av=λvA\vec{v} = \lambda\vec{v}

These eigenvectors v\vec{v} and their eigenvalues λ\lambda reveal fundamental structure.

Geometric Intuition: Imagine stretching a rubber sheet. Most directions get rotated as the sheet deforms, but along eigenvector directions, points only move closer to or farther from the origin without changing direction. These are the “natural axes” of the transformation.

Physical Example - Spinning Objects:

Consider a football. It has three principal axes:

The principal axes are eigenvectors of the moment of inertia tensor.

4.2 Finding Eigenvalues: The Characteristic Equation

To find eigenvalues:

  1. Rearrange: (AλI)v=0(A - \lambda I)\vec{v} = \vec{0}

  2. For non-trivial solutions: det(AλI)=0\det(A - \lambda I) = 0

  3. This gives the characteristic equation

For an n×nn×n matrix, the characteristic polynomial has degree nn, potentially yielding nn eigenvalues (counting multiplicity) in the complex numbers. The trace (sum of diagonal elements) equals the sum of eigenvalues.

4.3 Physical Meaning Throughout Your Projects

Physical Intuition: Why eigenvalues determine stability

Consider a star cluster near equilibrium. Small perturbations evolve as:

δx(t)=eλtv\delta x(t) = e^{\lambda t} v

The largest eigenvalue determines the fate: even one positive eigenvalue means the system will eventually fly apart!

For instance, a 2D rotation matrix has eigenvalues e±iθe^{±iθ}, where the imaginary unit explicitly encodes the rotation angle θθ. This shows how complex eigenvalues naturally describe oscillatory behavior in physical systems.

Eigenvalues appear in most projects in this course:

ProjectWhere Eigenvalues AppearWhat They Tell You
Project 2Linearized dynamics near equilibriumOrbital stability (stable if all λ<0\lambda < 0)
Project 3Scattering matrixPreferred scattering directions
Project 4MCMC transition matrixConvergence rate: 1/1λ2\sim 1/|1-\lambda_2| where λ2\lambda_2 is the second-largest eigenvalue by absolute value (with λ2<1|\lambda_2| < 1)
Project 5GP kernel matrixEffective degrees of freedom
Final ProjectNeural network HessianOptimization landscape curvature

Progressive Problems: Eigenvalues


Part 5: Numerical Reality - When Mathematics Meets Silicon (Essential Sections)

Priority: 🔴 Essential - Critical for debugging all projects

7.1 The Harsh Truth About Floating-Point Arithmetic

Computers can’t store infinite decimals, so they approximate real numbers using a finite representation:

x=±m×2ex = \pm m \times 2^e

where mm is the mantissa (fractional part) and ee is the exponent. Think of it as scientific notation in binary.

What This Means for 64-bit Doubles:

The Shocking Truth About 0.1:

0.1 + 0.2 == 0.3  # False!
print(f"{0.1 + 0.2:.17f}")  # 0.30000000000000004

# Why? 0.1 in binary is actually:
# 0.00011001100110011001100110011... (repeating forever!)
# The computer truncates this at 53 bits, creating rounding error

Just like 1/3 = 0.333... repeats forever in decimal, 1/10 repeats forever in binary. The computer must truncate, introducing tiny errors that compound.

Catastrophic Cancellation - The Silent Killer:

When you subtract nearly equal numbers, you lose precision catastrophically. Here’s why:

# Example: Computing small angles in astronomy
star_position_1 = 89.99999999  # degrees (16 digits total)
star_position_2 = 90.00000001  # degrees (16 digits total)

angle_difference = star_position_2 - star_position_1
# Result: 0.00000002 (only 1 significant digit!)
# We went from 16 digits of precision to 1!

# Better approach: Reformulate to avoid subtraction
# Instead of (A + small) - A, compute small directly

Real Project 2 Example - Gravitational Forces:

# BAD: Force between very close stars
def gravitational_force_bad(pos1, pos2, m1, m2):
    dx = pos2[0] - pos1[0]  # Catastrophic if positions nearly equal!
    dy = pos2[1] - pos1[1]
    dz = pos2[2] - pos1[2]
    r_squared = dx**2 + dy**2 + dz**2  # Can become 0 or negative!
    return G * m1 * m2 / r_squared  # Division by ~0!

# GOOD: With softening parameter (regularization)
def gravitational_force_good(pos1, pos2, m1, m2, epsilon=1e-4):
    dx = pos2[0] - pos1[0]
    dy = pos2[1] - pos1[1]
    dz = pos2[2] - pos1[2]
    r_squared = dx**2 + dy**2 + dz**2 + epsilon**2  # Never zero!
    return G * m1 * m2 / r_squared

7.2 Condition Numbers: Measuring Numerical Danger

The condition number tells you how much input errors get amplified:

δxxκ(A)δbb\frac{||\delta x||}{||x||} \leq \kappa(A) \frac{||\delta b||}{||b||}

This means: relative error in solution ≤ condition number × relative error in input.

Intuitive Understanding:

κ(A)InterpretationWhat It Means for You
< 10ExcellentTrust your results
10-100GoodMinor accuracy loss
100-1000AcceptableCheck residuals
10^3-10^6ProblematicNeed careful algorithms
> 10^6DangerousConsider reformulation
> 10^10Numerically singularAdd regularization
≈ 10^16Complete failureMatrix is effectively rank-deficient

Real Example - Why Your Stellar Population Fits Fail:

# Fitting mass-luminosity relation: L = a*M^b
# Taking logs: log(L) = log(a) + b*log(M)

# Design matrix for 3 stars with similar masses
M = np.array([0.99, 1.00, 1.01])  # Solar masses
X = np.column_stack([np.ones(3), np.log(M)])

# Check condition number
print(f"Condition number: {np.linalg.cond(X):.1e}")
# Output: 4.5e+03 (problematic!)

# Why? The log(M) values are nearly identical!
# log(0.99) ≈ -0.0101, log(1.00) = 0, log(1.01) ≈ 0.0100
# The columns are nearly parallel → high condition number

# Fix: Use centered/scaled variables
M_scaled = (M - M.mean()) / M.std()
X_better = np.column_stack([np.ones(3), M_scaled])
print(f"Better condition number: {np.linalg.cond(X_better):.1e}")
# Output: 2.4e+00 (excellent!)

Emergency Debugging Checklist


Essential SciPy Linear Algebra Reference {#essential-scipy-reference}

Priority: 🔴 Essential - Keep this open while coding

Quick Function Reference

Task

Function

When to Use

Numerical Stability

Solve Ax=bA\vec{x}=\vec{b}

scipy.linalg.solve(A, b)

General square systems

⭐⭐⭐⭐

Solve positive definite

scipy.linalg.cho_solve()

Covariance matrices

⭐⭐⭐⭐⭐

Least squares

scipy.linalg.lstsq()

Overdetermined systems

⭐⭐⭐⭐⭐

Eigenvalues (general)

scipy.linalg.eig()

Non-symmetric matrices

⭐⭐⭐

Eigenvalues (symmetric)

scipy.linalg.eigh()

Symmetric/Hermitian

⭐⭐⭐⭐⭐

SVD

scipy.linalg.svd()

Any matrix, rank

⭐⭐⭐⭐⭐

Matrix exponential

scipy.linalg.expm()

Time evolution

⭐⭐⭐⭐

Condition number

numpy.linalg.cond()

Check stability

N/A


One-Page Cheat Sheet


Glossary of Terms

All terms introduced in this module:


Main Takeaways


Essential NumPy/SciPy Reference for Module 0a

Priority: 🔴 Essential - Keep this open while coding Projects 1-3

Core Linear Algebra Functions

Task

Function

When to Use

Project

Dot product

np.dot(a, b) or a @ b

Work, projections

All

Cross product

np.cross(a, b)

Angular momentum

P2

Matrix multiply

A @ B or np.matmul(A, B)

Transformations

All

Solve Ax=b

np.linalg.solve(A, b)

Linear systems

P2-3

Eigenvalues

np.linalg.eig(A)

Stability analysis

P2

Determinant

np.linalg.det(A)

Check invertibility

P2-3

Matrix norm

np.linalg.norm(A)

Error estimates

All

Inverse (avoid!)

np.linalg.inv(A)

Use solve() instead


Module 0a Quick Reference Card

Next Steps

With this mathematical foundation firmly in place, you’re ready to tackle the computational challenges of modern astrophysics. In Project 1, you’ll immediately apply vector operations and matrix manipulations to handle stellar populations efficiently. In Project 2, you’ll see how eigenvalues determine orbital stability.

Module 0b continues with positive definite matrices, advanced topics, and the bridge to machine learning. Together, these modules provide the complete linear algebra foundation for computational astrophysics.

Remember: every algorithm you implement ultimately reduces to linear algebra. When numerical issues arise – and they will – return to these foundations. Check condition numbers, verify matrix properties, use appropriate decompositions. The mathematics you’ve learned here isn’t separate from computation – it IS computation in its purest form.


Welcome to computational astrophysics. You now speak its language.