The following code:
using namespace Eigen;
using namespace std;
SparseMatrix<double> A(3, 3);
for (int i = 0; i < 3; ++i)
A.insert(i,i) = 1.0;
VectorXd b = VectorXd::Zero(3);
VectorXd x = ConjugateGradient< SparseMatrix<double> >().compute( A ).solve( b );
cout << x << endl;
produces the following output:
Reason: the CG implementation doesn't check if the initial residual is already zero and then divides by zero. I think at least some other iterative solvers suffer from the same problem.
Thanks for the report.
I push a fix in the devel branch
date: 2013-03-20 11:22:45
summary: Handle zero right hand side in CG and GMRES
affected #: 2 files
Thank you, looks good!
Can you also check BiCGStab, I think it has the same issue?
A more subtle issue is that if a (non-zero) guess is given and it already solves the linear problem, then the same problems will happen.
The new commit address the subtle issue as well :
date: 2013-03-20 16:15:18
summary: Bug567 : Fix iterative solvers to immediately return when the initial guess is the true solution and for trivial solution
affected #: 4 files
Let us know if it fixes the issue.