Algebraic constructor
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([
Complex.fromReal(1), // x^3
Complex.fromReal(5), // x^2
Complex.fromReal(3), // x
Complex.fromReal(-2), // -2
]);
... because the coefficient with the highest degree goes first.
If the coefficients of the polynomial are all real numbers, consider using the Algebraic.realEquation(coefficients) constructor which is more convenient.
Implementation
Algebraic(List<Complex> coefficients) {
// Making a deep copy but there's no need to call 'copyWith' on the complex
// coefficients because 'Complex' is an immutable type.
this.coefficients = UnmodifiableListView(List<Complex>.from(coefficients));
// 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.');
}
}