?posv
求解线性方程组。其中A为实对称或共轭对称的正定矩阵;X和B为矩阵。计算矩阵A的Cholesky分解,并通过分解结果求解线性方程组。
接口定义
C Interface:
void dposv_(const char *uplo, const int *n, const int *nrhs, double *a, const int *lda, double *b, const int *ldb, int *info);
void sposv_(const char *uplo, const int *n, const int *nrhs, float *a, const int *lda, float *b, const int *ldb, int *info);
void cposv_(const char *uplo, const int *n, const int *nrhs, float _Complex *a, const int *lda, float _Complex *b, const int *ldb, int *info);
void zposv_(const char *uplo, const int *n, const int *nrhs, double _Complex *a, const int *lda, double _Complex *b, const int *ldb, int *info);
Fortran Interface:
DPOSV(uplo, n, nrhs, a, lda, b, ldb, info);
SPOSV(uplo, n, nrhs, a, lda, b, ldb, info);
CPOSV(uplo, n, nrhs, a, lda, b, ldb, info);
ZPOSV(uplo, n, nrhs, a, lda, b, ldb, info);
参数
参数名 |
类型 |
描述 |
输入/输出 |
---|---|---|---|
uplo |
字符型 |
|
输入 |
n |
整数型 |
对称矩阵A的行数或列数。 |
输入 |
nrhs |
整数型 |
右侧项的数量,即矩阵B的列数,要求nrhs≥0。 |
输入 |
a |
|
|
输入/输出 |
lda |
整数型 |
A的leading dimension大小,要求lda≥max(1, n)。 |
输入 |
b |
|
|
输入/输出 |
ldb |
整数型 |
B的leading dimension大小,要求ldb≥max(1, n)。 |
输入 |
info |
整数型 |
执行结果:
|
输出 |
依赖
#include "klapack.h"
示例
char uplo = 'L'; int n = 4; int nrhs = 1; int lda = 4; int ldb = 4; int info = 0; /* * A (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}; double b[] = {1.0, 2.0, 3.0, 4.0}; dposv_(&uplo, &n, &nrhs, a, &lda, b, &ldb, &info); /* * Output X: 0.002361 0.000904 0.006432 0.032521 */
Fortran Interface:
CHARACTER :: uplo = "L" PARAMETER (n = 4) PARAMETER (nrhs = 1) PARAMETER (lda = 4) PARAMETER (ldb = 4) INTEGER :: info = 0 * * A (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 REAL(8) :: a(lda, n) 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 / REAL(8) :: b(ldb, nrhs) DATA b / 1.0, 2.0, 3.0, 4.0 / EXTERNAL DPOSV CALL DPOSV(uplo, n, nrhs, a, lda, b, ldb, info); * Output X: 0.002361 0.000904 0.006432 0.032521