Back to Linear Algebra
lstsq
Least-squares solution to linear equation
Syntax
x = lstsq(A, b) [x, residuals, rank, s] = lstsq(A, b)
Description
Computes the least-squares solution to the equation A*x = b. Returns the solution that minimizes ||A*x - b||. With one output, returns the solution vector x. With four outputs, also returns residuals, rank, and singular values.
Parameters
| Name | Description |
|---|---|
| A | Coefficient matrix (m×n) |
| b | Ordinate values (m×1) or (m×k) |
Returns
Solution vector x, or [x, residuals, rank, s]