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

?trtri

Compute the inverse matrix of an upper/lower triangular matrix.

Interface Definition

C interface:

void strtri_(const char *uplo, const char *diag, const int *n, float *a, const int *lda, int *info);

void dtrtri_(const char *uplo, const char *diag, const int *n, double *a, const int *lda, int *info);

void ctrtri_(const char *uplo, const char *diag, const int *n, float _Complex *a, const int *lda, int *info);

void ztrtri_(const char *uplo, const char *diag, const int *n, double _Complex *a, const int *lda, int *info);

Fortran interface:

STRTRI(UPLO, DIAG, N, A, LDA, INFO)

DTRTRI(UPLO, DIAG, N, A, LDA, INFO)

CTRTRI(UPLO, DIAG, N, A, LDA, INFO)

ZTRTRI(UPLO, DIAG, N, A, LDA, INFO)

Parameters

Parameter

Type

Description

Input/Output

UPLO

Character

  • 'U': Stores the upper triangular part of matrix A.
  • 'L': Stores the lower triangular part of matrix A.

Input

DIAG

Character

  • 'N': Matrix A is a non-unit triangular matrix.
  • 'U': Matrix A is a unit triangular matrix.

Input/Output

N

Integer

Dimension of matrix A, N ≥ 0.

Input

A

  • A single-precision floating-point array for strtri
  • A double-precision floating-point array for dtrtri
  • A single-precision complex array for ctrtri
  • A double-precision complex array for ztrtri
  • Before this function is called, if UPLO='U', matrix A contains the upper triangular part and the lower triangular part will not be used. If UPLO='L', matrix A contains the lower triangular part and the upper triangular part will not be used. If DIAG='U', the diagonal element will not be used.
  • After this function is called, the inverse matrix of matrix A is stored in the same format.

Output

LDA

Integer

Leading dimension of matrix A. LDA ≥ 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 info-th element on the diagonal of U is 0, and the matrix cannot be inverted.

Output

Dependency

#include "klapack.h"

Examples

C interface:

const char uplo = 'U';
const char diag = 'N';
const int n = 4;
const int lda = n;
/* 
* A: After Cholesky factorization (via potrf, stored in column-major): 
*  231.8009    33.9545    9.4153   11.1156    
*   33.9454   162.2902   6.6684   53.2023     
*   9.4153   6.6684  100.3220  71.5384   
*   11.1156   53.2023    71.5384  106.5638  
*/ 
double a[] = {231.8009,   33.9545,   9.4143,   11.1156, 
              33.9495,  162.2902,   6.6684,   53.2033, 
              9.4143,    6.6684,  100.322,   71.5384, 
              11.1156,   53.2033,  71.5384,  106.5638 }; 
int info = 0;
dtrtri_(&uplo, &diag, &n, a, &lda, &info);
if (info != 0) {
    printf("ERROR, info = %d\n", info);
}

/* 
* Output: 
*   a: 
*    0.004314    -0.000902    -0.000345    0.000232
*    33.954500    0.006162    -0.000410    -0.002801
*    9.414300    6.668400    0.009968    -0.006692
*    11.115600    53.203300    71.538400    0.009384
*/

Fortran interface:

CHARACTER::uplo = "U"
CHARACTER::diag = "N"
PARAMETER (n = 4)  
PARAMETER (lda = 4)  
INTEGER :: info = 0 
REAL(8) :: a(lda, n) 
  
* A: After Cholesky factorization (via potrf, stored in column-major): 
*  231.8009    33.9545    9.4153   11.1156    
*   33.9454   162.2902   6.6684   53.2023     
*   9.4153   6.6684  100.3220  71.5384   
*   11.1156   53.2023    71.5384  106.5638 
  
DATA a / 231.8009,  33.9545,  9.4143, 11.1156, 
 $           33.9495,  162.2902, 6.6684, 53.2033, 
 $           9.4143,    6.6684,  100.322, 71.5384, 
 $           11.1156,   53.2033, 71.5384, 106.5638 / 

 EXTERNAL DTRTRI
 CALL DTRTRI(uplo, diag,  n, a, lda, info)

* 
* Output: 
*   a: 
*    0.004314    -0.000902    -0.000345    0.000232
*    33.954500    0.006162    -0.000410    -0.002801
*    9.414300    6.668400    0.009968    -0.006692
*    11.115600    53.203300    71.538400    0.009384
*