derivative method

  1. @override
Algebraic derivative()
override

The derivative of the polynomial.

Implementation

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