Skip to content

Instantly share code, notes, and snippets.

@kohnakagawa
Created April 19, 2014 12:40
Show Gist options
  • Save kohnakagawa/11083366 to your computer and use it in GitHub Desktop.
Save kohnakagawa/11083366 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <cmath>
#include <gsl/gsl_math.h>
#include <gsl/gsl_vector.h>
#include <gsl/gsl_matrix.h>
#include <gsl/gsl_eigen.h>
#include <gsl/gsl_sort_vector.h>
#define DIM 2
int main(void){
gsl_matrix *matrix = gsl_matrix_alloc(DIM,DIM);
gsl_eigen_symm_workspace *workspace = gsl_eigen_symm_alloc(DIM);;
gsl_vector *eig = gsl_vector_alloc(DIM);
gsl_matrix_set(matrix,0,0,1.);
gsl_matrix_set(matrix,0,1,-0.5);
gsl_matrix_set(matrix,1,0,-0.5);
gsl_matrix_set(matrix,1,1,1.);
gsl_eigen_symm(matrix, eig, workspace);
for(int i=0; i<DIM; i++) std::cout << gsl_vector_get(eig,i) << std::endl;
gsl_vector_free(eig);
gsl_eigen_symm_free(workspace);
gsl_matrix_free(matrix);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment