I have a task in which I have to solve a system of linear equations Ax =B, where A is a sparse matrix of the order of 10000. I am using csparse to solve it. In my initial implementation, for demo purposes A is 3*3 order identity matrix and B ={1,2,3}. Below is the code snippet, which is returning 0 in the status which means there is some error in my implementation. What is that I am doing wrong ?
cs A;
int N = 3;
double b[]={1,2,3};
double data[]={1,1,1};
int columnIndices[]={0,1,2};
int 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;
int status = cs_cholsol(0,&A,&b[0]);
NSLog(@"status=%d",status); // status always returns 0, which means error
Matrix A above is in matrix tripplet form. First we need to convert it to compressed column format (B) and then apply the cs_chsol function to get the results.
// Convert matrix tripplet to column compressed form
I implemented it in my program and everything is running perfectly fine now.