Least squares approximations
When Ax=b has no exact solution, least squares chooses x̂ that minimizes ||Ax−b||. The residual is perpendicular to every column of A, giving AᵀA x̂=Aᵀb.
What you will learn
- Write a fitting problem as Ax≈b
- Solve the normal equations
- Check residuals and squared error
A two-coefficient line fit
- Fit y=c+mx to points (0,1),(1,2),(2,2). Then A=[[1,0],[1,1],[1,2]], b=(1,2,2).
- AᵀA=[[3,3],[3,5]] and Aᵀb=(5,6). Solve 3c+3m=5 and 3c+5m=6: m=1/2 and c=7/6.
- Fitted values are 7/6,5/3,13/6; residuals are −1/6,1/3,−1/6. Their sum and x-weighted sum are zero, so Aᵀr=0.
- Squared error is 1/36+1/9+1/36=1/6. Independent columns give a unique coefficient pair.
Objective 1: Write a fitting problem as Ax≈b
- What row of A represents x=2?
- [1,2], for c+2m.
Objective 2: Solve the normal equations
- Subtract the two normal equations to find m.
- 2m=1, so m=1/2 and c=7/6.
Objective 3: Check residuals and squared error
- Check both residual sums and compute the squared error.
- The sum and x-weighted sum are zero; the squared error is 1/36+1/9+1/36=1/6.
A common mistake
State the assumptions before using the formula.
Review first
Continue learning
Interactive diagnosis and practice load in the learning app. You can read these lesson notes without JavaScript.