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

Conjugate Gradient

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

Conjugate Gradient

Sun Sep 29, 2013 8:04 pm
I am a newbie on the Eigen. I want to solve the sparse linear system Ax = b by using CG.
Here is my code
Code: Select all
Eigen::ConjugateGradient<Eigen::SparseMatrix<float> > cg;
cg.compute(A);
x = cg.solve(b);


A is symmetric matrix as shown below
A =
2 -1 0 0 -1 0 0 0 0 0 0 0 0 0 0 0
-1 3 -1 0 0 -1 0 0 0 0 0 0 0 0 0 0
0 -1 3 -1 0 0 -1 0 0 0 0 0 0 0 0 0
0 0 -1 2 0 0 0 -1 0 0 0 0 0 0 0 0
-1 0 0 0 3 -1 0 0 -1 0 0 0 0 0 0 0
0 -1 0 0 -1 4 -1 0 0 -1 0 0 0 0 0 0
0 0 -1 0 0 -1 4 -1 0 0 -1 0 0 0 0 0
0 0 0 -1 0 0 -1 3 0 0 0 -1 0 0 0 0
0 0 0 0 -1 0 0 0 3 -1 0 0 -1 0 0 0
0 0 0 0 0 -1 0 0 -1 4 -1 0 0 -1 0 0
0 0 0 0 0 0 -1 0 0 -1 4 -1 0 0 -1 0
0 0 0 0 0 0 0 -1 0 0 -1 3 0 0 0 -1
0 0 0 0 0 0 0 0 -1 0 0 0 2 -1 0 0
0 0 0 0 0 0 0 0 0 -1 0 0 -1 3 -1 0
0 0 0 0 0 0 0 0 0 0 -1 0 0 -1 3 -1
0 0 0 0 0 0 0 0 0 0 0 -1 0 0 -1 2

b = zeros


Actually x should be zeros, but x turns out to be not-a-number after solving by CG. I don't know why.
I use it on OS X.
Anyone know how to fix this?

Thank you in advance.
jitseniesen
Registered Member
Posts
204
Karma
2

Re: Conjugate Gradient

Tue Oct 01, 2013 8:33 am
The matrix A is singular; the vector of all ones is in the kernel. According to http://eigen.tuxfamily.org/dox-devel/gr ... stems.html , ConjugateGradient requires the matrix to be positive definite.
hesheitaa
Registered Member
Posts
2
Karma
0

Re: Conjugate Gradient

Tue Oct 01, 2013 1:31 pm
Thank you so much.
:)


Bookmarks



Who is online

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