Hi,
I am trying to find eigenvalues of the simple 2x2 matrix
-2 2
-10 7
It seems to me that the eigenvalues must be {2,3}.
When I implement GSL library code to compute this I have a weird result.
Please, find enclosed a minimalistic code for the problem.
I use gsl_eigen.h and gsl_matrix.h files.
I set up the matrix like
double jac[]={-2,2,-10,7};
gsl_matrix_view jacmat=gsl_matrix_view_array(jac,DIM,DIM);
where DIM=2 and jacmat.matrix contains the gsl_matrix object.
The output of the program is the reconstructed original matrix and the
eigenvalues. Here what I have:
Jacmat=
-2 2
-10 7
Eigen values: -8.46586 13.4659
It seems to me I am doing everything according to the examples in GSL
manuals. Please help.
P.S. I want to introduce this algorithm in bigger program with bigger
matrices I am just making it work on simpler ones.
Thanks you in advance.
with best regards,
Ilya Potapov.
#include <gsl/gsl_matrix.h>
#include <stdio.h>
#include <gsl/gsl_eigen.h>/* For eigenvalues */
#include <gsl/gsl_matrix.h>
//#include <gsl/gsl_linalg.h>
//#include <gsl/gsl_permutation.h>
int main()
{
int DIM=2;
int i,j;
gsl_eigen_symmv_workspace *w=gsl_eigen_symmv_alloc(DIM);
double jac[]={-2,2,-10,7};
gsl_matrix_view jacmat=gsl_matrix_view_array(jac,DIM,DIM);
gsl_vector *eval=gsl_vector_alloc(DIM);
gsl_matrix *evec=gsl_matrix_alloc(DIM,DIM);
gsl_eigen_symmv(&jacmat.matrix,eval,evec,w);
printf("Jacmat=\n");
for(i=0;i<DIM;i++){
for(j=0;j<DIM;j++)
printf("%G ",gsl_matrix_get(&jacmat.matrix,i,j));
printf("\n");
}
printf("Eigen values: ");
for(i=0;i<DIM;i++)
printf("%G ",gsl_vector_get(eval,i));
printf("\n");
/* Freeing the memory */
gsl_vector_free(eval);
gsl_matrix_free(evec);
gsl_eigen_symmv_free(w);
return 0;
}