Hello,
I'm developing a program to calculate the eigenvalues of an NxN matrix.
I ended up opting to use the GSL-GNU library Sciefic library (GSL - GNU Scientific Library - GNU Project - Free Software Foundation)
I've never used libraries like that, but I followed the tutorial and it worked.
To do the tests I am using two 2x2 arrays that I know the correct results of the eigenvalues to then enlarge and use for any NxN array.
But the program I did is giving segmentation error.
the code is:
Code:
#include <stdio.h>
#include <gsl/gsl_matrix.h>
#include <gsl/gsl_math.h>
#include <gsl/gsl_eigen.h>
double data[] = { -2.037381e-003, -1.329865e-003,-3.280068e-003, 5.025134e-003};
// double data[] = { -2.037381e-003, 2.037381e-003, 5.025134e-003,-5.025134e-003};
int main(int argc, char ** argv){
int i, j;
gsl_matrix_view m = gsl_matrix_view_array (data, 2, 2);
for(i = 0; i < 2; i++)
for(j = 0; j < 2; j++)
printf ("m(%d,%d) =%g\n", i, j,gsl_matrix_get (&m, i, j));
gsl_vector *eval = gsl_vector_alloc (2);
gsl_matrix *evec = gsl_matrix_alloc (2, 2);
gsl_eigen_nonsymmv_workspace *w = gsl_eigen_nonsymmv_alloc (2);
gsl_eigen_nonsymmv (&m.matrix, eval, evec, w);
gsl_eigen_nonsymmv_free (w);
gsl_eigen_nonsymmv_sort (eval, evec,GSL_EIGEN_SORT_ABS_DESC);
for(i = 0; i < 2; 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;
}
when the program is running in the command: gsl_eigen_nonsymmv
it returns me this error; Targeting failure (recorded core image)
Would anyone know what the problem was?
Anyway I accept suggestions from other libraries or codes to solve my problem.
In advanced, thank you very much.