title: Compute matrix eigenvalues on gsl
body: <p>I have define a <code>mateig</code> to compute matrix eigenvalues on gsl</p>
  <pre class="lang-c prettyprint-override"><code>#include &lt;gsl/gsl_math.h&gt;                                                                                                                                                                                        #include &lt;gsl/gsl_sf.h&gt;
  #include &lt;gsl/gsl_rng.h&gt;
  #include &lt;gsl/gsl_randist.h&gt;
  #include &lt;gsl/gsl_vector.h&gt;
  #include &lt;gsl/gsl_matrix.h&gt;
  #include &lt;gsl/gsl_blas.h&gt;
  #include &lt;gsl/gsl_linalg.h&gt;
  /*
   * @brief matlab eig()
   *
   */
  static int mateig(const double *Q, int n, int m, double *eigQ){
      int i,j;
      gsl_matrix *Qm = gsl_matrix_calloc(n, m);
      gsl_vector_view eval = gsl_vector_view_array (eigQ,n);
      gsl_matrix *evec = gsl_matrix_alloc (n,m);
  
      for(i=0;i&lt;n;i++){
          for(j=0;j&lt;m;j++){
              gsl_matrix_set(Qm, i, j,  Q[i*n + j]/1.0);
          }
      }
  
      gsl_eigen_symmv_workspace * w = gsl_eigen_symmv_alloc (n);
      gsl_eigen_symmv (Qm, &amp;eval.vector, evec, w);
      gsl_eigen_symmv_free (w);
  
  
      gsl_eigen_symmv_sort (&amp;eval.vector, evec, GSL_EIGEN_SORT_VAL_DESC);
  
      gsl_matrix_free (Qm);
      gsl_matrix_free (evec);
      return 1;
  }
  </code></pre>
  <p>I have test two matrix with the output (aka <code>ref_eigQ[]</code>) of matlab function <code>eig()</code>. for example</p>
  <pre class="lang-c prettyprint-override"><code>    double Q[] = {
          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 ref_eigQ[]={ 1.500214, 0.169141, 0.006738, 0.000097 };
  </code></pre>
  <pre class="lang-c prettyprint-override"><code>    double Q[] = {
          1.0000,    0.5000 ,   0.3333  ,  0.2500,
          0.5000,    1.0000 ,   0.6667  ,  0.5000,
          0.3333,    0.6667 ,   1.0000  ,  0.7500,
          0.2500,    0.5000 ,   0.7500  ,  1.0000
      };
      double ref_eigQ[]={
          2.536162474486201,
          0.848229155477913,
          0.407832884117875,
          0.207775485918012
      };          
  </code></pre>
  <p>But it did not work with this matrix</p>
  <pre class="lang-c prettyprint-override"><code>    double Q[] = {
          1,2,3,
          2,1,3,
          3,2,1}; //det = 12
      double ref_eigQ[]={ 6,-1,-2 };
  </code></pre>
  <p>But <code>mateig()</code> return <code>[ 5.701562, -0.701562,-2]</code>. I do not know why. Plz help me. Thanks.</p>