this is a small example from the gsl example online
I need to get the value from the "&evec_i.vector " into a 4x4 dimensional array
such that
abc[4][4]= vector elements

how can I do this ? those 16 values will create the 4x4 matrix

#include <stdio.h>
#include <gsl/gsl_math.h>
#include <gsl/gsl_eigen.h>

int main (void)
{
  double data[] = { 1.0  , 1/2.0, 1/3.0, 1/4.0,
                    1/2.0, 1/3.0, 1/4.0, 1/5.0,
                    1/3.0, 1/4.0, 1/5.0, 1/6.0,
                    1/4.0, 1/5.0, 1/6.0, 1/7.0 };

  gsl_matrix_view m  = gsl_matrix_view_array(data, 4, 4);

  gsl_vector *eval = gsl_vector_alloc (4);
  gsl_matrix *evec = gsl_matrix_alloc (4, 4);

  gsl_eigen_symmv_workspace * w =    gsl_eigen_symmv_alloc (4);
  
  gsl_eigen_symmv (&m.matrix, eval, evec, w);

  gsl_eigen_symmv_free(w);

  gsl_eigen_symmv_sort (eval, evec, GSL_EIGEN_SORT_ABS_ASC);
  
  {
    int i;

    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;
}

I don't really know, but did you try the obvious ?

for(i = 0; i < 4; ++i)
{
   for(j = 0; j < 4; ++j)
   {
        data[i][j] = gsl_matrix_column(i, j);
   }
}

Ancient Dragon:

I did a workaround the problem by printing the output of the vector to a file and then reading them into an array
sure doesnt look impressive :<

#include <stdio.h>
#include <gsl/gsl_math.h>
#include <gsl/gsl_eigen.h>

// trying to take the values of eigenvector and eigenvalues and put it in a array
     
     int main (void)
     {


  FILE *data3;

		data3 = fopen("data3.txt", "w");

		   if (data3 == NULL) 
		   {
		      printf("File doesn't exist\n");
		      exit (EXIT_FAILURE);
		   } 	

       double data[] = { 1.0  , 1/2.0, 1/3.0, 1/4.0,
                         1/2.0, 1/3.0, 1/4.0, 1/5.0,
                         1/3.0, 1/4.0, 1/5.0, 1/6.0,
                         1/4.0, 1/5.0, 1/6.0, 1/7.0 };
	double datax[4][4];
        double datay[16];
 

       gsl_matrix_view m  = gsl_matrix_view_array (data, 4, 4);
     
       gsl_vector *eval = gsl_vector_alloc (4);
       gsl_matrix *evec = gsl_matrix_alloc (4, 4);
     
       gsl_eigen_symmv_workspace * w =  gsl_eigen_symmv_alloc (4);
       
       gsl_eigen_symmv (&m.matrix, eval, evec, w);
     
       gsl_eigen_symmv_free (w);
     
//             gsl_vector_fprintf (stdout, evec.vector, "%g");

         int i,j,p=0;
     
         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 (data3, &evec_i.vector, "%g");
           }

	
       gsl_vector_free (eval);
       gsl_matrix_free (evec);
            fclose(data3);

FILE *fr;           

   int n;
   char line[80];
   float abc[10][10];
 //  int i=0,j=0;
  
   fr = fopen ("data3.txt", "r");  
   
for(i = 0; i < 4; ++i)
{
   for(j = 0; j < 4; ++j)
   {
	fgets(line, 80, fr);
         sscanf (line, "%f", &abc[i][j]);
	printf ("\n%f", abc[i][j]);	
   }
}
    printf("\n\n"); 
	
for(i = 0; i < 4; ++i)
{
   for(j = 0; j < 4; ++j)
   {
	printf ("%f ", abc[i][j]);	
   }
        printf("\n"); 
}


   fclose(fr); 

     
       return 0;
     }

You're looking in the wrong section of the manual. You don't want to create a vector view. Check out this section: http://www.gnu.org/software/gsl/manual/html_node/Accessing-matrix-elements.html

I think that this is what you seek:

double gsl_matrix_get (const gsl_matrix * m, size_t i, size_t j)

This function returns the (i,j)-th element of a matrix m. If i or j lie outside the allowed range of 0 to n1-1 and 0 to n2-1 then the error handler is invoked and 0 is returned. An inline version of this function is used when HAVE_INLINE is defined.

This article has been dead for over six months. Start a new discussion instead.