HuntsvilleEngineers mark
HE Reference Shelf — huntsvilleengineers.com
The Reference Shelf · Linear Algebra & Numerical Methods

Sparse matrices

A matrix with so many zeros that you store and compute on only the nonzeros — the trick that lets a million-DOF FEA model solve on a workstation instead of not solving at all.

Also known as: sparse linear algebra · sparse solvers · sparse storage formats

The formula

The working definition, usually credited to Wilkinson: a matrix is sparse when it has enough zeros that it pays to take advantage of them [2][3]. Not a percentage. An economics test.

The standard storage scheme, compressed sparse row (CSR), replaces the n×n grid with three arrays [1]:

values[nnz]      the nonzero entries, row by row
col_index[nnz]   which column each one lives in
row_ptr[n+1]     where each row starts in the other two arrays

Reading: keep the numbers, keep their addresses, throw away the zeros. nnz is the nonzero count. COO format (row, column, value triplets) is the loose-parts version used while assembling; CSC is the same idea organized by columns [1].

The memory ledger, doubles with 32-bit indices:

dense:  8·n²  bytes
CSR:    12·nnz + 4·(n+1)  bytes

Reading: dense cost grows with the square of the model; sparse cost grows with the physics. A million-DOF stiffness matrix at 60 nonzeros per row is 8·(10⁶)² = 8 TB dense versus about 0.72 GB in CSR — a factor of 11,000. Verified arithmetic; the dense version does not fit on your machine, or the cluster's.

Matrix-vector product, the workhorse of every iterative solver:

y_i = Σ values[k]·x[col_index[k]]   for k = row_ptr[i] … row_ptr[i+1]−1

Reading: touch each nonzero exactly once — 2·nnz flops instead of 2·n². The catch is x[col_index[k]]: scattered memory reads make this kernel memory-bandwidth-bound, not flop-bound, on every machine you own.

Where you meet it

  • Every FEA job you've ever submitted. A stiffness matrix couples each node only to the handful of nodes sharing an element, so a hundred nonzeros per row is typical no matter how many million rows there are. The sparse-solver phase in a NASTRAN or ANSYS log — ordering, symbolic factorization, numeric factorization — is this entire page executing. When the run dies on memory, it died on fill-in, not on the matrix you gave it.

  • Circuit simulation. SPICE builds a nodal-analysis matrix where each node connects to its few attached components; the sparse LU inside, with Markowitz-style pivoting, is why a 50,000-node board netlist simulates overnight instead of never [2]. Same story in the power-flow codes that schedule the grid feeding your building — that industry invented half the field [4][7].

  • The thermal model of the avionics box on your bench. Discretize the housing into a few hundred thousand cells and Fourier's law becomes K·T = q with a sparse K. Whether the analyst clicked a button in Icepak or wrote twenty lines of scipy.sparse, the same CSR machinery is underneath.

  • At the review board, when the schedule says "mesh refinement study." Halving element size in a 3D model multiplies DOF count by roughly eight and factorization cost by far more than eight. Whether that study finishes by CDR is a sparse-linear-algebra question wearing a Gantt chart.

How it works

Assembly and arithmetic want different formats. Build in COO — element loops append (row, col, value) triplets, duplicates summing on conversion — then convert once to CSR or CSC for the solve [1]. The classic performance bug is doing it backwards: inserting entries one at a time into an already-compressed format forces an array shuffle per entry, and the assembly takes longer than the solve.

Fill-in is the whole game. Factor a sparse matrix and the elimination creates nonzeros where zeros used to be [1]. Measured on a 200×200-grid Laplacian — n = 40,000, about 5 nonzeros per row, nnz = 199,200:

LU, natural node order:   16.0 million nonzeros in the factors   (80× the original)
LU, fill-reducing order:   3.4 million                            (4.7× less, same answer)

Verified in SciPy. Nothing about the physics changed between those two lines — only the order the unknowns were eliminated. That is why every serious solver spends its first seconds on ordering: reverse Cuthill–McKee to pull entries toward the diagonal, minimum degree to eliminate lightly-connected nodes first, nested dissection to split the mesh recursively along small separators [2][8][9]. And it is why 3D models hurt more than 2D: separators through a solid are surfaces, not lines, so fill grows much faster with mesh size. The 2D intuition you calibrated on shell models will lie to you on the potted assembly.

Direct or iterative. Sparse LU or Cholesky gives you a factor you can reuse across a thousand load cases — the right call for statics, medium sizes, and anything requiring exact answers with no tuning. When fill makes factors too large, iterative methods take over: conjugate gradient for symmetric positive definite systems [11][12], GMRES for the rest [13][14], both built on nothing but the 2·nnz matrix-vector product. The fine print is preconditioning. On a plain stiffness matrix, unpreconditioned CG crawls, and conditioning worsens as the mesh refines; an incomplete factorization or multigrid preconditioner is usually the difference between 80 iterations and 8,000. Iterative solvers are not a free lunch — they are a different lunch, paid for in tuning.

