Discussion:
[petsc-users] How to get the eigenvectors in Slepc
Sonya Blade
12 years ago
Permalink
Dear all,

I experience a difficulty with retrieving the eigenvectors 
obtained after eigen solution of generalized eigenvalue A*X=lambda*B*X
problem.The Slepc nicely finds the eigenvalues but doesn't retrieve the 
eigenvectors after calling the EPSGetEigenvector(eps,1,vec,vec1). I also 
tried the EPSGetEigenpairs function but neither of them 

I attach the main program codes.

Your help will be appreciated.

Regards,
Hong Zhang
12 years ago
Permalink
Sonya :
Test slpec example first, e.g.,
slepc-3.3-p3/src/eps/examples/tutorials>grep GetEigenvector *.c
ex12.c: ierr = EPSGetEigenvector(eps,i,X[i],PETSC_NULL);CHKERRQ(ierr);
ex12.c: ierr =
EPSGetEigenvectorLeft(eps,i,Y[i],PETSC_NULL);CHKERRQ(ierr);
ex7.c: ierr = EPSGetEigenvector(eps,i,xr,xi);CHKERRQ(ierr);

i.e., ex7.c and ex12.c call EPSGetEigenvector().

Hong

Dear all,
>
> I experience a difficulty with retrieving the eigenvectors
> obtained after eigen solution of generalized eigenvalue A*X=lambda*B*X
> problem.The Slepc nicely finds the eigenvalues but doesn't retrieve the
> eigenvectors after calling the EPSGetEigenvector(eps,1,vec,vec1). I also
> tried the EPSGetEigenpairs function but neither of them
>
> I attach the main program codes.
>
> Your help will be appreciated.
>
> Regards,
Sonya Blade
12 years ago
Permalink
Thank you Hong,

I already looked at those examples after not achieving the successful
results I decide to share it. It seems that I don't know how to read 
values from the vectors, EPSGetEigenvector(eps,1,vec,PETSC_NULL); retrieves
no errors which I assume that it returns the eigenvectors to corresponding 
eigenvalue(which is second in my case).

I use following notation to read values from vectors,  here I'm not sure 
whether the "&vec[i] or vec[i]"  can be used to read the values from vector. 

Vec vec;

