This is the mail archive of the gsl-discuss@sourceware.cygnus.com mailing list for the GSL project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Eigenvalue problem i GSL?



--------->--------->--------->--------->--------->--------->--------->
Hi,
I'm trying to calculate the eigenvalues from this matrix:

   | -3.34   1.596 |
a =|               |
   | -1.596  3.512 |

and if I haven't done anything wrong, gsl_eigen_jacobi returns:

-3.69351 and 3.86551

The prblem is that this is the wrong answer, according to Matlab, and
 my hp-48 calculator, which both gets:    -0.2946 and 0.3118

Here is my testing code:

#include <stdio.h>
#include <gsl_matrix.h>
#include "gsl_eigen.h"

int main ()
{
  int i,j, nrot;

  gsl_matrix * a = gsl_matrix_alloc(2, 2);
  gsl_vector * eigval = gsl_vector_alloc (2);
  gsl_matrix * eigvt  = gsl_matrix_alloc (2, 2);

  gsl_matrix_set(a, 0, 0, -3.34);
  gsl_matrix_set(a, 0, 1, 1.596);
  gsl_matrix_set(a, 1, 0, -1.596);
  gsl_matrix_set(a, 1, 1, 3.512);

  /* Testing, testing */
  for (i = 0 ; i < 2 ; i++)
    for (j = 0 ; j < 2 ; j++)
      printf("a(%d,%d) = %g\n",i,j, gsl_matrix_get (a, i, j));

  gsl_eigen_jacobi_impl( a, eigval, eigvt, 1000, &nrot);

  printf("Eigenvalues: %g and %g\n", gsl_vector_get( eigval, 0),
                                     gsl_vector_get( eigval, 1));

  return 0;
}

Is this a bug in GSL, or have I done something wrong?

regs,
Øystein



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]