Thread: eigenvalues of matrix using GSL - GNU Scientific Library

  1. #1
    Registered User
    Join Date
    Jan 2018
    Posts
    1

    eigenvalues of matrix using GSL - GNU Scientific Library

    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.

  2. #2
    Registered User
    Join Date
    Dec 2017
    Posts
    704
    It looks like you're passing real vectors and matrices where complex ones are expected. Also, I'm not sure if you can use a matrix view instead of a regular matrix.

    Aren't you getting a bunch of warnings when you compile?
    The world hangs on a thin thread, and that is the psyche of man. - Carl Jung

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Eigenvalues of matrix using dynamic allocation
    By Marwin55 in forum C Programming
    Replies: 10
    Last Post: 12-28-2015, 10:21 AM
  2. Library for Eigenvalues and Eigenvectors
    By ioan1ioan in forum C Programming
    Replies: 5
    Last Post: 03-15-2012, 09:46 PM
  3. c code for eigenvectors and eigenvalues for 4x4 matrix
    By sanjana in forum C++ Programming
    Replies: 2
    Last Post: 10-11-2011, 02:52 PM
  4. Finding Eigenvalues and Eigenvectors of a matrix
    By Zeeshan in forum C++ Programming
    Replies: 3
    Last Post: 06-13-2008, 02:50 AM
  5. Eigenvalues for 2x2 Matrix
    By dcwang3 in forum C Programming
    Replies: 18
    Last Post: 02-18-2008, 08:35 PM

Tags for this Thread