vnl_cpoly_roots.cxx
Go to the documentation of this file.
1 /*
2  fsm
3 */
4 #include <cassert>
5 #include "vnl_cpoly_roots.h"
7 
8 void vnl_cpoly_roots::compute(vnl_vector<std::complex<double> > const &a)
9 {
10  // construct companion matrix
12  comp.fill(0);
13  for (unsigned i=0; i<N-1; ++i)
14  comp(i+1, i) = 1;
15  for (unsigned i=0; i<N; ++i)
16  comp(i, N-1) = -a[N-1-i];
17 
18  // the eigenvalues of the companion matrix are the roots of the polynomial
20  false, // we only want
21  false).W; // the eigenvalues.
22 #ifdef DEBUG
23  std::cerr << "s = " << solns << '\n';
24 #endif
25 }
26 
27 vnl_cpoly_roots::vnl_cpoly_roots(vnl_vector<std::complex<double> > const & a)
28  : solns(a.size())
29  , N(a.size()) // degree
30 {
31  compute(a);
32 }
33 
35  vnl_vector<double> const & a_imag)
36  : solns(a_real.size())
37  , N(a_real.size()) // degree
38 {
39  assert(a_real.size() == a_imag.size());
41  for (unsigned i=0; i<N; ++i)
42  a[i] = std::complex<double>(a_real[i], a_imag[i]);
43 
44 #ifdef DEBUG
45  std::cerr << "a = " << a << '\n';
46 #endif
47  compute(a);
48 }
void compute(vnl_vector< std::complex< double > > const &a)
does the actual work.
size_t size() const
Return the length, number of elements, dimension of this vector.
Definition: vnl_vector.h:126
finds roots of a univariate polynomial with complex coefficients
Calculates eigenvalues and eigenvectors of a square complex matrix.
An ordinary mathematical matrix.
Definition: vnl_adjugate.h:22
vnl_matrix & fill(T const &)
Sets all elements of matrix to specified value, and returns "*this".
Definition: vnl_matrix.hxx:419
Mathematical vector class, templated by type of element.
Definition: vnl_fwd.h:16
Calculates eigenvalues and eigenvectors of a square complex matrix.
vnl_vector< std::complex< double > > solns
vnl_vector< std::complex< double > > W
vnl_cpoly_roots(vnl_vector< std::complex< double > > const &a)