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
You have to convert your input matrix to CSC. The solver functions check for the matrix format and return 0 if it's coordinate form. Btw. with a similar example I couldn't get "cholsol" to work, but "lsolve" works fine (after conversion to CSC).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With