operator * method

Algebraic operator *(
  1. Algebraic other
)

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 Laguerre for example.

Implementation

Algebraic operator *(Algebraic other) {
  // Generating the new list of coefficients
  final newLength = coefficients.length + other.coefficients.length - 1;
  final newCoefficients =
      List<Complex>.filled(newLength, const Complex.zero());

  // The product
  for (var i = 0; i < coefficients.length; ++i) {
    for (var j = 0; j < other.coefficients.length; ++j) {
      newCoefficients[i + j] += coefficients[i] * other.coefficients[j];
    }
  }

  // Returning a new instance
  return Algebraic.from(newCoefficients);
}