This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Wrong result using SimplicialLDLt

Tags: None
(comma "," separated)
guibencke
Registered Member
Posts
3
Karma
0

Wrong result using SimplicialLDLt

Wed Jan 25, 2012 6:25 pm
Hi,
I'm using SimplicialLDLt to solve a sparse linear system, but I'm not getting right results. My code looks like the following excerpt:
Code: Select all
   MappedSparseMatrix<double, RowMajor> mat(dim, dim, nnz_lin * dim, rowPtr, colInd, nonZero);

   Matrix<double, Dynamic, 1> b(dim), x(dim);
   for (int i = 0; i < dim; i++)
      b(i) = 1;

   SimplicialLDLt<SparseMatrix<double>> solver;
   solver.compute(mat);
   x = solver.solve(b);

I'm converting the sparse matrix to dense and printing it, and the values are fine. What am I doing wrong?
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
How is mat? is it really selfadjoint? does it store all coefficients? only the lower half? only the upper half? Then you should check the success of each step:
solver.compute(mat);
if(!solver.info()==Success) {...}
x = solver.solve(b);
if(!solver.info()==Success) {...}
guibencke
Registered Member
Posts
3
Karma
0
The test matrix I'm using is the following:
Code: Select all
mat =
     0     1     2     0     0
     0     3     4     5     0
     0     0     6     7     8
     9     0     0    10    11
    12    13     0     0    14

It's being solved fine by Matlab and by a SuperLU routine that I've written some time ago. The solver.info() is ok too.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
this matrix is not symmetric, so you cannot solve it with a Cholesky factorization.
guibencke
Registered Member
Posts
3
Karma
0

Re: Wrong result using SimplicialLDLt

Wed Feb 01, 2012 12:45 pm
Yes, that's right.
Now I'm trying to solve it with the BiCGSTAB method, but I'm getting the following error:
Unhandled exception at 0x0041751f in eigen_test.exe: 0xC0000005: Access violation reading location 0x00846838.
In the following line, when I call solver.solve(b):
Code: Select all
else if(RhsIsVector)              dest.coeffRef(it.index()) += it.value() * rhs_j;
in SparseDenseProduct.h

My code looks like the following:
Code: Select all
   colInd = new int[nnz_lin * dim];
   rowPtr = new int[dim + 1];
   nonZero = new double[nnz_lin * dim];
   GenSquareMatrix(dim, nnz_lin, nonZero, rowPtr, colInd);
   PrintMatrix(dim, nnz_lin, nonZero, rowPtr, colInd);

   MappedSparseMatrix<double, ColMajor> mat(dim, dim, nnz_lin * dim, rowPtr, colInd, nonZero);
   MatrixXd m = mat.toDense();
   //Print it and check if the values are ok

   VectorXd b(dim), x(dim);
   for (int i = 0; i < dim; i++)
      b(i) = 1;

   BiCGSTAB<SparseMatrix<double>> solver;
   solver.compute(mat);
   if(!solver.info()==Success) {cout << "Error on compute(mat)";}
   x = solver.solve(b);
   if(!solver.info()==Success) {cout << "Error on solve(b)";}

Thanks a lot,
Guilherme.


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]