?trtrs
求解三角方程A * X = B,或A**T * X = B。
接口定义
C Interface:
void dtrtrs_(const char *uplo, const char *trans, const char *diag, const int *n, const int *nrhs, const double *a, const int *lda, double *b, const int *ldb, int *info);
void strtrs_(const char *uplo, const char *trans, const char *diag, const int *n, const int *nrhs, const float *a, const int *lda, float *b, const int *ldb, int *info);
void ctrtrs_(const char *uplo, const char *trans, const char *diag, const int *n, const int *nrhs, const float _Complex *a, const int *lda, float _Complex *b, const int *ldb, int *info);
void ztrtrs_(const char *uplo, const char *trans, const char *diag, const int *n, const int *nrhs, const double _Complex *a, const int *lda, double _Complex *b, const int *ldb, int *info);
Fortran Interface:
DTRTRS(UPLO, TRANS, DIAG, N, NRHS, A, LDA, B, LDB, INFO);
STRTRS(UPLO, TRANS, DIAG, N, NRHS, A, LDA, B, LDB, INFO);
CTRTRS(UPLO, TRANS, DIAG, N, NRHS, A, LDA, B, LDB, INFO);
ZTRTRS(UPLO, TRANS, DIAG, N, NRHS, A, LDA, B, LDB, INFO);
参数
参数名 |
类型 |
描述 |
输入/输出 |
---|---|---|---|
UPLO |
字符型 |
|
输入 |
TRANS |
字符型 |
|
输入 |
DIAG |
字符型 |
|
输入 |
N |
整数型 |
矩阵A的阶数,N ≥ 0。 |
输入 |
NRHS |
整数型 |
矩阵B的列数,NRHS ≥ 0。 |
输入 |
A |
|
三角矩阵A,大小为(LDA, N)。 |
输入 |
LDA |
整数型 |
矩阵A的主维,LDA ≥ max(1, N)。 |
输入 |
B |
|
输入时,为右端矩阵B,大小为(LDB, NRHS)。 输出时, 若INFO = 0,为方程的解矩阵X。 |
输入、输出 |
LDB |
整数型 |
右端矩阵B的主维, LDB ≥ max(1, N)。 |
输入 |
INFO |
整数型 |
|
输出 |
依赖
include "klapack.h"
示例
C Interface:
const char uplo = 'L'; const char trans = 'N'; const char diag = 'N'; const int n = 4; const int lda = n; const int ldb = n; const int nrhs = 1; double *a = (double*)malloc(lda * n * sizeof(double)); double *b = (double*)malloc(ldb * nrhs * sizeof(double)); int info = 0; // Generate Matrix A. for (int i = 0; i < n; i++) { for (int j = i; j < lda; j++) { a[i * lda + j] = (rand() % 53 + 1) / 53.0; } } // Generate right hand side matrix B. for (int i = 0; i < ldb * nrhs; i++) { b[i] = (rand() % 23 + 1) / 23.0; } // Call dtrtrs. dtrtrs_(&uplo, &trans, &diag, &n, &nrhs, a, &lda, b, &ldb, &info); if (info != 0) { printf("ERROR, info = %d\n", info); }
Fortran Interface:
CHARACTER :: uplo = "L" CHARACTER :: trans = "N" CHARACTER :: diag = "N" PARAMETER (n = 4) PARAMETER (lda = 4) PARAMETER (ldb = 4) PARAMETER (nrhs = 1) INTEGER :: info = 0 REAL(8) :: d(lda, n) REAL(8) :: b(ldb, nrhs) EXTERNAL DTRTRS CALL DTRTRS(uplo, trans, diag n, nrhs, a, lda, b, ldb, info);