|
|
◆ dgesv()
| def dgesv |
( |
n |
, |
|
|
a |
, |
|
|
ipiv |
, |
|
|
b |
, |
|
|
nrhs |
= 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 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 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 (int)
= 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] | n | Number of linear equations, i.e., order of the matrix A. (n >= 0) (If n = 0, returns without computation) |
| [in,out] | a | Numpy ndarray (2-dimensional, float, 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] | ipiv | Numpy ndarray (1-dimensional, int, n)
Pivot indices that define the permutation matrix P; row i of the matrix was interchanged with row ipiv[i - 1]. |
| [in,out] | b | Numpy ndarray (1 or 2-dimensional, float, 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 )
def TestDgesv():
n = 3
a = np.array([
[0.2, -0.32, -0.8],
[-0.11, 0.81, -0.92],
[-0.93, 0.37, -0.29]])
b = np.array([-0.3727, 0.4319, -1.4247])
ipiv = np.empty(n, dtype=int)
anorm, info = dlange( '1', n, n, a)
info = dgesv(n, a, ipiv, b)
print(b, info)
rcond, info = dgecon( '1', n, a, anorm)
print(rcond, info)
def dgesv(n, a, ipiv, b, nrhs=1) Solution to system of linear equations AX = B for a general matrix
def dgecon(norm, n, a, anorm) Condition number of a general matrix
def dlange(norm, m, n, a) One norm, Frobenius norm, infinity norm, or largest absolute value of any element of a general rectan...
- Example Results
>>> TestDgesv()
[0.86 0.64 0.51] 0
0.23270847318607646 0
|