示例#1
0
文件: eigen.cpp 项目: jimianelli/admb
/** Eigenvalues.
  \param m Input matrix (unchanged on return).
  \return Vector of eigenvalues.
*/
dvector eigenvalues(const dmatrix& m)
{
  if (m.rowsize()!=m.colsize())
  {
    cerr << "error -- non square matrix passed to "
    "dvector eigen(const dmatrix& m)\n";
    ad_exit(1);
  }
  dmatrix m1=symmetrize(m);
  m1.colshift(1);     // set minimum column and row indices to 1
  m1.rowshift(1);
  int n=m1.rowsize();
  dvector diag(1,n);
  dvector off_diag(1,n);

  tri_dag(m1,diag,off_diag);

  get_eigen(diag,off_diag,m1); // eigenvalues are returned in diag
           // eigenvalues are returned in columns of z
  return diag;
}
示例#2
0
文件: PCA.c 项目: napean/Compufis
int main (int argc, char** argv)
{
 
  FILE *in;
  in = fopen(argv[1], "r");

  int n_rows;
  int n_columns;

  n_columns = 3;
  n_rows  = contarlineas(argv[1]);

  gsl_matrix *matriz = gsl_matrix_calloc (n_rows, n_columns);
  gsl_matrix* comatriz = gsl_matrix_calloc ( n_columns,  n_columns);
  gsl_matrix* eigenvectors = gsl_matrix_calloc ( n_columns,  n_columns);
  gsl_vector* eigenvalues = gsl_vector_calloc ( n_columns );

  gsl_matrix_fscanf (in, matriz);
  matrizcovariansa (matriz,  n_columns, n_rows,  comatriz);
  get_eigen ( comatriz , eigenvalues, eigenvectors,  n_columns);
  creararch (eigenvectors);

}