vnl_real_eigensystem.cxx
Go to the documentation of this file.
1 // This is core/vnl/algo/vnl_real_eigensystem.cxx
2 //:
3 // \file
4 //
5 // \author Andrew W. Fitzgibbon, Oxford RRG
6 // \date 23 Jan 97
7 
8 //-----------------------------------------------------------------------------
9 
10 #include <iostream>
11 #include <cassert>
12 #include "vnl_real_eigensystem.h"
13 #include <vnl/vnl_fortran_copy.h>
14 #include <vnl/algo/vnl_netlib.h> // rg_()
15 
16 //: Extract eigensystem of non-symmetric matrix M, using the EISPACK routine rg.
17 // Should probably switch to using LAPACK's dgeev to avoid transposing.
19  Vreal(M.rows(), M.columns()),
20  V(M.rows(), M.columns()),
21  D(M.rows())
22 {
23  long n = M.rows();
24  assert(n == (int)(M.columns()));
25 
27 
28  vnl_vector<double> wr(n);
29  vnl_vector<double> wi(n);
30  vnl_vector<long> iv1(n);
31  vnl_vector<double> fv1(n);
32  vnl_matrix<double> devout(n, n);
33 
34  long ierr = 0;
35  long matz = 1;
36  v3p_netlib_rg_(&n, &n, mf,
37  wr.data_block(), wi.data_block(),
38  &matz, devout.data_block(),
39  iv1.data_block(), fv1.data_block(),
40  &ierr);
41 
42  if (ierr != 0) {
43  std::cerr << " *** vnl_real_eigensystem: Failed on " << ierr << "th eigenvalue\n"
44  << M << std::endl;
45  }
46 
47  // Copy out eigenvalues and eigenvectors
48  for (int c = 0; c < n; ++c) {
49  D(c,c) = std::complex<double>(wr[c], wi[c]);
50  if (wi[c] != 0) {
51  // Complex - copy conjugates and inc c.
52  D(c+1, c+1) = std::complex<double>(wr[c], -wi[c]);
53  for (int r = 0; r < n; ++r) {
54  V(r, c) = std::complex<double>(devout(c,r), devout(c+1,r));
55  V(r, c+1) = std::complex<double>(devout(c,r), -devout(c+1,r));
56  }
57 
58  ++c;
59  }
60  else
61  for (int r = 0; r < n; ++r) {
62  V(r, c) = std::complex<double>(devout(c,r), 0);
63  Vreal(r,c) = devout(c,r);
64  }
65  }
66 }
vnl_real_eigensystem(vnl_matrix< double > const &M)
Extract eigensystem of non-symmetric matrix M, using the EISPACK routine rg.
vnl_matrix< std::complex< double > > V
Output matrix of eigenvectors, which will in general be complex.
T const * data_block() const
Access the contiguous block storing the elements in the vector. O(1).
Definition: vnl_vector.h:230
vnl_diag_matrix< std::complex< double > > D
Output diagonal matrix of eigenvalues.
vnl_matrix< double > Vreal
Convert row-stored matrix to column-stored.
Declare in a central place the list of symbols from netlib.
Convert row-stored matrix to column-stored.
T const * data_block() const
Access the contiguous block storing the elements in the matrix row-wise. O(1).
Definition: vnl_matrix.h:601
unsigned int rows() const
Return the number of rows.
Definition: vnl_matrix.h:179
Extract eigensystem of non-symmetric matrix M, using EISPACK.
unsigned int columns() const
Return the number of columns.
Definition: vnl_matrix.h:187