Fixed wrong first iteration for midpoint integrator.
Thanks to Gilles for spotting the issue. git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1488969 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
0b2d417d52
commit
e68422227f
|
@ -120,7 +120,7 @@ public class MidPointIntegrator extends BaseAbstractUnivariateIntegrator {
|
|||
final double diff = getMax() - min;
|
||||
|
||||
if (n == 0) {
|
||||
final double midPoint = 0.5 * diff;
|
||||
final double midPoint = min + 0.5 * diff;
|
||||
return diff * computeObjectiveValue(midPoint);
|
||||
} else {
|
||||
final long np = 1L << (n - 1); // number of new points in this stage
|
||||
|
|
|
@ -35,6 +35,25 @@ import org.junit.Test;
|
|||
*/
|
||||
public final class MidPointIntegratorTest {
|
||||
|
||||
/**
|
||||
* Test of integrator for the sine function.
|
||||
*/
|
||||
@Test
|
||||
public void testLowAccuracy() {
|
||||
UnivariateFunction f = new QuinticFunction();
|
||||
UnivariateIntegrator integrator = new MidPointIntegrator(0.01, 1.0e-10, 2, 4);
|
||||
|
||||
double min = -10;
|
||||
double max = -9;
|
||||
double expected = -3697001.0 / 48.0;
|
||||
double tolerance = FastMath.abs(expected * integrator.getRelativeAccuracy());
|
||||
double result = integrator.integrate(Integer.MAX_VALUE, f, min, max);
|
||||
Assert.assertTrue(integrator.getEvaluations() < Integer.MAX_VALUE / 2);
|
||||
Assert.assertTrue(integrator.getIterations() < MidPointIntegrator.MIDPOINT_MAX_ITERATIONS_COUNT / 2);
|
||||
Assert.assertEquals(expected, result, tolerance);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of integrator for the sine function.
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue