How to find a least-squares solution using normal equations
A system can have more equations than we can satisfy at once. Least squares gives us a way to choose a solution by minimizing the total squared error. We’ll use normal equations to find that choice for three equations in two unknowns.
Write the system as a matrix equation
Use , , and . The coefficient matrix and target vector are
Make the residual perpendicular to the columns
Call the least-squares coefficient vector . We want the output closest to . The residual must be perpendicular to every column of , so . Rearranging gives the normal equations.
Solve the two normal equations
The residual is . Dotting it with either column of gives zero. The columns are independent, so this least-squares solution is unique.