Reputation: 426
I want to solve a sparse linear system like this:
SparseMatrix<double> A(m, n);
VectorXd b(m);
ConjugateGradient<SparseMatrix<double>, Upper> solver;
solver.compute(A);
VectorXd X = solver.solve(b);
but I got this error for running this code:
Assertion failed: (rows()==cols() && "SelfAdjointView is only for squared matrices"), function SparseSelfAdjointView
why I got this problem and how to solve it?
I write a small example to reproduce this error:
#include "lib/Eigen/Sparse"
using namespace Eigen;
int main()
{
SparseMatrix<double> A(2, 3);
A.coeffRef(0, 0) = 1;
A.coeffRef(0, 1) = 1;
A.coeffRef(0, 2) = 1;
A.coeffRef(1, 0) = 1;
A.coeffRef(1, 1) = 1;
A.coeffRef(1, 2) = 1;
VectorXd b(2);
b << 3, 3;
ConjugateGradient<SparseMatrix<double>, Upper> solver;
solver.compute(A);
VectorXd X = solver.solve(b);
return 0;
}
Upvotes: 0
Views: 160
Reputation: 18807
The ConjugateGradient
algorithm only works with self-adjoint matrices. For rectangular matrices use LeastSquaresConjugateGradient
instead.
Upvotes: 2