help-gsl
[Top][All Lists]

## Re: [Help-gsl] Same eigenvector but different eigenvalues - Why?

 From: Patrick Alken Subject: Re: [Help-gsl] Same eigenvector but different eigenvalues - Why? Date: Thu, 13 Nov 2008 10:41:37 -0700 User-agent: Mutt/1.5.17+20080114 (2008-01-14)

```Hello, when I run your code I get the following output:

eigenvalue = -0.00750388
eigenvector =
-0.499844
-0.500918
-0.500013
-0.499223
eigenvalue = 3.26739
eigenvector =
0.0411024
-0.614189
-0.189536
0.764957
eigenvalue = -5.5658
eigenvector =
0.388034
-0.609619
0.587093
-0.364851
eigenvalue = 35.7159
eigenvector =
0.773237
0.0147647
-0.60777
-0.180282

This agrees with your octave results exactly. Is it possible you
platform you are using and how you are linking your code? And
what version of GSL are you using?

Patrick

On Thu, Nov 13, 2008 at 11:00:29AM +0100, Antonio Divisato wrote:
> *Hi, I'm italian student. First of all sorry for my english.
> I have a problem when I use GSL to test an example on classical scaling:
> I have this matrix *
> A =
>
>    20.52000    1.64000  -18.08000   -4.09000
>     1.64000   -0.83000    2.05000   -2.87000
>   -18.08000    2.05000   11.39000    4.63000
>    -4.09000   -2.87000    4.63000    2.33000
>
> *and I want the eigendecomposition. So I write this code:*
>
> int main(void) {
>
>     int i=0, j=0;
>     double nm;
>
> gsl_vector *eval;
> gsl_matrix *evec;
>
>     gsl_matrix *matr=gsl_matrix_alloc(4,4);
>     gsl_matrix_set(matr,0,0,20.52);
>     gsl_matrix_set(matr,0,1,1.64);
>     gsl_matrix_set(matr,0,2,-18.08);
>     gsl_matrix_set(matr,0,3,-4.09);
>
>     gsl_matrix_set(matr,1,0,1.64);
>     gsl_matrix_set(matr,1,1,-0.83);
>     gsl_matrix_set(matr,1,2,2.05);
>     gsl_matrix_set(matr,1,3,-2.87);
>
>     gsl_matrix_set(matr,2,0,-18.08);
>     gsl_matrix_set(matr,2,1,2.05);
>     gsl_matrix_set(matr,2,2,11.39);
>     gsl_matrix_set(matr,2,3,4.63);
>
>     gsl_matrix_set(matr,3,0,-4.09);
>     gsl_matrix_set(matr,3,1,-2.87);
>     gsl_matrix_set(matr,3,2,4.63);
>     gsl_matrix_set(matr,3,3,2.33);
>
>
>    eval = gsl_vector_alloc(4);
>    evec = gsl_matrix_alloc(4,4);
>     gsl_eigen_symmv_workspace *w = gsl_eigen_symmv_alloc(4);
>     gsl_eigen_symmv(matr,eval,evec,w);
>     gsl_eigen_symmv_free (w);
>
>    gsl_eigen_symmv_sort(eval,evec,GSL_EIGEN_SORT_ABS_ASC);
>
> for (i = 0; i < 4; i++)
>            {
>              double eval_i
>                 = gsl_vector_get (eval, i);
>              gsl_vector_view evec_i
>                 = gsl_matrix_column (evec, i);
>
>              printf ("eigenvalue = %g\n", eval_i);
>              printf ("eigenvector = \n");
>              gsl_vector_fprintf (stdout,
>                                  &evec_i.vector, "%g");
>            }
> return 0;
> }
>
> The problem is that I have this result:
> eigenvalue = -3.28845e-15
> eigenvector =
> -0.5
> -0.5
> -0.5
> -0.5
> eigenvalue = -6.53416
> eigenvector =
> 0.0405866
> -0.614856
> -0.190051
> 0.76432
> eigenvalue = 11.1461
> eigenvector =
> 0.387874
> -0.609699
> 0.586947
> -0.365121
> eigenvalue = -71.4219
> eigenvector =
> 0.773244
> 0.0147966
> -0.607761
> -0.180279
> *
> While my book and OCTAVE says:*
>
> octave-3.0.0:3> A=[20.52 1.64 -18.08 -4.09; 1.64 -0.83 2.05 -2.87; -18.08
> 2.05 11.39 4.63; -4.09 -2.87 4.63 2.33]
> A =
>
>    20.52000    1.64000  -18.08000   -4.09000
>     1.64000   -0.83000    2.05000   -2.87000
>   -18.08000    2.05000   11.39000    4.63000
>    -4.09000   -2.87000    4.63000    2.33000
>
> octave-3.0.0:4> [EVECT,EVAL]=eig(A)
> EVECT =
>
>   -0.388034   0.499844  -0.041102  -0.773237
>    0.609619   0.500918   0.614189  -0.014765
>   -0.587093   0.500013   0.189536   0.607770
>    0.364851   0.499223  -0.764957   0.180282
>
> EVAL =
>
>    -5.56580    0.00000    0.00000    0.00000
>     0.00000   -0.00750    0.00000    0.00000
>     0.00000    0.00000    3.26739    0.00000
>     0.00000    0.00000    0.00000   35.71592
>
> *So I have the same eigenvector but different eigenvalues. Why? Can you help
> me?*
>
> Bye
> Antonio Divisato
> _______________________________________________
> Help-gsl mailing list