Index / 001 EN
Numerical Computing with MATLAB cover

Mathematics

Mathematics

Numerical Computing with MATLAB

Cleve B. Moler

An introduction to numerical methods and technical computing by the creator of MATLAB. Each chapter explains a core algorithm, shows how it is implemented in short MATLAB programs supplied with the book, and explores its behaviour through examples and exercises. The electronic edition is offered free by MathWorks alongside the printed SIAM edition.

Prerequisites: Calculus, some familiarity with ordinary differential equations and with matrices, and some programming experience; MATLAB access is needed for the exercises.

Difficulty Level
Beginner
Academic Level
Undergraduate
numerical methodsmatlablinear systemsinterpolationdifferential equations

01 / Reading Guide

Reading Guide

Citation

Moler, C. B. (2008). Numerical Computing with MATLAB (revised reprint; electronic edition updated September 2013). Society for Industrial and Applied Mathematics. Free official edition: https://www.mathworks.com/moler/index_ncm.html

Chapter Summary

Chapter 1: Introduction to MATLAB

The first chapter teaches MATLAB through small programs that explore elementary but interesting problems: the golden ratio, Fibonacci numbers, a fractal fern produced by random affine maps, magic squares, a simple cryptography scheme and the 3n + 1 sequence. It ends with a substantial section on IEEE floating-point arithmetic—machine epsilon, roundoff, underflow and overflow—which the preface says every reader should study, whatever their MATLAB experience.

Chapter 2: Linear Equations

This chapter explains how MATLAB's backslash operator solves Ax = b by Gaussian elimination. It works through a 3-by-3 example, introduces permutation and triangular matrices and the LU factorisation, shows why partial pivoting is necessary, and analyses the effect of roundoff using norms and condition numbers. Later sections cover sparse and band matrices and use Google's PageRank to illustrate Markov chains and large sparse systems. Textbook versions of the algorithms (lutx, bslashtx) and a graphical demo accompany the text.

Chapter 3: Interpolation

Starting from the interpolating polynomial and its oscillation for many points, the chapter turns to piecewise methods: piecewise linear interpolation, piecewise cubic Hermite interpolation, the shape-preserving "pchip" interpolant and the cubic spline. It compares how the last two behave on the same data and provides textbook implementations and an interactive interpolation demo.

Chapter 4: Zeros and Roots

Bisection, Newton's method (with a deliberately perverse example where it fails), the secant method and inverse quadratic interpolation are introduced in turn and then combined into "zeroin", the robust algorithm behind MATLAB's fzero. The chapter also covers finding where a function takes a given value and closes with one-dimensional minimisation by golden-section search and parabolic interpolation (fmintx).

Chapter 5: Least Squares

Curve fitting motivates linear least squares, illustrated with U.S. census data (updated to include 2010). The chapter introduces vector norms, Householder reflections and the QR factorisation as the stable way to solve least squares problems, then discusses the pseudoinverse, rank deficiency and separable nonlinear least squares.

Chapter 6: Quadrature

