Skip to main content

What is a residual, and why should a numerical answer be checked?

A numerical output should be compared with the original mathematical conditions.

Programming & Scientific ComputingIntermediate

Learning goal

Understand residuals for linear systems and their role in checking numerical solutions.

Prerequisites

  • Basic linear algebra
  • Basic norm notation

Residual

For Ax=b and an approximate solution x̂, the residual measures what remains when x̂ is substituted into the equation.

Residual
r=b−Ax^

Measuring the residual

Residual norm
∥r∥2=∥b−Ax^∥2

A smaller norm means the computed result satisfies that equation more closely. In numerical work, scaling and conditioning also matter.

Connection to optimization

For a constrained solver, the objective value is not enough. Stationarity, primal feasibility, complementarity, and duality gap provide independent checks of solve quality.

Simple example

Linear-system example
A=\begin{bmatrix}1&1\\2&-1\end{bmatrix},\quad b=\begin{bmatrix}3\\0\end{bmatrix},\quad \hat{x}=\begin{bmatrix}1\\2\end{bmatrix}

Here A x̂=[3,0], so the residual is zero. The transferable habit is to check the computed answer against the original equation.

Related project

Convex QP Solver

The project exposes numerical diagnostics for checking KKT-related conditions.

Open source

Have a numerical problem?

We can define mathematical and numerical checks for the output.