integrate method
Calculates the numerical value of the definite function integral between lowerBound and upperBound. Returns a Record object whose members are:
-
a
guesses
named field, which contains the list of values generated by the algorithm on each step; -
a
result
named field, which contains the evaluation of the integral in the[a, b]
interval.
Implementation
@override
({List<double> guesses, double result}) integrate() {
// The 'step' of the algorithm.
final h = (upperBound - lowerBound) / intervals;
// The initial approximation of the result.
var integralResult =
evaluateFunction(lowerBound) + evaluateFunction(upperBound);
// The list containing the various guesses of the algorithm.
final guesses = List<double>.filled(intervals, 0);
// The actual algorithm.
for (var i = 0; i < intervals; ++i) {
final x = lowerBound + i * h;
integralResult += 2 * evaluateFunction(x);
guesses[i] = integralResult;
}
return (
guesses: guesses,
result: integralResult * h / 2,
);
}