source: util/src/diagonalize.c@ e78824

Last change on this file since e78824 was e08f45, checked in by Frederik Heber <heber@…>, 17 years ago

Merge branch 'ConcaveHull' of ../espack2 into ConcaveHull

Conflicts:

molecuilder/src/boundary.cpp
molecuilder/src/boundary.hpp
molecuilder/src/builder.cpp
molecuilder/src/linkedcell.cpp
molecuilder/src/linkedcell.hpp
molecuilder/src/vector.cpp
molecuilder/src/vector.hpp
util/src/NanoCreator.c

Basically, this resulted from a lot of conversions two from spaces to one tab, which is my standard indentation. The mess was caused by eclipse auto-indenting. And in espack2:ConcaveHull was the new stuff, so all from ConcaveHull was replaced in case of doubt.
Additionally, vector had ofstream << operator instead ostream << ...

  • Property mode set to 100755
File size: 1.3 KB
Line 
1/** Diagonlizes a 3x3 matrix.
2 * Most of here comes from the GSL example
3 */
4
5#include <stdio.h>
6#include <gsl/gsl_math.h>
7#include <gsl/gsl_eigen.h>
8
9int main(int argc, char **argv)
10{
11 double matrix[9];
12 int i;
13
14 if (argc < 9) {
15 printf("Usage: %s <9 entries of 3x3 matrix>\n", argv[0]);
16 return 1;
17 } else {
18 for(i=0;i<9;i++)
19 matrix[i] = atof(argv[i+1]);
20 }
21
22 gsl_matrix_view m
23 = gsl_matrix_view_array (matrix, 3, 3);
24
25 gsl_vector *eval = gsl_vector_alloc (3);
26 gsl_matrix *evec = gsl_matrix_alloc (3, 3);
27
28 gsl_eigen_symmv_workspace * w =
29 gsl_eigen_symmv_alloc (4);
30
31 gsl_eigen_symmv (&m.matrix, eval, evec, w);
32
33 gsl_eigen_symmv_free (w);
34
35 gsl_eigen_symmv_sort (eval, evec,
36 GSL_EIGEN_SORT_ABS_ASC);
37
38 {
39 for (i = 0; i < 3; i++)
40 {
41 double eval_i
42 = gsl_vector_get (eval, i);
43 gsl_vector_view evec_i
44 = gsl_matrix_column (evec, i);
45
46 fprintf (stderr, "eigenvalue = %g\n", eval_i);
47 fprintf (stderr, "eigenvector = \n");
48 gsl_vector_fprintf (stderr,
49 &evec_i.vector, "%g");
50 }
51 }
52 fprintf (stdout, "eigenvalues: %lg\t%lg\t%lg\n", gsl_vector_get (eval, 0), gsl_vector_get (eval, 1), gsl_vector_get (eval, 2));
53
54 gsl_vector_free (eval);
55 gsl_matrix_free (evec);
56
57
58 return 0;
59}
Note: See TracBrowser for help on using the repository browser.