functionleastSquares
Solve overdetermined or underdetermined real system of linear equations A*x=b in a least squares sense (A may be rank deficient)
Extends from Modelica.Icons.Function (Icon for functions).
Information
Syntax
x = Matrices.leastSquares(A,b);
Description
A linear system of equations A*x = b has no solutions or infinitely many solutions if A is not square. Function "leastSquares" returns a solution in a least squarse sense:
size(A,1) > size(A,2): returns x such that |A*x - b|^2 is a minimum
size(A,1) = size(A,2): returns x such that A*x = b
size(A,1) < size(A,2): returns x such that |x|^2 is a minimum for all
vectors x that fulfill A*x = b
Note
The solution is computed with the LAPACK function "dgelsx", i.e., QR or LQ factorization of A with column pivoting. If A does not have full rank, the solution is not unique and from the infinitely many solutions the one is selected that minimizes both |x|^2 and |A*x - b|^2.
Inputs
| Type | Name | Default | Description |
|---|---|---|---|
| Real[:,:] | A | Matrix A | |
| Real[size(A, 1)] | b | Vector b |
Outputs
| Type | Name | Default | Description |
|---|---|---|---|
| Real[size(A, 2)] | x | 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) |