Registered Member
|
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 |
Moderator
|
This is because your matrix is not positive definite, which is a requirement for CG. Either use SimplicialLDLT or BICGSTAB.
|
Registered Member
|
Thanks a lot.
So, what can I do if my matrix is not positive definite? |
Moderator
|
Registered users: Bing [Bot], Evergrowing, Google [Bot], rockscient