## eigen vector solving with dsyev driver routine.

Open discussion regarding features, bugs, issues, vendors, etc.

### eigen vector solving with dsyev driver routine.

Hi all..
I'm novice for Lapack.. now i'm trying to solve principal compoent analysis(PCA) with dsyev driver routine.
i use clapack on windows with VC++6.0

i hope making a pca routine like pcacov or princomp in matlab.
with dsyev routine the eigen values produce properly, but in eigen vectors is not same as matlab results.

Q1. 3*3 sysmetric matrix
input matrix A = cov(A) in matlab
1.3333 1.6667 5.6667
1.6667 14.3333 26.3333
5.6667 26.3333 54.3333

* results of matlab pcacov(A)
ans =
-0.0871 0.6257 0.7752
-0.4416 -0.7218 0.5330
-0.8930 0.2959 -0.3392
* results of dsyev routine of A
ans =
0.7752 0.6257 -0.0871
0.5330 -0.7218 -0.4416
-0.3392 0.2959 -0.8930
==> this time col1,col3 switched. Why?

Q2. 4*4 sysmetric matrix
input matrix A = cov(A) in matlab
1.5600 0.7100 0.7100 1.8700
0.7100 1.4633 1.4633 -3.0433
0.7100 1.4633 1.4633 -3.0433
1.8700 -3.0433 -3.0433 15.5433

* results of matlab pcacov(A)
ans=
-0.0969 -0.6817 0.4924 -0.5324
0.2011 -0.5071 -0.8246 -0.1499
0.2011 -0.5071 0.2137 0.8104
-0.9538 -0.1446 -0.1788 0.1934

* results of dsyev routine of A
ans =
-0.2545 0.6791 0.6817 -0.0969
0.8200 -0.1731 0.5071 0.2011
-0.5043 -0.6693 0.5071 0.2011
0.0924 -0.2467 0.1446 0.9538
=> this time just col3,col4 switched. col1,col2 is not same. Why?

I use jobz='V', uplo='L' and working arrary size=3*N.
the result of INFO value is 0..

Q3. am i right using dsyev routine to get eigen value & eigen vectors?
if not, could you show me the way?

thanks for all^^..
hifiverhee

Posts: 3
Joined: Tue Apr 25, 2006 6:34 am

Denote the spectral factorization of A as

A = Q S Q^T,

where S is the diagonal matrix of eigenvalues and Q is the orthogonal matrix whose columns are the eigenvectors.

Then DSYEV produces an S whose diagonal elements are in ascending order, whereas, I presume, that pcacov produces an S whose diagonal elements are in descending order. If you try the MATLAB function eig you will see that it produces the same output as you achieved for DSYEV.

So you need to permute the output from DSYEV if you wish to have the columns of Q corresponding to the eigenvalues in descending order.

A = (Q P) (P^T S P) (Q P)^T,

where P is the permutation matrix.

In your second example you have two (nearly) equal eigenvalues. Eigenvectors corresponding to equal eigenvectors are not unique. Think of the unit matrix for which any vector is an eigenvector (I x = 1 x for any x). The two relevant columns from pcacov and DSYEV span the same subspace.

Hope that helps. Best wishes,

Sven Hammarling.
sven

Posts: 146
Joined: Wed Dec 22, 2004 4:28 am

without your help,i couldn't know my misunderstanding of eigen vectors and values including ordering difference between matlab and dsyev routine.

if my another question doesn't bother you much(i hope^^) i want to give one more question to lapack users.

Q1. From my 2nd question considering the acending order of dsyev routine
* results of matlab pcacov(A)
ans=
-0.0969 -0.6817 0.4924 -0.5324
0.2011 -0.5071 -0.8246 -0.1499
0.2011 -0.5071 0.2137 0.8104
-0.9538 -0.1446 -0.1788 0.1934

* results of dsyev routine of A
ans =
-0.2545 0.6791 0.6817 -0.0969
0.8200 -0.1731 0.5071 0.2011
-0.5043 -0.6693 0.5071 0.2011
0.0924 -0.2467 0.1446 -0.9538(omitted - sign...^^;)

dsyev produce same results compared to pcacov mathlab routine.
except for difference sign of second eigen vectors.

-0.0969 -0.6817 <---> 0.6817 -0.0969
0.2011 -0.5071 <---> 0.5071 0.2011
0.2011 -0.5071 <---> 0.5071 0.2011
-0.9538 -0.1446 <---> 0.1446 -0.9538

how can i understand the sign difference of second eigen vector?
how does it affect to produce second principal components?

thanks sven and lapack users..

ps. sorry for missing my name. my name is hokyoung
thanks.
hifiverhee

Posts: 3
Joined: Tue Apr 25, 2006 6:34 am

Dear hokyoung,

Remember that an eigenvector is a direction and so can be multiplied by any non-zero scalar and the result is still an eigenvector.

A x = lambda x == A (alpha x) = lambda (alpha x)

DSYEV normalizes the eigenvectors so that norm(x) = 1, so alpha can only be +1 or -1.

Best wishes,

Sven.
sven

Posts: 146
Joined: Wed Dec 22, 2004 4:28 am

### thanks Sven

Dear Sven :D

with your help i could solve my problems and learned more about linear algebra..

Thanks.

from Hokyoung
hifiverhee

Posts: 3
Joined: Tue Apr 25, 2006 6:34 am