coefficient method
Returns the coefficient of the polynomial whose degree is degree
. For
example:
final quadratic = Quadratic(
a: Complex.fromReal(2),
b: Complex.fromReal(-6),
c: Complex.fromReal(5),
);
final degreeZero = quadratic.coefficient(0) // Complex(5, 0)
final degreeOne = quadratic.coefficient(1) // Complex(-6, 0)
final degreeTwo = quadratic.coefficient(2) // Complex(2, 0)
This method returns null
if no coefficient of the given degree
is found.
Implementation
Complex? coefficient(int degree) {
// The coefficient of the given degree doesn't exist
if ((degree < 0) || (degree > coefficients.length - 1)) {
return null;
}
// Return the coefficient of degree 'degree'
return coefficients[coefficients.length - degree - 1];
}