KmlDssGenSolve?I
求解LUx=b。
接口定义
C Interface:
int KmlDssGenSolveSI(KmlSolverTask **pHandle, int nb, float *x, int ldx, float *b, int ldb);
int KmlDssGenSolveDI(KmlSolverTask **pHandle, int nb, double *x, int ldx, double *b, int ldb);
int KmlDssGenSolveCI(KmlSolverTask **pHandle, int nb, kml_complex_float *x, int ldx, kml_complex_float *b, int ldb);
int KmlDssGenSolveZI(KmlSolverTask **pHandle, int nb, kml_complex_double *x, int ldx, kml_complex_double *b, int ldb);
参数
参数名 |
类型 |
描述 |
输入/输出 |
---|---|---|---|
pHandle |
KmlSolverTask ** |
求解器句柄,传入之前步骤的变量。 |
输入 |
nb |
int |
右端项矢量的个数。 |
输入 |
x |
|
稠密向量存储求解结果,其元素个数为ldx*nb,第k个矢量的第i个元素位置为x[i + k * ldx]。 |
输入/输出 |
ldx |
int |
x的leading dimension大小,要求ldx ≥ max(1, n)。 |
输入 |
b |
|
稠密向量存储右端项,其元素个数为ldb*nb,第k个矢量的第i个元素位置为b[i + k * ldb]。 |
输入 |
ldb |
int |
b的leading dimension大小,要求ldb ≥ max(1, n)。 |
输入 |
返回值
返回值 |
类型 |
描述 |
---|---|---|
KMLSS_NO_ERROR |
int |
正常执行。 |
KMLSS_NULL_ARGUMENT |
int |
pHandle,x,b为空。 |
KMLSS_BAD_NB |
int |
输入参数nb小于等于0。 |
KMLSS_BAD_HANDLE |
int |
pHandle格式存在问题。 |
KMLSS_BAD_LDX |
int |
ldx取值不在有效范围内。 |
KMLSS_BAD_LDB |
int |
ldb取值不在有效范围内。 |
KMLSS_INVALID_CALL_ORDER |
int |
函数执行顺序错误,尚未执行分解阶段就提前执行求解函数。 |
KMLSS_NO_MEMORY |
int |
开辟内存失败。 |
依赖
#include "kml_dss.h"或#include "kml_solver.h"
示例
int n = 8; int ia[9] = {0, 2, 4, 6, 7, 8, 10, 12, 14}; int ja[14] = {0, 7, 1, 6, 2, 5, 3, 4, 2, 5, 1, 6, 0, 7}; double a[14] = {1.0, 2.0, -2.0, 3.0, 3.0, 4.0, -4.0, 5.0, 4.0, -6.0, 3.0, 7.0, 2.0, 8.0}; double b[8] = {3.0, 1.0, 7.0, -4.0, 5.0, -2.0, 10.0, 10.0}; double x[8]; int nrhs = 1; int ldx = n, ldb = n; KmlSolverTask *handle; int ierr = KmlDssGenInitDI(&handle, n, a, ja, ia); if (ierr != 0) { printf("\nERROR in KmlDssGenInitDI: %d", ierr); } ierr = KmlDssGenAnalyzeDI(&handle); if (ierr != 0) { printf("\nERROR in KmlDssGenAnalyzeDI: %d", ierr); } ierr = KmlDssGenFactorizeDI(&handle); if (ierr != 0) { printf("\nERROR in KmlDssGenFactorizeDI: %d", ierr); } ierr = KmlDssGenSolveDI(&handle, nrhs, x, ldx, b, ldb); if (ierr != 0) { printf("\nERROR in KmlDssGenSolveDI: %d", ierr); } for (int i = 0; i < n; i++) { printf("%lf ", x[i]); } printf("\n");
1.000000 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000 1.000000