|
|
◆ dgels()
| function dgels |
( |
trans::Char |
, |
|
|
m::Integer |
, |
|
|
n::Integer |
, |
|
|
a::Array{Float64} |
, |
|
|
b::Array{Float64} |
, |
|
|
nrhs::Integer |
= 1 |
|
) |
| |
Solution to overdetermined or underdetermined linear equations Ax = b (full rank)
- Purpose
- dgels solves overdetermined or underdetermined real linear systems involving an m x n matrix A, or its transpose, using a QR or LQ factorization of A. It is assumed that A has full rank.
The following options are provided:
- If trans = 'N' and m >= n: find the least squares solution of an overdetermined system, i.e., solve the least squares problem
- If trans = 'N' and m < n: find the minimum norm solution of an underdetermined system A * X = B.
- If trans = 'T' and m >= n: find the minimum norm solution of an underdetermined system A^T * X = B.
- If trans = 'T' and m < n: find the least squares solution of an overdetermined system, i.e., solve the least squares problem
minimize || B - A^T*X ||.
Several right hand side vectors b and solution vectors x can be handled in a single call; they are stored as the columns of the m x nrhs right hand side matrix B and the n x nrhs solution matrix X.
- Returns
- info (Int32)
= 0: Successful exit
= -1: The argument trans had an illegal value (trans != 'T' nor 'N')
= -2: The argument m had an illegal value (m < 0)
= -3: The argument n had an illegal value (n < 0)
= -4: The argument a is invalid.
= -5: The argument b is invalid.
= -6: The argument nrhs had an illegal value (nrhs < 0)
= i > 0: The i-th diagonal element of the triangular factor of A is zero, so that A does not have full rank. The least squares solution could not be computed.
- Parameters
-
| [in] | trans | = 'N': The linear system involves A.
= 'T': The linear system involves A^T. |
| [in] | m | Number of rows of the matrix A. (m >= 0) (If m = 0, returns zero vectors in b) |
| [in] | n | Number of columns of the matrix A. (n >= 0) (If n = 0, returns zero vectors in b) |
| [in,out] | a | 2-dimensional array (Float64, m x n)
[in] m x n matrix A.
[out] m >= n: a is overwritten by details of its QR factorization as returned by dgeqrf.
m < n: a is overwritten by details of its LQ factorization as returned by dgelqf. |
| [in,out] | b[][] | 1 or 2-dimensional array (Float64, max(m, n) or max(m, n) x nrhs)
[in] Matrix B of right hand side vectors, stored columnwise; B is m x nrhs if trans = 'N', or n x nrhs if trans = 'T'.
[out] If info = 0, b is overwritten by the solution vectors, stored columnwise:
trans = 'N' and m >= n: Rows 0 to n-1 of b contain the least squares solution vectors; the residual sum of squares for the solution in each column is given by the sum of squares of elements n to m-1 in that column.
trans = 'N' and m < n: Rows 0 to n-1 of b contain the minimum norm solution vectors.
trans = 'T' and m >= n: Rows 0 to m-1 of b contain the minimum norm solution vectors.
trans = 'T' and m < n: Rows 0 to m-1 of b contain the least squares solution vectors; the residual sum of squares for the solution in each column is given by the sum of squares of elements m to n-1 in that column. |
| [in] | nrhs | (Optional)
Number of right hand sides, i.e., number of columns of the matrices B and X. (nrhs >= 0) (If nrhs = 0, returns without computation) (default = 1) |
- Reference
- LAPACK
- Example Program
- Compute the least squares solution of the overdetermined linear equations Ax = b and its variance, where
( -1.06 0.48 -0.04 )
A = ( -1.19 0.73 -0.24 )
( 1.97 -0.89 0.56 )
( 0.68 -0.53 0.08 )
( 0.3884 )
B = ( 0.1120 )
( -0.3644 )
( -0.0002 )
function TestDgels()
m = 4
n = 3
a = [ -1.06 0.48 -0.04;
-1.19 0.73 -0.24;
1.97 -0.89 0.56;
0.68 -0.53 0.08 ]
b = [ 0.3884, 0.1120, -0.3644, -0.0002 ]
info = dgels('N', m, n, a, b)
println(b[1], " ", b[2], " ", b[3], " ", info)
if info == 0
ci = Vector{Cdouble}(undef, n)
println(ci, " ", info)
end
end
function dgels(trans::Char, m::Integer, n::Integer, a::Array{Float64}, b::Array{Float64}, nrhs::Integer=1) Solution to overdetermined or underdetermined linear equations Ax = b (full rank)
function dgecov(job::Integer, n::Integer, a::Array{Float64}, ci::Array{Float64}) Unscaled covariance matrix of linear least squares problem solved by dgels
- Example Results
> TestDgels()
-0.8200000000000006 -0.9400000000000007 0.7400000000000008 0
[6.46959967542666, 16.735040821891918, 18.717753277322856] 0
|