for (i=0;i<9;i++)
  {
    PetscPrintf(MPI_COMM_WORLD," %3
Matthew Knepley
12 years ago
Permalink
On Sat, Apr 13, 2013 at 11:34 AM, Sonya Blade <***@hotmail.com>wrote:

> Thank you Hong,
>
> I already looked at those examples after not achieving the successful
> results I decide to share it. It seems that I don't know how to read
> values from the vectors, EPSGetEigenvector(eps,1,vec,PETSC_NULL); retrieves
> no errors which I assume that it returns the eigenvectors to corresponding
> eigenvalue(which is second in my case).
>
> I use following notation to read values from vectors, here I'm not sure
> whether the "&vec[i] or vec[i]" can be used to read the values from
> vector.
>
> Vec vec;
>
> for (i=0;i<9;i++)
> {
> PetscPrintf(MPI_COMM_WORLD," %3.8f: ",&vec[i] );
> }
>

Read the Manual chapter on Vectors.

Matt


> Regards,




--
What most experimenters take for granted before they begin their
experiments is infinitely more interesting than any results to which their
experiments lead.
-- Norbert Wiener
Sonya Blade
12 years ago
Permalink
Dear All,

If I have all eigenvalues as real numbers is it possible mathematically that 
I get the complex eigenvectors? Because nowhere in my solution I obtain the 
complex eigenvalues but Slepc returns the complex for eigenvectors.

Your enlightenment will be appreciated.

Regards,
Jose E. Roman
12 years ago
Permalink
El 14/04/2013, a las 08:04, Sonya Blade escribió:

> Dear All,
>
> If I have all eigenvalues as real numbers is it possible mathematically that
> I get the complex eigenvectors? Because nowhere in my solution I obtain the
> complex eigenvalues but Slepc returns the complex for eigenvectors.
>
> Your enlightenment will be appreciated.
>
> Regards,

If the eigenvector is complex then of course the eigenvalue is complex as well (I assume your matrix is real non-symmetric). You have to get both the real and imaginary parts of the eigenvalue.
http://www.grycap.upv.es/slepc/documentation/current/docs/manualpages/EPS/EPSGetEigenpair.html

An alternative is to do all the computation in complex arithmetic (configure --with-scalar-type=complex).

Jose
z***@yahoo.com.cn
12 years ago
Permalink
Dear Roman:
   Could you please tell me how to ask questions in mailing list. i have put one question to petsc-***@mcs.anl.gov, but i get nothing feedback
 
 



>________________________________
> 发件人 Jose E. Roman <***@dsic.upv.es>
>收件人 PETSc users list <petsc-***@mcs.anl.gov>
>发送日期 2013幎4月14日, 星期日, 10:44 䞋午
>䞻题: Re: [petsc-users] How to get the eigenvectors in Slepc
>
>
>
>El 14/04/2013, a las 08:04, Sonya Blade escribió:
>
>> Dear All,
>>
>> If I have all eigenvalues as real numbers is it possible mathematically that
>> I get the complex eigenvectors? Because nowhere in my solution I obtain the
>> complex eigenvalues but Slepc returns the complex for eigenvectors.
>>
>> Your enlightenment will be appreciated.
>>
>> Regards,                        
>
>If the eigenvector is complex then of course the eigenvalue is complex as well (I assume your matrix is real non-symmetric). You have to get both the real and imaginary parts of the eigenvalue.
>http://www.grycap.upv.es/slepc/documentation/current/docs/manualpages/EPS/EPSGetEigenpair.html
>
>An alternative is to do all the computation in complex arithmetic (configure --with-scalar-type=complex).
>
>Jose
>
>
>
>
Jose E. Roman
12 years ago
Permalink
El 17/04/2013, a las 02:12, ***@yahoo.com.cn escribió:

> Dear Roman:
> Could you please tell me how to ask questions in mailing list. i have put one question to petsc-***@mcs.anl.gov, but i get nothing feedback
>

Do you mean your question on March 3? Matt replied, here is the answer:
https://lists.mcs.anl.gov/mailman/htdig/petsc-users/2013-March/016530.html

Answers are sent to the list, so you must be suscribed to receive the answer.

Jose
Sonya Blade
12 years ago
Permalink
>If the eigenvector is complex then of course the eigenvalue is complex as well >(I assume your matrix is real non-symmetric). You have to get both the real and >imaginary parts of the eigenvalue.>http://www.grycap.upv.es/slepc/documentation/current/docs/manualpages/EPS/EPSGetEigenpair.html>An alternative is to do all the computation in complex arithmetic (configure --with-scalar-type=complex).>Jose
Hi Jose,
Probably you misunderstood my question my problem is: ierr = EPSGetEigenvalue(eps,i,&eigen_r,&eigen_i);CHKERRQ(ierr);returns all eigenvalues for each iteration where there is no imaginary parts (and set to zeros in eigen_i as expected).
I cross checked that with another algorithm which proves that all the eigenvalues are correct (no imaginary parts),but glitch is with trying to fetch the eigenvectors. Eigenvectors obtained from the code below are mostly filled with zeros and only the 11th row(Slepc returns 11 eigenvalue) has real and imaginary part which is not possible.
for (j=0;j<test_int;j++)
{
ierr = EPSGetEigenvector(eps,j,&vec[0],&vec1[0]);CHKERRQ(ierr);
PetscPrintf(MPI_COMM_WORLD," %d || %4.8f || %4.8f \n",j,vec[j],vec1[j]);
} I also provide you the main code and required files.
Your help will be appreciated,
Regards,
Jose E. Roman
12 years ago
Permalink
El 14/04/2013, a las 17:11, Sonya Blade escribió:

> >If the eigenvector is complex then of course the eigenvalue is complex as well
> >(I assume your matrix is real non-symmetric). You have to get both the real and >imaginary parts of the eigenvalue.
> >http://www.grycap.upv.es/slepc/documentation/current/docs/manualpages/EPS/EPSGetEigenpair.html
> >An alternative is to do all the computation in complex arithmetic (configure --with-scalar-type=complex).
> >Jose
>
> Hi Jose,
>
> Probably you misunderstood my question my problem is: ierr = EPSGetEigenvalue(eps,i,&eigen_r,&eigen_i);CHKERRQ(ierr);
> returns all eigenvalues for each iteration where there is no imaginary parts (and set to zeros in eigen_i as expected).
>
> I cross checked that with another algorithm which proves that all the eigenvalues are correct (no imaginary parts),but
> glitch is with trying to fetch the eigenvectors. Eigenvectors obtained from the code below are mostly filled with zeros
> and only the 11th row(Slepc returns 11 eigenvalue) has real and imaginary part which is not possible.
>
>
> for (j=0;j<test_int;j++)
> {
> ierr = EPSGetEigenvector(eps,j,&vec[0],&vec1[0]);CHKERRQ(ierr);
> PetscPrintf(MPI_COMM_WORLD," %d || %4.8f || %4.8f \n",j,vec[j],vec1[j]);
> }
>
>
> I also provide you the main code and required files.
>
> Your help will be appreciated,
>
> Regards,
> <main.c><IN.txt><mass.txt>


As Matt said, read the manual section on vectors. Page 43 "Basic Vector operations":

"On occasion, the user needs to access the actual elements of the vector. The routine VecGetArray() returns a pointer to the elements local to the process:
VecGetArray(Vec v,PetscScalar **array);
When access to the array is no longer needed, the user should call
VecRestoreArray(Vec v, PetscScalar **array);
"

Then have a look at any of the examples, for instance those listed here
http://www.mcs.anl.gov/petsc/petsc-3.3/docs/manualpages/Vec/VecGetArray.html

Please read the documentation. We cannot develop your code for you.

Jose
Sonya Blade
12 years ago
Permalink
> As Matt said, read the manual section on vectors. Page 43 "Basic Vector operations":
>
> "On occasion, the user needs to access the actual elements of the vector. The routine VecGetArray() returns a pointer to the elements local to the process:
> VecGetArray(Vec v,PetscScalar **array);
> When access to the array is no longer needed, the user should call
> VecRestoreArray(Vec v, PetscScalar **array);
> Then have a look at any of the examples, for instance those listed here
> http://www.mcs.anl.gov/petsc/petsc-3.3/docs/manualpages/Vec/VecGetArray.html
> Please read the documentation. We cannot develop your code for you.
> Jose

Thanks in advance,
I'm already reading those manuals Petsc,Slepc, online Petsc/Slepc documents are always open in my browser.But it seems it really take times to get used to it, which I think that this is what I'm suffering for the time being.
Can you confirm that having all the eigenvalues as real and corresponding eigenvectors as zero and having imaginary parts is something weird. At least to confirm that I'm on a right path and this should be the point that I've to focus.
Regards,
Jose E. Roman
12 years ago
Permalink
El 14/04/2013, a las 17:53, Sonya Blade escribió:

> Thanks in advance,
>
> I'm already reading those manuals Petsc,Slepc, online Petsc/Slepc documents are always open in my browser.
> But it seems it really take times to get used to it, which I think that this is what I'm suffering for the time being.
>
> Can you confirm that having all the eigenvalues as real and corresponding eigenvectors as zero and having
> imaginary parts is something weird. At least to confirm that I'm on a right path and this should be the point
> that I've to focus.
>
> Regards,

Let me put it more clearly: you are not getting eigenvector entries, your printing statement is nonsense (you print a pointer as a floating point number), so you cannot say the imaginary part is nonzero. It is indeed zero, SLEPc gives the right solution, your program is wrong.

Jose
Sonya Blade
12 years ago
Permalink
>Let me put it more clearly: you are not getting eigenvector entries, your printing statement is 
>nonsense (you >print a pointer as a floating point number), so you cannot say the imaginary part is 
>nonzero. It is indeed >zero, SLEPc gives the right solution, your program is wrong.
>Jose

Sorry and thank you for clarifying that,
One last question, I got the correct eigenvalues, now I got the 
eigenvectors, but they differ from the exact solution. 

For example, for the first eigenvalue(2405.247) I got the following eigenvector 
set where it differ from the exact solution, what could be the possible reason of that?

Regards,
   
Row Exact Results   SLEPC RESULTS
0 0.2255511 -0.014234
1 -5.2313502 0.330131
2 3.1352583 -0.197855
3 -4.4245184 0.279215
4 0.0898345 -0.005669
5 1.9278406 -0.121659
6 0.0033757 -0.000213
7 -0.7077308 0.044662
8 0.0687009 -0.004335
9 0.1684281 -0.010629
10 -2.81293611 0.177514
11 1.93270712 -0.121966
12 -0.00306213 0.000193
13 0.88278714 -0.055709
14 -0.70857415: 0.044715
15 0.03025516: -0.001909
16 -2.81094417: 0.177388
17 1.12005518: -0.070683
18 2.73596119: -0.172656
19 0.22734020: -0.014347
20 -4.42534221: 0.279267
21 2.22134222: -0.140181
22 -5.00448323: 0.315815
23 0.17399224: -0.01098
24 2.38934725: -0.150783
25 -3.75380226: 0.236889
26 0.09633427: -0.006079
27 0.48140228: -0.03038
28 -1.52250229: 0.09608
29 -0.00132830: 0.000084
30 1.16923331: -0.073786
31 0.09701232: -0.006122
32 0.00268833: -0.00017
33 1.59855934: -0.100879
34 -3.75642735: 0.237054
35 0.13951936: -0.008805
36 1.17316037: -0.074034
37 -1.32576838: 0.083664
38 -0.00203439: 0.000128
39 0.47943940: -0.030256
40 0.09694141: -0.006118
41 0.00071442: -0.000045
42 0.14814343: -0.009349
43 -5.23126844: 0.330126
44 2.33293345: -0.147223
45 3.01784046: -0.190445
46 -5.00416947: 0.315795
47 0.17591748: -0.011101
Jose E. Roman
12 years ago
Permalink
El 15/04/2013, a las 09:22, Sonya Blade escribió:

>> Let me put it more clearly: you are not getting eigenvector entries, your printing statement is
>> nonsense (you >print a pointer as a floating point number), so you cannot say the imaginary part is
>> nonzero. It is indeed >zero, SLEPc gives the right solution, your program is wrong.
>> Jose
>
> Sorry and thank you for clarifying that,
> One last question, I got the correct eigenvalues, now I got the
> eigenvectors, but they differ from the exact solution.
>
> For example, for the first eigenvalue(2405.247) I got the following eigenvector
> set where it differ from the exact solution, what could be the possible reason of that?
>
> Regards,
>
> Row Exact Results SLEPC RESULTS
> 0 0.2255511 -0.014234
> 1 -5.2313502 0.330131
> 2 3.1352583 -0.197855
> 3 -4.4245184 0.279215
> 4 0.0898345 -0.005669
> 5 1.9278406 -0.121659
> 6 0.0033757 -0.000213
> 7 -0.7077308 0.044662
> 8 0.0687009 -0.004335
> 9 0.1684281 -0.010629
> 10 -2.81293611 0.177514
> 11 1.93270712 -0.121966
> 12 -0.00306213 0.000193
> 13 0.88278714 -0.055709
> 14 -0.70857415: 0.044715
> 15 0.03025516: -0.001909
> 16 -2.81094417: 0.177388
> 17 1.12005518: -0.070683
> 18 2.73596119: -0.172656
> 19 0.22734020: -0.014347
> 20 -4.42534221: 0.279267
> 21 2.22134222: -0.140181
> 22 -5.00448323: 0.315815
> 23 0.17399224: -0.01098
> 24 2.38934725: -0.150783
> 25 -3.75380226: 0.236889
> 26 0.09633427: -0.006079
> 27 0.48140228: -0.03038
> 28 -1.52250229: 0.09608
> 29 -0.00132830: 0.000084
> 30 1.16923331: -0.073786
> 31 0.09701232: -0.006122
> 32 0.00268833: -0.00017
> 33 1.59855934: -0.100879
> 34 -3.75642735: 0.237054
> 35 0.13951936: -0.008805
> 36 1.17316037: -0.074034
> 37 -1.32576838: 0.083664
> 38 -0.00203439: 0.000128
> 39 0.47943940: -0.030256
> 40 0.09694141: -0.006118
> 41 0.00071442: -0.000045
> 42 0.14814343: -0.009349
> 43 -5.23126844: 0.330126
> 44 2.33293345: -0.147223
> 45 3.01784046: -0.190445
> 46 -5.00416947: 0.315795
> 47 0.17591748: -0.011101

Eigenvectors are not unique. If you normalize your "exact" solution you will see that it coincides with SLEPc's answer. If you don't know what an eigenvector is, you will have a hard time using SLEPc.

Jose
Sonya Blade
12 years ago
Permalink
Even If I have normalization at the exact solution this doesn't explain
how the sign of it has changed, as a result square roots of sum of squares 
can never have negative value (vector length). 

Basically what I need to do, to get the Slepc results matching with the exact ones. 
Do I need to call any function before Slepc normalizes them
Karl Rupp
12 years ago
Permalink
Hi Sonya,

I really suggest you familiarize yourself with eigenvalues and
eigenvectors. For each eigenvector v, alpha*v is also an eigenvector to
the same eigenvalue, where alpha can be any nonzero scalar. If the sign
doesn't fit your expectations, just multiply it with -1. :-)

Best regards,
Karli


On 04/15/2013 04:02 AM, Sonya Blade wrote:
> Even If I have normalization at the exact solution this doesn't explain
> how the sign of it has changed, as a result square roots of sum of squares
> can never have negative value (vector length).
>
> Basically what I need to do, to get the Slepc results matching with the exact ones.
> Do I need to call any function before Slepc normalizes them or something else?
>
> Regards,
>
Loading...