Rate This Document
Findability
Accuracy
Completeness
Readability

?getrs

Solve the general linear equation A * X = B, AT * X = B, or AH * X = B. The coefficient matrix A is obtained by calling ?getrf.

Interface Definition

C interface:

void sgetrs_(const char *TRANS, const int *N, const int *NRHS, float *A, const int *LDA, int *IPIV, float *B, const int *LDB, int *INFO);

void dgetrs_(const char *TRANS, const int *N, const int *NRHS, double *A, const int *LDA, int *IPIV, double *B, const int *LDB, int *INFO);

void cgetrs_(const char *TRANS, const int *N, const int *NRHS, float _Complex *A, const int *LDA, int *IPIV, float _Complex *B, const int *LDB, int *INFO);

void zgetrs_(const char *TRANS, const int *N, const int *NRHS, double _Complex *A, const int *LDA, int *IPIV, double _Complex *B, const int *LDB, int *INFO);

Fortran interface:

SGETRS(TRANS, N, NRHS, A, LDA, IPIV, B, LDB, INFO);

DGETRS(TRANS, N, NRHS, A, LDA, IPIV, B, LDB, INFO);

CGETRS(TRANS, N, NRHS, A, LDA, IPIV, B, LDB, INFO);

ZGETRS(TRANS, N, NRHS, A, LDA, IPIV, B, LDB, INFO);

Parameters

Parameter

Type

Description

Input/Output

TRANS

Character

  • If the value is 'N', A * X = B.
  • If the value is 'T', AT * X = B.
  • If the value is 'C', AH * X = B (conjugate transposition).

Input

N

Integer

Order of matrix A, N ≥ 0.

Input

NRHS

Integer

Number of columns in matrix B, NRHS ≥ 0.

Input

A

  • A single-precision floating-point array for sgetrs
  • A double-precision floating-point array for dgetrs
  • A single-precision complex array for cgetrs
  • A double-precision complex array for zgetrs

L and U parts of matrix A obtained by calling GETRF. The size is LDA*N.

Input

LDA

Integer

Leading dimension of matrix A. LDA ≥ max(1, N).

Input

IPIV

Integer array

Transposed array.

Input

B

  • A single-precision floating-point array for sgetrs
  • A double-precision floating-point array for dgetrs
  • A single-precision complex array for cgetrs
  • A double-precision complex array for zgetrs

Right-hand side matrix, with a size of LDB*NRHS.

  • Before calling: right-hand side matrix B.
  • After calling: solved matrix X.

Input, output

LDB

Integer

Leading dimension of matrix B. LDB ≥ max(1, N).

Input

INFO

Integer

0: The exit is successful.

Smaller than 0: The value of the -info-th parameter is invalid.

Output

Dependency

include "klapack.h"

Examples

C interface:

char trans = 'N';
int n = 5; 
int nrhs = 1; 
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[]={1.0, 2.0, 3.0, 4.0, 5.0}; 
dgetrf_(&n, &n, a, &lda, ipiv, &info);
dgetrs_(&trans, &n, &nrhs, a, &lda, ipiv, b, &ldb, &info); 
/* 
* Output: -0.073465    0.038136    -0.033917    0.055903    0.112798
*/
Fortran interface:
CHARACTER::trans='N'
PARAMETER(n=5) 
PARAMETER(nrhs=1) 
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 / 1.0, 2.0, 3.0, 4.0, 5.0 / 
 EXTERNAL DGETRF, DGETRS
 CALL DGETRF(n, n, a, lda, ipiv, info); 
 CALL DGETRS(trans, n, nrhs, a, lda, ipiv, b, ldb, info); 
* Output: -0.073465    0.038136    -0.033917    0.055903    0.112798