---
title: ?ppsv
description: "求解线性方程组。其中A为实对称或共轭对称的正定矩阵，以压缩方式存储；X和B为矩阵。计算矩阵A的Cholesky分解，并通过分解结果求解线性方程组。"
url: https://www.hikunpeng.com/document/detail/zh/kunpengboostkithistory/2200/accel/kunpengaccel_kml_16_0212.html
sourcePath: /source/zh/kunpengboostkithistory/2200/accel/kunpengaccel_kml_16_0212.html
indexId: 984bde7ba3f50035a7a5680cdb357a219fd544d3b763bc2f945bb30aa3db4ff574
---
# ?ppsv

求解线性方程组。其中A为实对称或共轭对称的正定矩阵，以压缩方式存储；X和B为矩阵。计算矩阵A的Cholesky分解，并通过分解结果求解线性方程组。

#### 接口定义

C Interface：

void dppsv_(const char *uplo, const int *n, const int *nrhs, double *ap, double *b, const int *ldb, int *info);

void sppsv_(const char *uplo, const int *n, const int *nrhs, float *ap, float *b, const int *ldb, int *info);

void cppsv_(const char *uplo, const int *n, const int *nrhs, float _Complex *ap, float _Complex *b, const int *ldb, int *info);

void zppsv_(const char *uplo, const int *n, const int *nrhs, double _Complex *ap, double _Complex *b, const int *ldb, int *info);

Fortran Interface：

DPPSV(uplo, n, nrhs, ap, b, ldb, info);

SPPSV(uplo, n, nrhs, ap, b, ldb, info);

CPPSV(uplo, n, nrhs, ap, b, ldb, info);

ZPPSV(uplo, n, nrhs, ap, b, ldb, info);


#### 参数

| 参数名 | 类型 | 描述 | 输入/输出 |
| --- | --- | --- | --- |
| uplo | 字符型 | 'U'：A中保存上三角矩阵。 'L'：A中保存下三角矩阵。 | 输入 |
| n | 整型数 | 对称矩阵A的行数或列数。 | 输入 |
| nrhs | 整型数 | 右侧项的数量，即矩阵B的列数，要求nrhs≥0。 | 输入 |
| ap | 在sppsv中为单精度浮点型数组。 在dppsv中为双精度浮点型数组。 在cppsv中为单精度复数型数组。 在zppsv中为双精度复数型数组。 | 调用前以压缩格式保存对称矩阵A，见数据结构中关于压缩存储矩阵的说明。 调用后以压缩格式保存A的Cholesky分解结果（U或L）。 | 输入/输出 |
| b | 在sppsv中为单精度浮点型数组。 在dppsv中为双精度浮点型数组。 在cppsv中为单精度复数型数组。 在zppsv中为双精度复数型数组。 | 调用前为右侧矩阵B。 调用后为解矩阵X。 | 输入/输出 |
| ldb | 整型数 | B的leading dimension大小，要求ldb≥max(1, n)。 | 输入 |
| info | 整数型 | 执行结果： 等于0：成功。 小于0：第\-info个参数值不合法。 大于0：A中info大小的顺序主子式非正定，无法完成分解。 | 输出 |


#### 依赖

#include "klapack.h"


#### 示例

C Interface：

```
char uplo = 'L';
int n = 5;
int nrhs = 2;
int ldb = 5;
int info = 0;
/*
* A (stored in column-major):
*  178.535    33.2929    9.2538   11.1156   21.5482
*   33.2929  156.5955    5.1031   55.771    41.3063
*    9.2538    5.1031  100.5198   73.8396   23.04
*   11.1156   55.771    73.8396  106.5638   56.19
*   21.5482   41.3063   23.04     56.19    114.5161
*/
double ap[] = {178.535,  33.2929,  9.2538, 11.1156, 21.5482,
156.5955,  5.1031, 55.771,  41.3063,
100.5198, 73.8396, 23.04,
106.5638, 56.19,
114.5161};
double b[] = {0.374, 6.242, 5.593, 2.456, 5.222,
6.906, 2.31 , 3.948, 6.403, 5.664};
dppsv_(&uplo, &n, &nrhs, ap, b, &ldb, &info);
/*
* Output X:
*  -0.0186   0.0373
*   0.0770  -0.0235
*   0.1536  -0.0208
*  -0.1574   0.0726
*   0.0677   0.0195
*/
```

Fortran Interface：

```
CHARACTER :: uplo = "L"
PARAMETER (n = 5)
PARAMETER (nrhs = 2)
PARAMETER (ldb = 5)
INTEGER :: info = 0
*       A (stored in column-major):
*        178.535    33.2929    9.2538   11.1156   21.5482
*         33.2929  156.5955    5.1031   55.771    41.3063
*          9.2538    5.1031  100.5198   73.8396   23.04
*         11.1156   55.771    73.8396  106.5638   56.19
*         21.5482   41.3063   23.04     56.19    114.5161
REAL(8) :: ap(15)
DATA ap / 178.535,  33.2929,  9.2538, 11.1156, 21.5482,
$                      156.5955, 5.1031, 55.771,  41.3063,
$                                100.5198, 73.8396, 23.04,
$                                          106.5638, 56.19,
$                                                    114.5161 /
REAL(8) :: b(n, nrhs)
DATA b / 0.374, 6.242, 5.593, 2.456, 5.222,
$           6.906, 2.31 , 3.948, 6.403, 5.664 /
EXTERNAL DPPSV
CALL DPPSV(uplo, n, nrhs, ap, b, ldb, info);
*       Output X:
*        -0.0186   0.0373
*         0.0770  -0.0235
*         0.1536  -0.0208
*        -0.1574   0.0726
*         0.0677   0.0195
```
