root_pol
Functions
-
int main(int argc, char *argv[])
root_pol [ option ] [ infile ]
-m int
order of polynomial \((1 \le M)\)
-i int
maximum number of iterations
-d double
convergence threshold
-q int
input format
0
forward order1
reverse order
-o int
output format
0
rectangular form1
polar form
infile str
double-type coefficients of polynomial
stdout
double-type roots of polynomial
If
-o
is 0, real and imaginary parts of roots are written.echo 3 4 5 | root_pol -m 2 -o 0 | x2x +da -c 2 # -0.666667 1.10554 # -0.666667 -1.10554
If
-o
is 1, radius and angle of roots are written.echo 3 4 5 | root_pol -m 2 -o 1 | x2x +da -c 2 # 1.29099 2.11344 # 1.29099 -2.11344
See also
-
class DurandKernerMethod
Find roots of a polynomial.
The input is the \(M\)-th order polynomial coefficients:
\[ \begin{array}{cccc} a(1), & a(2), & \ldots, & a(M), \end{array} \]where the polynomial is represented as\[ x^M + a(1) x^{M-1} + \cdots + a(M-1) x + a(M). \]The output is the complex-valued roots of the polynomial:\[ \begin{array}{cccc} z(0), & z(1), & \ldots, & z(M-1). \end{array} \]They are found by the Durand-Kerner method.Public Functions
-
DurandKernerMethod(int num_order, int num_iteration, double convergence_threshold)
- Parameters:
num_order – [in] Order of coefficients, \(M\).
num_iteration – [in] Number of iterations.
convergence_threshold – [in] Convergence threshold.
-
inline int GetNumOrder() const
- Returns:
Order of coefficients.
-
inline int GetNumIteration() const
- Returns:
Number of iterations.
-
inline double GetConvergenceThreshold() const
- Returns:
Convergence threshold.
-
inline bool IsValid() const
- Returns:
True if this object is valid.
-
bool Run(const std::vector<double> &coefficients, std::vector<std::complex<double>> *roots, bool *is_converged) const
- Parameters:
coefficients – [in] Coefficients of polynomial.
roots – [out] Root of the polynomial.
is_converged – [out] True if convergence is reached.
- Returns:
True on success, false on failure.
-
DurandKernerMethod(int num_order, int num_iteration, double convergence_threshold)