我要评分
获取效率
正确性
完整性
易理解

?gesv

Solve a system of linear equations , where is an matrix. and are matrices. In the solving process, LU factorization with partial rotation and row interchange is performed on to factor it into a form of , where is a permutation matrix, is a unit lower triangular matrix, and is an upper triangular matrix. The system of linear equations is solved based on the result of LU factorization.

Interface Definition

C interface:

void sgesv_(const int *n,const int *nrhs,float *a,const int *lda,int *ipiv, float *b, const int *ldb,int *info);

void dgesv_(const int *n,const int *nrhs,double *a,const int *lda,int *ipiv, double *b, const int *ldb,int *info);

void cgesv_(const int *n,const int *nrhs,float_Complex *a,const int *lda,int *ipiv, float_Complex *b, const int *ldb,int *info);

void zgesv_(const int *n,const int *nrhs, double_Complex *a,const int *lda,int *ipiv, double_Complex *b, const int *ldb,int *info);

Fortran interface:

SGESV(n, nrhs, a, lda, ipiv, b, ldb, info);

DGESV(n, nrhs, a, lda, ipiv, b, ldb, info);

CGESV(n, nrhs, a, lda, ipiv, b, ldb, info);

ZGESV(n, nrhs, a, lda, ipiv, b, ldb, info);

Parameters

Parameter

Type

Description

Input/Output

n

Integer

Order of matrix A. n ≥ 0.

Input

nrhs

Integer

Number of items on the right, that is, the number of columns in matrix B. nrhs ≥ 0.

Input

a

  • A single-precision floating-point array for sgesv
  • A double-precision floating-point array for dgesv
  • A single-precision complex array for cgesv
  • A double-precision complex array for zgesv

The matrix dimension is (lda, n).

  • Input: n*n coefficient matrix A.
  • Output: and in are stored. The unit diagonal element of is not stored.

Input/Output

lda

Integer

Leading dimension of matrix A. lda ≥ max(1, n).

Input

ipiv

Integer array

The array dimension is n.

Array storing the pivot indices of the permutation matrix P. The i-th row of the matrix is interchanged with the ipiv(i)-th row.

Output

b

  • A single-precision floating-point array for sgesv
  • A double-precision floating-point array for dgesv
  • A single-precision complex array for cgesv
  • A double-precision complex array for zgesv

The matrix dimension is (ldb, nrhs).

  • Input: matrix B on the right of .
  • Output: When info=0, it is the solved matrix X of .

Input/Output

ldb

Integer

Leading dimension of matrix B. ldb ≥ max(1, n).

Input

info

Integer

Execution result:

  • 0: The execution is successful.
  • Smaller than 0: The value of the -info-th parameter is invalid.
  • Greater than 0: . The factorization is complete, but the solution cannot be completed due to the singularity of .

Output

Dependency

#include "klapack.h"

Examples

C interface:

int n = 5; 
int nrhs = 2; 
int lda = 5; 
int ldb = 5; 
int ipiv[5]; 
int info = 0; 
double a[]={72.1673 , 66.1857 , 64.7644 , 28.0199 , 91.4151, 
            6.5180 , 62.8483 , 72.4323 , 46.5760 ,  8.6928, 
            28.9821 , 42.1828 , 18.6437 , 99.8612 , 35.6972, 
            67.9812 ,  5.0880 , 85.5035 ,79.2945 , 54.5920, 
            28.6869 , 49.7512 ,  7.5186 ,28.6929 , 84.6041}; 
double b[]={ 9.4532 ,  1.5204 ,  2.2127 ,  0.9891, 7.1778, 
             6.8955 ,   7.2465,  3.5019 ,  8.2268, 3.5287}; 
dgesv_(&n,&nrhs,a,&lda,ipiv,b,&ldb,&info); 
/* 
* Output: 
* 0.17538061067669766        0.16637572403098155 
* -0.11183914210321674       -3.7758100714851153E-002 
* 5.5415093265516101E-002    0.15550950667724139 
* -1.4901096204948673E-002   -7.3593964815566168E-002 
* -0.10693481055391466       -0.15230871441871899 
*/

Fortran interface:

PARAMETER(n=5) 
PARAMETER(nrhs=2) 
PARAMETER(lda=5) 
PARAMETER(ldb=5) 
INTEGER::info =0 
INTEGER :: ipiv(n) 
REAL(8) :: a(n*n) 
        DATA a / 72.1673 , 66.1857 , 64.7644 , 28.0199 , 91.4151, 
     $           6.5180 , 62.8483 , 72.4323 , 46.5760 ,  8.6928, 
     $           28.9821 , 42.1828 , 18.6437 , 99.8612 , 35.6972, 
     $           67.9812 ,  5.0880 , 85.5035 ,79.2945 , 54.5920, 
     $           28.6869 , 49.7512 ,  7.5186 ,28.6929 , 84.6041 / 
        REAL(8) :: b(n, nrhs) 
        DATA b /9.4532 ,  1.5204 ,  2.2127 ,  0.9891, 7.1778, 
     $           6.8955 ,   7.2465,  3.5019 ,  8.2268, 3.5287 / 
        EXTERNAL DGESV 
        CALL DGESV(n, nrhs, a, lda, ipiv, b, ldb, info); 
*       Output: 
*       0.17538061067669766        0.16637572403098155 
*       -0.11183914210321674       -3.7758100714851153E-002 
*       5.5415093265516101E-002    0.15550950667724139  
 *      -1.4901096204948673E-002   -7.3593964815566168E-002 
*       -0.10693481055391466       -0.15230871441871899