XLPack 6.1
Julia API Reference Manual
Loading...
Searching...
No Matches

◆ dgesv()

function dgesv ( n::Integer  ,
a::Array{Float64}  ,
ipiv::Array{Int32}  ,
b::Array{Float64}  ,
nrhs::Integer  = 1 
)

Solution to system of linear equations AX = B for a general matrix

Purpose
dgesv computes the solution to a real system of linear equations
A * X = B
where A is an n x n matrix and X and B are n x nrhs matrices.

The LU decomposition with partial pivoting and row interchanges is used to factor A as
A = P * L * U
where P is a permutation matrix, L is unit lower triangular, and U is upper triangular. The factored form of A is then used to solve the system of equations A * X = B.
Returns
info (Int32)
= 0: Successful exit.
= -1: The argument n had an illegal value. (n < 0)
= -2: The argument a is invalid.
= -3: The argument ipiv is invalid.
= -4: The argument b is invalid.
= -5: The argument nrhs had an illegal value. (nrhs < 0)
= i > 0: The i-th diagonal element of the factor U is exactly zero. The factorization has been completed, but the factor U is exactly singular, so the solution could not be computed.
Parameters
[in]nNumber of linear equations, i.e., order of the matrix A. (n >= 0) (If n = 0, returns without computation)
[in,out]a2-dimensional array (Float64, n x n)
[in] n x n coefficient matrix A.
[out] Factors L and U from the factorization A = P*L*U; the unit diagonal elements of L are not stored.
[out]ipiv1-dimensional array (Int32, n)
Pivot indices that define the permutation matrix P; row i of the matrix was interchanged with row ipiv[i - 1].
[in,out]b1 or 2-dimensional array (Float64, n or n x nrhs)
[in] n x nrhs matrix of right hand side matrix B.
[out] If info = 0, the n x nrhs solution matrix X.
[in]nrhs(Optional)
Number of right hand sides, i.e., number of columns of the matrix B. (nrhs >= 0) (If nrhs = 0, returns without computation) (default = 1)
Reference
LAPACK
Example Program
Solve the system of linear equations Ax = B and estimate the reciprocal of the condition number (RCond) of A, where
( 0.2 -0.11 -0.93 ) ( -0.3727 )
A = ( -0.32 0.81 0.37 ), B = ( 0.4319 )
( -0.8 -0.92 -0.29 ) ( -1.4247 )
function TestDgesv()
n = 3
a = [ 0.2 -0.11 -0.93;
-0.32 0.81 0.37;
-0.8 -0.92 -0.29 ]
b = [ -0.3727, 0.4319, -1.4247 ]
ipiv = Vector{Cint}(undef, n)
anorm, info = dlange('1', n, n, a)
info = dgesv(n, a, ipiv, b)
println("x = ", b, ", info = ", info)
if info == 0
rcond, info = dgecon('1', n, a, anorm)
println("rcond = ", rcond, ", info = ", info)
end
end
function dgecon(norm::Char, n::Integer, a::Array{Float64}, anorm::Real)
Condition number of a general matrix
function dlange(norm::Char, m::Integer, n::Integer, a::Array{Float64})
One norm, Frobenius norm, infinity norm, or largest absolute value of any element of a general rectan...
function dgesv(n::Integer, a::Array{Float64}, ipiv::Array{Int32}, b::Array{Float64}, nrhs::Integer=1)
Solution to system of linear equations AX = B for a general matrix
Example Results
> TestDgesv()
x = [0.8600000000000002, 0.64, 0.5099999999999999], info = 0
rcond = 0.23270847318607646, info = 0