Foundations: Algorithms, Approximation & Error

a numerical algorithm

An algorithm is a finite list of well-defined steps that turns an input into an output — like a recipe a machine can follow with no judgement of its own. A numerical algorithm is one whose inputs and outputs are numbers (or arrays of numbers) and whose job is to compute an approximate answer to a mathematical problem: solve A x = b, find a root of f, integrate a function, fit a curve.

Three things make a procedure a genuine algorithm. It must be finite: it has to stop after a definite number of steps (an iterative method needs a stopping rule, or it is not an algorithm). It must be well-defined: every step is unambiguous given the current data, so two people running it by hand get the same result. And it must have a clear input-output contract: state exactly what it consumes (a matrix, a tolerance, an initial guess) and what it promises to return (a solution, an estimate, an error flag). For example, bisection takes a continuous f, a bracket [a, b] with f(a) and f(b) of opposite signs, and a tolerance; it repeatedly halves the bracket and returns a point within the tolerance of a root.

The same mathematical problem usually has many algorithms, and they are not equally good. They differ in accuracy (how close the result is), in cost (how the work and memory grow with problem size, often written O(n^2) or O(n^3)), and in stability (whether rounding and small input errors get amplified). Choosing well means weighing all three; the fastest method is useless if it is unstable, and the most accurate is useless if it never finishes.

Gaussian elimination is a numerical algorithm: input a matrix A and vector b; eliminate unknowns row by row to reach a triangular system; back-substitute; output x solving A x = b, at a cost of about O(n^3) operations for an n-by-n system.

A clear input, a finite sequence of unambiguous steps, a defined output, and a known cost — the four marks of an algorithm.

Pseudocode that loops forever (no stopping criterion) is not an algorithm. An iterative method becomes one only once you pin down when to stop.

Also called
numerical methodnumerical procedure數值方法演算法