The orthogonal projection of onto a subspace is the point of closest to . With an orthogonal basis it is a sum of one-line projections, and the leftover is perpendicular to .
| Step | On , | |
|---|---|---|
| 1 | Check that the basis is orthogonal. If , switch to the normal equations or orthogonalize first. | ✓ |
| 2 | Compute one coefficient per basis vector. Each coefficient is . | and |
| 3 | Add the scaled basis vectors. The sum is the projection , a point of . | |
| 4 | Check the residual. The leftover must be orthogonal to every basis vector. Its length is the distance from to . | , , distance |