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

Output infinity

Tags: None
(comma "," separated)
ysimpson
Registered Member
Posts
2
Karma
0

Output infinity

Mon Apr 04, 2016 5:37 am
Hi
I am testing the Eigen's sparse matrix solver to solve this simple problem:

min ||AX-B||^2
x

A =
0 0 0 -1
0 1 0 0
0 0 1 0
-1 0 0 0

B = [0 0 0 1]^T

This is my code:

void test()
{
typedef Eigen::SparseMatrix<double> SpMat; // declares a column-major sparse matrix type of double
Eigen::VectorXd b(4), x(4);
SpMat mat(4,4);

mat.insert(0, 3) = -1;
mat.insert(1, 1) = 1;
mat.insert(2, 2) = 1;
mat.insert(3, 0) = -1;
mat.makeCompressed();
b.setZero();
b(3) = 1;

Eigen::ConjugateGradient<Eigen::SparseMatrix<double>, Eigen::Upper | Eigen::Lower> solver;
x = solver.compute(mat).solve(b);
std::cout << x << std::endl;
}
But the output go to infinity:
-1.#IND
-1.#IND
-1.#IND
-1.#IND

What's wrong I using the Eigen?

Thanks

Best Regards,
Simpson
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: Output infinity

Mon Apr 04, 2016 9:37 am
This is because your matrix is not positive definite, which is a requirement for CG. Either use SimplicialLDLT or BICGSTAB.
ysimpson
Registered Member
Posts
2
Karma
0

Re: Output infinity

Mon Apr 04, 2016 10:02 am
Thanks a lot.
So, what can I do if my matrix is not positive definite?
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: Output infinity

Mon Apr 04, 2016 1:03 pm
As I wrote: "Either use SimplicialLDLT or BICGSTAB."


Bookmarks



Who is online

Registered users: Bing [Bot], Evergrowing, Google [Bot], rockscient