integrate method

  1. @override
IntegralResults integrate(
  1. String function
)
override

Calculates the numerical value of the function definite integral between lowerBound and upperBound.

Implementation

@override
IntegralResults integrate(String function) {
  // The 'step' of the algorithm
  final h = (upperBound - lowerBound) / intervals;

  // This variable will keep track of the actual result
  var integralResult = 0.0;

  // 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 midpoint = lowerBound + h / 2;
    final guess = evaluateFunction(function, midpoint + i * h);

    integralResult += guess;
    guesses[i] = guess;
  }

  return IntegralResults(
    guesses: guesses,
    result: integralResult * h,
  );
}