If A
is of full rank, i.e. the columns of A
are linearly independent, the least-squares solution of an overdetermined system of linear equations
A * x = b
can be found by inverting the normal equations (see Linear Least Squares):
x = inv(A' * A) * A' * b
If A
is not of full rank, A' * A
is not invertible. Instead, one can use the pseudoinverse of A
x = pinv(A) * b
or Matlab's left-division operator
x = A b
Both give the same solution, but the left division is more computationally efficient.
The two latter computation methods can also deal with underdetermined systems of linear equations, but they give different solutions in that case: The pseudoinverse gives the solution where x
has the smallest sum of squares, while the left-division operator gives a solution with as many 0 coefficients as possible.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…