The mistakes people make:

  • Computing the inverse. A⁻¹ of a sparse matrix is dense — verified on a 20×20-grid Laplacian (a 400×400 matrix): 1,920 nonzeros in the matrix, 160,000 of 160,000 nonzero in its inverse. Every inv(A)·b in a script is a request to un-sparsify the problem. Factor and solve instead; that is what the backslash does.
  • Trusting sparsity to survive arithmetic. Products like A·Aᵀ and normal-equation matrices come out much denser than their factors. Operate with the factors; never form the dense intermediate.
  • Row-slicing a CSC matrix (or column-slicing CSR) inside a loop. Each access fights the storage direction and costs a pass over the whole array. Pick the format that matches the access pattern; conversion costs one pass, once.
  • Going sparse too early. Below a few thousand unknowns, dense LAPACK with its cache-friendly kernels routinely beats sparse code and skips the bookkeeping. Wilkinson's definition cuts both ways: if it doesn't pay, it isn't sparse.

History

The field has an odd founding father. Harry Markowitz, an economist at RAND in the 1950s, hit huge mostly-zero matrices in linear programming models and worked out the elimination form of the inverse — pick each pivot to create the least fill, scoring candidates by (r−1)·(c−1), nonzeros remaining in its row times nonzeros remaining in its column [2][5]. Published in 1957, it stands as the first sparse direct method, and the term "sparse matrix" itself is plausibly his coinage [1][2]. Then he left the field. The same man had already written the 1952 portfolio-selection paper that won him the 1990 Nobel in economics [6] — diversification theory and your FEA solver's pivot rule, same author.

The engineers picked it up from there. William Tinney spent his career at the Bonneville Power Administration wrestling transmission-network equations, and his 1967 paper with John Walker introduced what became the minimum degree ordering, making large power networks solvable exactly and fast for the first time [4][7]. One footnote survives in the numerical-analysis literature: the "optimally" in their title overstated it — minimum degree is a strong heuristic for a problem later shown NP-hard, not an optimum [2]. Elizabeth Cuthill and James McKee at the Naval Ship R&D Center published the bandwidth-reducing ordering in 1969 [8]; Alan George found that simply reversing their ordering usually did better [2][8], then introduced nested dissection in 1973 — recursively cut the mesh along small separators, number the separators last — with the name suggested by Garrett Birkhoff [9][10].

The iterative line runs parallel. Magnus Hestenes and Eduard Stiefel published the conjugate gradient method in 1952 out of the National Bureau of Standards [11][12]; treated at first as a direct method that finished in n steps, it went quiet for two decades until people noticed it was the natural partner for matrices too large to factor. Yousef Saad and Martin Schultz added GMRES for nonsymmetric systems in 1986 [13][14]. Between Markowitz's pivot rule and GMRES, essentially every large simulation you have ever trusted sits on one of these two rails.

Related tools

  • /tools/beam-deflection — the one-beam closed form; the moment the geometry stops matching a handbook case, its replacement is a sparse stiffness system
  • /tools/vibration-natural-freq — the single spring–mass estimate; the full-model modal survey is a sparse generalized eigenvalue problem
  • /tools/heat-conduction — Fourier's law through one wall; discretize a real housing and the same law becomes K·T = q with a sparse K
  • /tools/parallel-resistors — nodal analysis at n = 2; SPICE's sparse conductance matrix is this calculator scaled up fifty thousand nodes

Sources

  1. https://en.wikipedia.org/wiki/Sparse_matrix
  2. https://people.engr.tamu.edu/davis/publications_files/survey_tech_report.pdf
  3. https://www.cambridge.org/core/journals/acta-numerica/article/abs/survey-of-direct-methods-for-sparse-linear-systems/8AE7AC55909389F7EA1F027855AC4044
  4. https://ieeexplore.ieee.org/document/1447941/
  5. https://www.rand.org/pubs/research_memoranda/RM1452.html
  6. https://www.nobelprize.org/prizes/economic-sciences/1990/markowitz/facts/
  7. https://www.nationalacademies.org/read/26229/chapter/56
  8. https://en.wikipedia.org/wiki/Cuthill%E2%80%93McKee_algorithm
  9. https://en.wikipedia.org/wiki/Nested_dissection
  10. https://doi.org/10.1137/0710032
  11. https://nvlpubs.nist.gov/nistpubs/jres/049/jresv49n6p409_A1b.pdf
  12. https://en.wikipedia.org/wiki/Conjugate_gradient_method
  13. https://en.wikipedia.org/wiki/Generalized_minimal_residual_method
  14. https://doi.org/10.1137/0907058

Written by HE in our own words from the cited sources — engineering judgment included, your stamp still required. All entries →

★ The Reference Shelf

Reading is free. The shelf is for cardholders.

Your library card is an email address: pin it to your shelf, print the card, take the FE/PE quick-reference pack, read the Huntsville history. The shelf remembers what you reach for.

Already on the list? Enter with your subscribed email →