Algebraic.realEquation constructor

Algebraic.realEquation(
  1. List<double> coefficients
)

Creates a new algebraic equation by taking the coefficients of the polynomial starting from the one with the highest degree.

For example, the equation x^3 + 5x^2 + 3x - 2 = 0 would require a subclass of Algebraic to call the following...

super.realEquation(1, 5, 3, 2);

... because the coefficient with the highest degree goes first.

Use this constructor when the coefficients are all real numbers. If there were complex numbers as well, use the Algebraic(coefficients) constructor.

Implementation

Algebraic.realEquation(List<double> coefficients) {
  this.coefficients = UnmodifiableListView(
    coefficients.map((c) => Complex.fromReal(c)).toList(),
  );

  // Unless this is a constant value, the coefficient with the highest degree
  // cannot be zero.
  if (!isValid) {
    throw const AlgebraicException('The given equation is not valid.');
  }
}