derivative method

  1. @override
Algebraic derivative()
override

The derivative of the polynomial.

Implementation

@override
Algebraic derivative() {
  // Rather than always returning 'DurandKerner', if the degree is <= 4 there
  // is the possibility to return a more convenient object
  switch (coefficients.length) {
    case 1:
      return Constant(
        a: coefficients.first,
      ).derivative();
    case 2:
      return Linear(
        a: coefficients.first,
        b: coefficients[1],
      ).derivative();
    case 3:
      return Quadratic(
        a: coefficients.first,
        b: coefficients[1],
        c: coefficients[2],
      ).derivative();
    case 4:
      return Cubic(
        a: coefficients.first,
        b: coefficients[1],
        c: coefficients[2],
        d: coefficients[3],
      ).derivative();
    case 5:
      return Quartic(
        a: coefficients.first,
        b: coefficients[1],
        c: coefficients[2],
        d: coefficients[3],
        e: coefficients[4],
      ).derivative();
    case 6:
      final coeffs = _derivativeOf();
      return Quartic(
        a: coeffs.first,
        b: coeffs[1],
        c: coeffs[2],
        d: coeffs[3],
        e: coeffs[4],
      );
    default:
      return DurandKerner(
        coefficients: _derivativeOf(),
        precision: precision,
        maxSteps: maxSteps,
      );
  }
}