WOLFRAM SYSTEM MODELER
leastSquaresSolve linear equation A*x = b (exactly if possible, or otherwise in a least square sense; A may be non-square and may be rank deficient) |
SystemModel["Modelica.Math.Matrices.leastSquares"]
This information is part of the Modelica Standard Library maintained by the Modelica Association.
x = Matrices.leastSquares(A,b);
Returns a solution of equation A*x = b in a least square sense (A may be rank deficient):
minimize | A*x - b |
Several different cases can be distinguished (note, rank is an output argument of this function):
size(A,1) = size(A,2)
A solution is returned for a regular, as well as a singular matrix A:
size(A,1) > size(A,2):
The equation A*x = b has no unique solution. The solution x is selected such that |A*x - b| is as small as possible. If rank = size(A,2), this minimum norm solution is unique. If rank < size(A,2), there are an infinite number of solutions leading to the same minimum value of |A*x - b|. From these infinite number of solutions, the one with the minimum norm |x| is selected. This gives a unique solution that minimizes both |A*x - b| and |x|.
size(A,1) < size(A,2):
Note, the solution is computed with the LAPACK function "dgelsy", i.e., QR or LQ factorization of A with column pivoting.
The function first computes a QR factorization with column pivoting:
A * P = Q * [ R11 R12 ] [ 0 R22 ]
with R11 defined as the largest leading submatrix whose estimated condition number is less than 1/rcond. The order of R11, rank, is the effective rank of A.
Then, R22 is considered to be negligible, and R12 is annihilated by orthogonal transformations from the right, arriving at the complete orthogonal factorization:
A * P = Q * [ T11 0 ] * Z [ 0 0 ]
The minimum-norm solution is then
x = P * Z' [ inv(T11)*Q1'*b ] [ 0 ]
where Q1 consists of the first "rank" columns of Q.
Matrices.leastSquares2
(same as leastSquares, but with a right hand side matrix),
Matrices.solve
(for square, regular matrices A)
A |
Type: Real[:,:] Description: Matrix A |
---|---|
b |
Type: Real[size(A, 1)] Description: Vector b |
rcond |
Default Value: 100 * Modelica.Constants.eps Type: Real Description: Reciprocal condition number to estimate the rank of A |
x |
Type: Real[size(A, 2)] Description: Vector x such that min|A*x-b|^2 if size(A,1) >= size(A,2) or min|x|^2 and A*x=b, if size(A,1) < size(A,2) |
---|---|
rank |
Type: Integer Description: Rank of A |