solutions method

  1. @override
List<Complex> solutions()
override

Finds the roots (the solutions) of the associated P(x) = 0 equation.

Implementation

@override
List<Complex> solutions() {
  const two = Complex.fromReal(2);
  const three = Complex.fromReal(3);
  final sigma = Complex(-1 / 2, 1 / 2 * math.sqrt(3));

  final d0 = b * b - a * c * three;
  final d1 = (b.pow(3) * two) -
      (a * b * c * const Complex.fromReal(9)) +
      (a * a * d * const Complex.fromReal(27));
  final sqrtD = (discriminant() * a * a * const Complex.fromReal(-27)).sqrt();
  final C = ((d1 + sqrtD) / two).nthRoot(3);
  final constTerm = const Complex.fromReal(-1) / (a * three);

  return <Complex>[
    constTerm * (b + C + (d0 / C)),
    constTerm * (b + (C * sigma) + (d0 / (C * sigma))),
    constTerm * (b + (C * sigma.pow(2)) + (d0 / (C * sigma.pow(2)))),
  ];
}