文档
注册
评分
提单
论坛
小智

?gesv

求解线性方程组,其中的矩阵,的矩阵。求解过程中,对使用具有部分旋转和行交换的LU分解,将其分解为的形式,其中是置换矩阵,是单位下三角矩阵,是上三角矩阵。并通过LU分解的结果来求解线性方程组。

接口定义

C Interface:

void dsgesv_(const int *n, const int *nrhs, double *a, const int *lda, int *ipiv, const double *b, const int *ldb, double *x, const int *ldx, double *work, float *swork, int *iter, int *info);

void zcgesv_( const int *n, const int *nrhs, double _Complex *a, const int *lda, int *ipiv, const double _Complex *b, const int *ldb, double _Complex *x, const int *ldx, double _Complex *work, float _Complex *swork, double *rwork, int *iter, int *info);

Fortran Interface:

DSGESV(N, NRHS, A, LDA, IPIV, B, LDB, X, LDX, WORK, SWORK, ITER, info);

ZCGESV(N, NRHS, A, LDA, IPIV, B, LDB, X, LDX, WORK, SWORK, RWORK, ITER, info);

参数

参数名

类型

描述

输入/输出

n

整数型

矩阵A的阶数,要求n≥0。

输入

nrhs

整数型

右端项的数量,即矩阵B的列数,要求nrhs≥0。

输入

a

  • 在dsgesv中为双精度浮点型数组。
  • 在zcgesv中为双精度复数型数组。

矩阵大小为(lda,n)。

  • 输入:n*n的系数矩阵A。
  • 输出:储存了中的,其中的单位对角线元素不存储。

输入,输出

lda

整数型

A的leading dimension大小,要求lda≥max(1, n)。

输入

ipiv

整数型数组

数组维度为n。

存放了置换矩阵P的主元索引,即矩阵第i行与第ipiv(i)行交换。

输出

b

  • 在dsgesv中为双精度浮点型数组。
  • 在zcgesv中为双精度复数型数组。

矩阵维度为(ldb,nrhs)。

  • 输入:的右端矩阵B。

输入

ldb

整数型

B的主维大小,要求ldb≥max(1, n)。

输入

x

  • 在dsgesv中为双精度浮点型数组。
  • 在zcgesv中为双精度复数型数组。

大小为ldx*nrhs。

若info=0时,输出为n*nrhs的解矩阵。

输出

ldx

整数型

矩阵x的主维,ldx≥max(1, n)。

输入

work

  • 在dsgesv中为双精度浮点型数组。
  • 在zcgesv中为双精度复数型数组。

大小为n*nrhs。

用于保存残差向量。

输出

swork

  • 在dsgesv中为单精度浮点型数组。
  • 在zcgesv中为单精度复数型数组。

大小为n*(n+nrhs)。

用于存储单精度矩阵和单精度中的解。

输出

rwork(复数特有)

双精度浮点型数组

工作数组,大小为n。

输出

iter

整数型

  • 小于0:迭代细化失败,使用双精度完成分解。
  • 大于0:迭代细化成功,返回迭代步数。

输出

info

整数型

执行结果:

  • 等于0:成功。
  • 小于0:第-info个参数值不合法。
  • 大于0:,分解已经完成,但是因为奇异,所以无法完成求解。

输出

依赖

#include "klapack.h"

示例

C Interface:

const int n = 4;
const int nrhs = 2;
const int lda = 4;
const int ldb = 4;
const int ldx = 4;

int info = 0;
int iter = 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}; 
int *ipiv = (int*)malloc(n * sizeof(int));
double b[] = {9.4532, 1.5204, 2.2127, 0.9891, 7.1778,
              6.8955, 7.2465, 3.5019, 8.2268, 3.5287};

double *x = (double*)malloc(ldx * nrhs * sizeof(double));
double *work = (double*)malloc(n * nrhs * sizeof(double));
float *swork = (float*)malloc(n * (n + nrhs) * sizeof(float));

dsgesv_(&n, &nrhs, a, &lda, ipiv, b, &ldb, x, &ldx, work, swork, &iter, &info);
if (info != 0) {
    printf("ERROR, info = %d\n", info);
}

if (iter < 0) {
    printf("Iterative refinement failed, iter = %d\n", iter);
}
/* output */
* x
* 0.153366        0.083995
* -0.538653       0.096517
* 1.080726        -0.174382
* -0.145340       0.022261
* iter
* 2

Fortran Interface:

PARAMETER (n = 4) 
PARAMETER (nrhs = 2) 
PARAMETER (lda = 4)
PARAMETER (ldb = 4)
PARAMETER (ldx = 4)
REAL(8) :: a(lda, n)  
REAL(8) :: b(ldb, n)
REAL(8) :: b(ldx, n)
REAL(8) :: work(nrhs, n)
REAL(4) :: swork(n+nrhs, n)
INTERGER::ipiv(n)

INTEGER :: info = 0
INTEGER :: iter = 0
  
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 /
 EXTERNAL DSGESV
 CALL DSGESV(n, nrhs, a, lda, ipiv, b, ldb, x, ldx, work, swork, iter, info);
IF (info.NE.0) THEN 
    CALL EXIT(1) 
END IF
IF (iter.LT.0) THEN 
    CALL EXIT(1) 
END IF
* 
* Output: 
* 0.153366        0.083995
* -0.538653       0.096517
* 1.080726        -0.174382
* -0.145340       0.022261
* iter
* 2
搜索结果
找到“0”个结果

当前产品无相关内容

未找到相关内容,请尝试其他搜索词