vnl_rnpoly_solve.h
Go to the documentation of this file.
1 // This is core/vnl/algo/vnl_rnpoly_solve.h
2 #ifndef vnl_rnpoly_solve_h_
3 #define vnl_rnpoly_solve_h_
4 //:
5 // \file
6 // \brief Solves for roots of system of real polynomials
7 // \author Marc Pollefeys, ESAT-VISICS, K.U.Leuven
8 // \date 12-Aug-1997
9 //
10 // \verbatim
11 // Modifications
12 // Oct.1999 - Peter Vanroose - implementation simplified through "cmplx" class for doing complex arithmetic.
13 // May.2002 - Peter Vanroose - added operator*=(cmplx) and operator/=(cmplx)
14 // Mar.2003 - Peter Vanroose - renamed M to M_, T to T_
15 // Feb.2004 - Peter Vanroose - removed hard limits on dimensionality; this gets rid of M_ and T_;
16 // now using std::vector throughout instead of C arrays of fixed size
17 // \endverbatim
18 
19 #include <utility>
20 #include <vector>
21 #ifdef _MSC_VER
22 # include <vcl_msvc_warnings.h>
23 #endif
24 #include <vnl/algo/vnl_algo_export.h>
26 #include <vnl/vnl_vector.h>
27 
28 //: Solves for roots of system of real polynomials
29 // Calculates all the roots of a system of N polynomials in N variables
30 // through continuation.
31 // Adapted from the PARALLEL CONTINUATION algorithm, written by Darrell
32 // Stam, 1991, and further improved by Kriegman and Ponce, 1992.
33 
34 class VNL_ALGO_EXPORT vnl_rnpoly_solve
35 {
36  // Data Members--------------------------------------------------------------
37  std::vector<vnl_real_npolynomial*> ps_; // the input
38  std::vector<vnl_vector<double>*> r_; // the output (real part)
39  std::vector<vnl_vector<double>*> i_; // the output (imaginary part)
40 
41  public:
42 
43  // Constructor---------------------------------------------------------------
44 
45  //: The constructor already does all the calculations
46  inline vnl_rnpoly_solve(std::vector<vnl_real_npolynomial*> ps)
47  : ps_(std::move(ps)) { compute(); }
48 
49  // Destructor----------------------------------------------------------------
50 
52 
53  // Operations----------------------------------------------------------------
54 
55  //: Array of real parts of roots
56  inline std::vector<vnl_vector<double>*> real() { return r_; }
57 
58  //: Array of imaginary parts of roots
59  inline std::vector<vnl_vector<double>*> imag() { return i_; }
60 
61  //: Return real roots only.
62  // Roots are real if the absolute value of their imaginary part is less than
63  // the optional argument tol, which defaults to 1e-12 [untested]
64  std::vector<vnl_vector<double>*> realroots(double tol = 1e-12);
65 
66  // Computations--------------------------------------------------------------
67 
68  private:
69  //: Compute roots using continuation algorithm.
70  bool compute();
71 
72  void Read_Input(std::vector<unsigned int>& ideg,
73  std::vector<unsigned int>& terms,
74  std::vector<int>& polyn,
75  std::vector<double>& coeff);
76 };
77 
78 #endif // vnl_rnpoly_solve_h_
std::vector< vnl_vector< double > * > real()
Array of real parts of roots.
std::vector< vnl_real_npolynomial * > ps_
std::vector< vnl_vector< double > * > i_
vnl_rnpoly_solve(std::vector< vnl_real_npolynomial * > ps)
The constructor already does all the calculations.
Solves for roots of system of real polynomials.
std::vector< vnl_vector< double > * > imag()
Array of imaginary parts of roots.
std::vector< vnl_vector< double > * > r_
contains class for polynomials with N variables