【发布时间】:2014-04-07 08:26:05
【问题描述】:
我不明白如何使用 CSparese 库在 C 中轻松表示稀疏矩阵。
这就是我想要的
| 6.0 0.0 2.0 |
A = | 3.0 8.0 0.0 |
| 6.0 0.0 1.0 |
with
| 40.0 |
b = | 50.0 |
| 30.0 |
csparse的cs结构是这样的
typedef struct cs_sparse /* matrix in compressed-column or triplet form */
{
csi nzmax ; /* maximum number of entries */
csi m ; /* number of rows */
csi n ; /* number of columns */
csi *p ; /* column pointers (size n+1) or col indices (size nzmax) */
csi *i ; /* row indices, size nzmax */
double *x ; /* numerical values, size nzmax */
csi nz ; /* # of entries in triplet matrix, -1 for compressed-col */
} cs ;
我就是这么做的
int main(int argc, const char * argv[])
{
cs A;
int N = 3;
double b[]={1,2,3};
double data[]={1,1,1};
csi columnIndices[]={0,1,2};
csi rowIndices[]={0,1,2};
A.nzmax =3;
A.m = N;
A.n = N;
A.p = &columnIndices[0];
A.i = &rowIndices[0];
A.x = &data[0];
A.nz = 3;
cs *B = cs_compress(&A);
int status = cs_cholsol(0,B,&b[0]);
printf("status=%d",status); // status always returns 0, which means error
return 0;
我要问的是如何用我的数据填充我的矩阵以及我必须使用哪种方法来解决它。
谢谢
【问题讨论】:
-
您的矩阵在实践中有多大?
-
大矩阵,例如 918*918 我发布的代码只是为了了解如何使用这个库......但我需要使用更大的矩阵
标签: c matrix linear-algebra sparse-matrix