【发布时间】:2014-02-06 20:06:06
【问题描述】:
我正在尝试使用 clapack 求解线性方程组。
我的代码如下:
//ATTENTION: matrix in column-major
double A[3*3]={ 2.0, -1.0, 0.0,
0.0, 2.0, -1.0,
0.0, 0.0, 2.0},
b[3]={1.0,2.0,3.0};
integer n=3,info,nrhs=1; char uplo='L';
dpotrf_("L", &n, A, &n, &info);
dpotrs_("L", &n, &nrhs, A, &n, b, &n, &info);
printf("Solution: %10.4f %10.4f %10.4f",b[0], b[1], b[2]);
正如this question 中所问的,有必要首先对矩阵进行因式分解。 dpotrf 应该是因式分解,dpotrs 使用分解后的矩阵求解系统。
但是,我的结果
2.5 4.0 3.5
明显错了,我这里查了with WolframAlpha
我的错误在哪里?
【问题讨论】:
标签: c linear-algebra lapack