DurandKerner class

The Durand–Kerner method, also known as Weierstrass method, is a root finding algorithm for solving polynomial equations. With this class, you can find all the roots of a polynomial of any degree.

This is the preferred approach:

  • when the polynomial degree is 5 or higher, use DurandKerner;
  • when the polynomial degree is 4, use Quartic;
  • when the polynomial degree is 3, use Cubic;
  • when the polynomial degree is 2, use Quadratoc;
  • when the polynomial degree is 1, use Linear.

This algorithm requires an initial set of values to find the roots. This implementation generates some random values if the user doesn't provide some initial points to the algorithm.

Note that this algorithm does NOT always converge. To be more clear, it is NOT true that for every polynomial, the set of initial vectors that eventually converges to roots is open and dense.

Inheritance

Constructors

DurandKerner({required List<Complex> coefficients, List<Complex> initialGuess = const [], double precision = 1.0e-10, int maxSteps = 2000})
Instantiates a new object to find all the roots of a polynomial equation using the Durand-Kerner algorithm. The polynomial can have both complex (Complex) and real (double) values.
DurandKerner.realEquation({required List<double> coefficients, List<Complex> initialGuess = const [], double precision = 1.0e-10, int maxSteps = 2000})
Instantiates a new object to find all the roots of a polynomial equation using the Durand-Kerner algorithm. The polynomial can have both complex (Complex) and real (double) values.

Properties

coefficients UnmodifiableListView<Complex>
An unmodifiable list with the coefficients of the polynomial.
finalinherited
degree int
The degree of the polynomial.
no setteroverride
hashCode int
The hash code for this object.
no setteroverride
initialGuess List<Complex>
The initial guess from which the algorithm has to start finding the roots.
final
isRealEquation bool
Determines whether the polynomial is real or not.
no setterinherited
isValid bool
A polynomial equation is valid if the coefficient associated to the variable of highest degree is different from zero. In other words, the polynomial is valid if a is different from zero.
no setterinherited
maxSteps int
The maximum steps to be made by the algorithm.
final
precision double
The accuracy of the algorithm.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

coefficient(int degree) Complex?
Returns the coefficient of the polynomial whose degree is degree. For example:
inherited
complexHypot(Complex x, Complex y) Complex
Computes sqrt(x^2 + y^2) without under/overflow.
inherited
copyWith({List<Complex>? coefficients, List<Complex>? initialGuess, double? precision, int? maxSteps}) DurandKerner
Creates a deep copy of this object with the given fields replaced with the new values.
derivative() Algebraic
The derivative of the polynomial.
override
discriminant() Complex
The discriminant of the algebraic equation if it exists.
override
evaluateIntegralOn(double lower, double upper) Complex
Integrates the polynomial between lower and upper and computes the result.
inherited
evaluateOn(Complex x) Complex
Evaluates the polynomial on the given complex number x.
inherited
hypot(double x, double y) double
Computes sqrt(x^2 + y^2) without under/overflow.
inherited
log2(num value) double
Computes the base-2 logarithm of a real number.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
realEvaluateOn(double x) Complex
Evaluates the polynomial on the given real number x.
inherited
solutions() List<Complex>
Calculates the roots (the solutions) of the equation.
override
toString() String
A string representation of this object.
inherited
toStringWithFractions() String
Returns a string representation of the polynomial where the coefficients are converted into their fractional representation.
inherited

Operators

operator *(Algebraic other) Algebraic
The product of two polynomials is performed by multiplying the corresponding coefficients of the polynomials. The degrees of the two polynomials don't need to be the same so you can multiply a Constant with a DurandKerner for example.
inherited
operator +(Algebraic other) Algebraic
The addition of two polynomials is performed by adding the corresponding coefficients. The degrees of the two polynomials don't need to be the same so you can sum a Cubic with a Linear for example.
inherited
operator -(Algebraic other) Algebraic
The difference of two polynomials is performed by subtracting the corresponding coefficients. The degrees of the two polynomials don't need to be the same so you can subtract a Quadratic and a Quartic for example.
inherited
operator /(Algebraic other) AlgebraicDivision
This operator divides a polynomial by another polynomial of the same or lower degree.
inherited
operator ==(Object other) bool
The equality operator.
override
operator [](int index) Complex
Returns the coefficient of the polynomial at the given index position. For example:
inherited
operator unary-() Algebraic
The 'negation' operator changes the sign of every coefficient of the polynomial. For example:
inherited