finds an x that solves the linear least-squares problem for the matrix equation m.x==b.
Details and Options
- LeastSquares[m,b] gives a vector x that minimizes Norm[m.x-b].
- The vector x is uniquely determined by the minimization only if Length[x]==MatrixRank[m].
- The argument b can be a matrix, in which case the least-squares minimization is done independently for each column in b, which is the x that minimizes Norm[m.x-b,"Frobenius"].
- LeastSquares works on both numerical and symbolic matrices, as well as SparseArray objects.
- A Method option can also be given. Settings for arbitrary-precision numerical matrices include "Direct" and "IterativeRefinement", and for sparse arrays "Direct" and "Krylov". The default setting of Automatic switches between these methods, depending on the matrix given.
Examplesopen allclose all
Generalizations & Extensions (1)
With Tolerance->0, numerical roundoff can introduce excessive error:
Properties & Relations (6)
LeastSquares gives the parameter estimates for a linear model with normal errors:
LinearModelFit fits the model and gives additional information about the fitting:
Wolfram Research (2007), LeastSquares, Wolfram Language function, https://reference.wolfram.com/language/ref/LeastSquares.html.
Wolfram Language. 2007. "LeastSquares." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/LeastSquares.html.
Wolfram Language. (2007). LeastSquares. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/LeastSquares.html