Multiple computations of the same value.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1488942 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Gilles Sadowski 2013-06-03 09:47:40 +00:00
parent e0e56f8055
commit 0b2d417d52
1 changed files with 4 additions and 4 deletions

View File

@ -116,17 +116,17 @@ public class MidPointIntegrator extends BaseAbstractUnivariateIntegrator {
double previousStageResult) double previousStageResult)
throws TooManyEvaluationsException { throws TooManyEvaluationsException {
final double max = getMax();
final double min = getMin(); final double min = getMin();
final double diff = getMax() - min;
if (n == 0) { if (n == 0) {
final double midPoint = 0.5 * (max - min); final double midPoint = 0.5 * diff;
return (max - min) * computeObjectiveValue(midPoint); return diff * computeObjectiveValue(midPoint);
} else { } else {
final long np = 1L << (n - 1); // number of new points in this stage final long np = 1L << (n - 1); // number of new points in this stage
double sum = 0; double sum = 0;
// spacing between adjacent new points // spacing between adjacent new points
final double spacing = (max - min) / np; final double spacing = diff / np;
double x = min + 0.5 * spacing; // the first new point double x = min + 0.5 * spacing; // the first new point
for (long i = 0; i < np; i++) { for (long i = 0; i < np; i++) {
sum += computeObjectiveValue(x); sum += computeObjectiveValue(x);