The numerical evaluation of definite integrals is presented through adaptive quadrature, which concentrates function evaluations where the integrand is hard to approximate. Basic rules (midpoint, trapezoid, Simpson's) are derived and combined in a textbook adaptive routine; the chapter then discusses how to specify integrands, performance, and integrating discrete data.

Chapter 7: Ordinary Differential Equations

After setting up initial value problems and systems, the chapter studies single-step methods, develops the Bogacki–Shampine BS23 algorithm in a textbook solver (ode23tx), and works through examples including the Lorenz attractor. It explains stiffness and why stiff solvers are needed, event location, multistep methods, the family of MATLAB ODE solvers, error control and performance.

Chapter 8: Fourier Analysis

Touch-tone telephone dialing introduces the finite Fourier transform. The chapter explores it interactively, analyses sunspot data and other periodic time series, derives the fast finite Fourier transform algorithm with a textbook implementation, and relates the FFT to other Fourier transforms and series.

Chapter 9: Random Numbers

The chapter explains why computer-generated random numbers are pseudorandom, describes Lehmer's linear congruential generator and later uniform generators, and generates normally distributed numbers with Marsaglia's ziggurat algorithm. A short final section describes the Mersenne Twister algorithm used by MATLAB's uniform generator.

Chapter 10: Eigenvalues and Singular Values

Eigenvalue and singular value decompositions are introduced with small examples and interactive demonstrations (eigshow). The chapter discusses why characteristic polynomials are a poor computational route, symmetric and Hermitian matrices, the sensitivity and accuracy of computed eigenvalues and singular values, Jordan and Schur forms, and the QR algorithm. Applications include principal component analysis and a "circle generator" example.

Chapter 11: Partial Differential Equations

Limited to three model problems involving the Laplacian—the Poisson, heat and wave equations—the chapter develops finite-difference methods, their matrix representation and numerical stability conditions. It ends with the eigenvalues of the L-shaped membrane, whose first eigenfunction is the basis of the MathWorks logo.

Key Concepts

Chapter 1: Introduction to MATLAB

  • Floating-point arithmetic: computation with a finite set of binary numbers, governed by the IEEE standard.
  • Machine epsilon: the gap between 1 and the next larger floating-point number, which sets the scale of roundoff error.

Chapter 2: Linear Equations

  • LU factorisation with partial pivoting: writing a row-permuted matrix as a product of lower and upper triangular factors, the basis of the backslash operator.
  • Condition number: a measure of how much relative errors in the data can be magnified in the solution.
  • PageRank: the stationary distribution of a Markov chain defined by the link structure of the Web.

Chapter 3: Interpolation

  • Interpolating polynomial: the unique polynomial of degree less than n through n data points, which can oscillate badly.
  • Shape-preserving cubic (pchip): a piecewise cubic Hermite interpolant whose slopes are chosen to avoid overshoot.
  • Cubic spline: a piecewise cubic with continuous second derivative, smoother than pchip but able to overshoot.

Chapter 4: Zeros and Roots

  • Newton's method: iteration using the tangent line, converging quadratically near a simple root but not always globally.
  • Zeroin: a hybrid that combines bisection's reliability with the speed of the secant method and inverse quadratic interpolation.

Chapter 5: Least Squares

  • Least squares fit: choosing model parameters that minimise the sum of squared residuals.
  • QR factorisation by Householder reflections: an orthogonal factorisation that solves least squares problems stably.
  • Pseudoinverse: a generalised inverse giving the minimum-norm least squares solution, relevant when the matrix is rank deficient.

Chapter 6: Quadrature

  • Adaptive quadrature: recursively subdividing intervals until local error estimates meet a tolerance.
  • Simpson's rule: a basic rule integrating quadratics exactly, used with error estimates in adaptive schemes.

Chapter 7: Ordinary Differential Equations

  • Single-step method with error estimate: a Runge–Kutta-type method, such as BS23, that compares two orders to choose step sizes.
  • Stiffness: a property of problems with widely different time scales that forces explicit methods to take tiny steps.

Chapter 8: Fourier Analysis

  • Finite Fourier transform: a transform expressing a vector of samples as a combination of complex exponentials.
  • FFT: an algorithm computing the finite Fourier transform quickly when the length factors into small primes.

Chapter 9: Random Numbers

  • Pseudorandom generator: a deterministic algorithm whose output passes statistical tests for randomness.
  • Ziggurat algorithm: a fast method for generating normally distributed numbers using a stack of rectangles.

Chapter 10: Eigenvalues and Singular Values

  • Singular value decomposition: factorisation of any matrix into orthogonal factors and nonnegative singular values.
  • Eigenvalue sensitivity: how perturbations in a matrix affect its eigenvalues, worst for nonsymmetric matrices.
  • QR algorithm: the iterative method, based on repeated QR factorisations, used to compute eigenvalues.

Chapter 11: Partial Differential Equations

  • Finite differences: approximating derivatives on a grid, turning a PDE into a matrix problem.
  • Numerical stability condition: a restriction on the time step relative to the grid spacing for explicit schemes.

Critical Analysis

Strengths

  • Software as part of the text. The NCM collection of more than 70 M-files includes interactive graphical demonstrations and "tx" textbook versions of MATLAB's own functions (lutx, pchiptx, fzerotx, quadtx, ode23tx, ffttx and others). Reading a short, readable implementation alongside the explanation shows exactly what a built-in routine does and how to modify it.
  • Focus on informed use. The preface states that the aim is to use mathematical software correctly, understand its limitations and adapt it when needed. Chapters compare methods for accuracy and efficiency—for example, pchip against splines, or MATLAB's ODE solvers on stiff and non-stiff problems.
  • Engaging, real examples. Touch-tone dialing, sunspot cycles, census data, PageRank, the Lorenz attractor and the L-shaped membrane connect algorithms to recognisable applications.
  • Many exercises built on code. The preface mentions more than 200 exercises, many of which ask students to modify or extend NCM programs, which suits a course with regular computer work.

Limitations

  • Light on theory and proofs. Convergence results and error bounds are explained informally; there are few proofs, so the book does not replace a theoretical numerical analysis text.
  • Tied to MATLAB. Code, demos and exercises use MATLAB (some exercises also mention the Symbolic or PDE Toolbox); students using Python or other languages must translate them, and some interface details reflect the 2013 version of the software.
  • Dated in places. The latest update dates from 2013, so the discussion of MATLAB's functions, performance and some applications (for example, how PageRank is computed) reflects that time.
  • Selective coverage. The preface acknowledges that there is more than a semester of material, yet topics such as iterative methods for large linear systems, numerical optimisation beyond one dimension and finite element methods receive little or no treatment.

Applications in the Book

Applications run through every chapter: the golden ratio, Fibonacci numbers, a fractal fern, magic squares and a simple cipher (Chapter 1); PageRank and Markov chains (Chapter 2); U.S. census data fitting (Chapter 5); the Lorenz attractor and other ODE examples (Chapter 7); touch-tone dialing, sunspot periodicity and periodic time series (Chapter 8); random number generation for simulation (Chapter 9); principal component analysis and a circle-generator algorithm (Chapter 10); and heat flow, waves and the vibrating L-shaped membrane behind the MathWorks logo (Chapter 11).

Where It Fits in the Course

Moler's book sits alongside Kong, Siauw and Bayen's Python Programming and Numerical Methods. Both are software-first introductions; the Python book spends half its length teaching programming before numerical methods, while Moler assumes some programming and moves quickly to algorithms, giving more depth on how library routines work. Choose by language: Moler for MATLAB-based courses, Kong et al. for Python.

Burden, Faires and Burden's Numerical Analysis and Süli and Mayers's An Introduction to Numerical Analysis are undergraduate texts generally described as more mathematical treatments with error analysis and proofs; they are natural companions or follow-ups for students who want to understand why Moler's algorithms work. Trefethen and Bau's Numerical Linear Algebra and Stoer and Bulirsch's Introduction to Numerical Analysis are graduate-level texts; Moler's Chapters 2, 5 and 10 on LU, QR and eigenvalue algorithms are useful preparation for Trefethen and Bau.

How to Use This Book

The book is written for an introductory course in numerical methods and technical computing. The preface lists the prerequisites as calculus, some familiarity with ordinary differential equations and with matrices, and some programming experience; no previous MATLAB experience is needed.

Install the NCM files from the book's website before starting, and run each demonstration as it appears. Everyone should read Section 1.7 on floating-point arithmetic. The author suggests covering the first several chapters (linear equations, interpolation, zeros, least squares, quadrature and ODEs) and then choosing among the last four chapters (Fourier analysis, random numbers, eigenvalues, PDEs) according to interest. Work exercises that modify the "tx" programs, compare their output with MATLAB's built-in functions, and consult a more theoretical text from the course list when an error bound or convergence proof is needed.

Edition and Sources

This guide is based on the free electronic edition of Numerical Computing with MATLAB on the MathWorks website (chapter PDFs from the September 2013 update, which incorporates the 2008 revised reprint of the SIAM print edition), https://www.mathworks.com/moler/index_ncm.html. It draws on the preface (aims, prerequisites, NCM software, course advice and revision history), the introduction and every section heading of all eleven chapters, and selected sections read more closely, including floating-point arithmetic (1.7), PageRank (2.11), stiffness (7.9), the ziggurat and Twister generators (Chapter 9) and the L-shaped membrane (11.5), together with sample exercises.