Trefethen NLA in C++

Trefethen NLA in C++

Reference: Lloyd N. Trefethen and David Bau III, Numerical Linear Algebra, SIAM, 1997 / 25th Anniversary Edition, 2022.

Sources: Author’s book page · SIAM 25th Anniversary Edition

This study series follows the book’s 40 lectures, develops the mathematical arguments, and explores their numerical meaning through C++20/Eigen computations. Book content and personal implementation extensions are identified separately. Lecture 09 covers MATLAB in the book; its C++/Eigen adaptation is a personal extension.

Study roadmap · Linear Algebra Review · Saad Study

Writing workflow

  1. Review the lecture’s goals, prerequisites, and guiding questions.
  2. Fix assumptions and notation, then derive the main results.
  3. Develop examples, implementations, or comparisons according to the study focus below.
  4. Record actual results and open questions, then update the note’s status.
Study focusMain deliverable
Theory and derivationDefinitions, results, derivations, small examples, and limits of the assumptions. A new solver is optional
Algorithm and implementationUpdates, costs, API, failure handling, tests, and reproducible experiments
Comparison and experimentControlled comparisons, reference values, metrics, observations, and interpretation

Prerequisite links identify needed background; the Previous/Next links at the end of each note describe reading order. An empty outline is a plan, not a completed argument. Include key equations and usage examples in the blog, with links to actual source files and commits. Function and file names below are implementation plans. Add the code repository URL and implementation status after verifying them.

Shared notation and reproduction records

  • $A^*$ denotes the conjugate transpose, which equals the transpose for real matrices. State matrix and vector dimensions first.
  • Distinguish vector norms, induced matrix norms, and the Frobenius norm.
  • Distinguish exact-arithmetic results, problem conditioning, and algorithm stability.
  • State the denominators in relative errors and normalized residuals, including how zeros are handled.
  • Record the code commit, compiler/Eigen versions, scalar type, build flags, input generation method, size, seed, relevant tolerances, commands, and raw output.
  • For timings, state how measurements are repeated and whether setup costs are included. Omit irrelevant items with a brief explanation.

New notes and status

Use templates/trefethen-lecture.md in the repository for a new note. Files for Lectures 01–40 already exist, so develop the existing file for each lecture. Check the title, date, series_order, and permalink, and preserve existing URLs. Keep published: false while writing. When the note is ready to publish, set status: note and published: true.

  • status: outline: a reading or writing plan.
  • status: working-note: a note with content and derivations in progress.
  • status: note: a note whose assumptions, derivations, examples, and necessary checks have been reviewed.

Outlines and working notes remain in the repository while the blog lists published notes. Reading-plan titles link to a lecture once that individual post is published. Changing this index page’s status does not publish the lectures.

Linear Algebra Review → Trefethen Part I–V → Trefethen Part VI → Saad Study

I — Fundamentals

LLectureFocusC++ verification / implementation plan
01Matrix-Vector MultiplicationAlgorithm and implementationnla::matvec_by_columns in fundamentals.*
02Orthogonal Vectors and MatricesTheory and derivationnla::orthogonality_error and a unitary-invariance experiment
03NormsTheory and derivationplanned norm helpers in fundamentals.*
04The Singular Value DecompositionTheory and derivationexperiments/l04_svd_geometry.cpp
05More on the SVDTheory and derivationnla::truncated_svd in fundamentals.*

II — QR Factorization and Least Squares

LLectureFocusC++ verification / implementation plan
06ProjectorsTheory and derivationnla::orthogonal_projector in qr.*
07QR FactorizationTheory and derivationnla::QrFactorization validation experiment
08Gram-Schmidt OrthogonalizationAlgorithm and implementationnla::classical_gram_schmidt and nla::modified_gram_schmidt
09MATLABComparison and experimentexperiments/l09_eigen_primer.cpp
10Householder TriangularizationAlgorithm and implementationnla::householder_qr in qr.*
11Least Squares ProblemsAlgorithm and implementationnla::least_squares_qr in qr.*

III — Conditioning and Stability

LLectureFocusC++ verification / implementation plan
12Conditioning and Condition NumbersTheory and derivationnla::condition_number_2 in stability.*
13Floating Point ArithmeticComparison and experimentexperiments/l13_floating_point.cpp
14StabilityTheory and derivationnla::linear_system_backward_error in stability.*
15More on StabilityTheory and derivationexperiments/l15_stability_composition.cpp
16Stability of Householder TriangularizationComparison and experimentHouseholder QR diagnostics in experiments/l16_householder_stability.cpp
17Stability of Back SubstitutionAlgorithm and implementationnla::back_substitution in systems.*
18Conditioning of Least Squares ProblemsTheory and derivationexperiments/l18_least_squares_conditioning.cpp
19Stability of Least Squares AlgorithmsComparison and experimentexperiments/l19_least_squares_solvers.cpp

IV — Systems of Equations

LLectureFocusC++ verification / implementation plan
20Gaussian EliminationAlgorithm and implementationnla::lu_factor in systems.*
21PivotingAlgorithm and implementationnla::lu_factor_partial_pivoting in systems.*
22Stability of Gaussian EliminationComparison and experimentgrowth-factor diagnostics in experiments/l22_growth_factor.cpp
23Cholesky FactorizationAlgorithm and implementationnla::cholesky in systems.*

V — Eigenvalues

LLectureFocusC++ verification / implementation plan
24Eigenvalue ProblemsTheory and derivationexperiments/l24_eigenvalue_conditioning.cpp
25Overview of Eigenvalue AlgorithmsTheory and derivationPersonal extension: nla::power_iteration in eigenvalues.*
26Reduction to Hessenberg or Tridiagonal FormAlgorithm and implementationnla::hessenberg_reduction in eigenvalues.*
27Rayleigh Quotient, Inverse IterationAlgorithm and implementationnla::inverse_iteration and nla::rayleigh_quotient_iteration
28QR Algorithm without ShiftsAlgorithm and implementationnla::qr_algorithm(..., false) in eigenvalues.*
29QR Algorithm with ShiftsAlgorithm and implementationnla::qr_algorithm(..., true) with shift and deflation
30Other Eigenvalue AlgorithmsTheory and derivationOptional extension: compare one method in experiments/l30_other_eigensolver.cpp
31Computing the SVDAlgorithm and implementationBidiagonalization in eigenvalues.*; a complete SVD solver is optional

VI — Iterative Methods

LLectureFocusC++ verification / implementation plan
32Overview of Iterative MethodsComparison and experimentnla::LinearOperator and experiments/l32_matrix_free.cpp
33The Arnoldi IterationAlgorithm and implementationnla::arnoldi in iterative.*
34How Arnoldi Locates EigenvaluesTheory and derivationexperiments/l34_ritz_values.cpp
35GMRESAlgorithm and implementationnla::gmres in iterative.*
36The Lanczos IterationAlgorithm and implementationnla::lanczos in iterative.*
37From Lanczos to Gauss QuadratureTheory and derivationexperiments/l37_gauss_quadrature.cpp
38Conjugate GradientsAlgorithm and implementationnla::conjugate_gradient in iterative.*
39Biorthogonalization MethodsAlgorithm and implementationBi-Lanczos in iterative.*; BiCG is an optional extension
40PreconditioningAlgorithm and implementationnla::preconditioned_cg in iterative.*

Next actions

  • Derive the column expansion in Lecture 01 — Matrix-Vector Multiplication and work through a small example by hand.
  • Implement matvec_by_columns and compare its results with Eigen.
  • Record the actual code repository URL, commit, environment, commands, and results in the first note.