![]()  | 
  
    TheAlgorithms/C++ 1.0.0
    
   All the algorithms implemented in C++ 
   | 
 
Compute all possible approximate roots of any given polynomial using Durand Kerner algorithm More...
#include <algorithm>#include <cassert>#include <cmath>#include <complex>#include <cstdint>#include <cstdlib>#include <ctime>#include <fstream>#include <iostream>#include <valarray>Go to the source code of this file.
Macros | |
| #define | ACCURACY 1e-10 | 
| #define | MAX_BUFF_SIZE 50 | 
Functions | |
| std::complex< double > | poly_function (const std::valarray< double > &coeffs, std::complex< double > x) | 
| const char * | complex_str (const std::complex< double > &x) | 
| bool | check_termination (long double delta) | 
| std::pair< uint32_t, double > | durand_kerner_algo (const std::valarray< double > &coeffs, std::valarray< std::complex< double > > *roots, bool write_log=false) | 
| void | test1 () | 
| void | test2 () | 
| int | main (int argc, char **argv) | 
Compute all possible approximate roots of any given polynomial using Durand Kerner algorithm
Test the algorithm online: https://gist.github.com/kvedala/27f1b0b6502af935f6917673ec43bcd7
Try the highly unstable Wilkinson's polynomial:
 Sample implementation results to compute approximate roots of the equation \(x^4-1=0\):
  
 
Definition in file durand_kerner_roots.cpp.
| #define ACCURACY 1e-10 | 
maximum accuracy limit
Definition at line 46 of file durand_kerner_roots.cpp.
| bool check_termination | ( | long double | delta | ) | 
check for termination condition
| [in] | delta | point at which to evaluate the polynomial | 
Definition at line 92 of file durand_kerner_roots.cpp.
| const char * complex_str | ( | const std::complex< double > & | x | ) | 
create a textual form of complex number
| [in] | x | point at which to evaluate the polynomial | 
Definition at line 77 of file durand_kerner_roots.cpp.
| std::pair< uint32_t, double > durand_kerner_algo | ( | const std::valarray< double > & | coeffs, | 
| std::valarray< std::complex< double > > * | roots, | ||
| bool | write_log = false ) | 
Implements Durand Kerner iterative algorithm to compute all roots of a polynomial.
| [in] | coeffs | coefficients of the polynomial | 
| [out] | roots | the computed roots of the polynomial | 
| [in] | write_log | flag whether to save the log file (default = false) | 
Definition at line 110 of file durand_kerner_roots.cpp.
| int main | ( | int | argc, | 
| char ** | argv ) | 
Definition at line 284 of file durand_kerner_roots.cpp.
| std::complex< double > poly_function | ( | const std::valarray< double > & | coeffs, | 
| std::complex< double > | x ) | 
Evaluate the value of a polynomial with given coefficients
| [in] | coeffs | coefficients of the polynomial | 
| [in] | x | point at which to evaluate the polynomial | 
Definition at line 54 of file durand_kerner_roots.cpp.
| void test1 | ( | ) | 
Self test the algorithm by checking the roots for \(x^2+4=0\) to which the roots are \(0 \pm 2i\)
Definition at line 208 of file durand_kerner_roots.cpp.
| void test2 | ( | ) | 
Self test the algorithm by checking the roots for \(0.015625x^3-1=0\) to which the roots are \((4+0i),\,(-2\pm3.464i)\)
Definition at line 243 of file durand_kerner_roots.cpp.