You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by lu...@apache.org on 2013/06/03 14:10:36 UTC
svn commit: r1488969 - in /commons/proper/math/trunk/src:
main/java/org/apache/commons/math3/analysis/integration/MidPointIntegrator.java
test/java/org/apache/commons/math3/analysis/integration/MidPointIntegratorTest.java
Author: luc
Date: Mon Jun 3 12:10:36 2013
New Revision: 1488969
URL: http://svn.apache.org/r1488969
Log:
Fixed wrong first iteration for midpoint integrator.
Thanks to Gilles for spotting the issue.
Modified:
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/analysis/integration/MidPointIntegrator.java
commons/proper/math/trunk/src/test/java/org/apache/commons/math3/analysis/integration/MidPointIntegratorTest.java
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/analysis/integration/MidPointIntegrator.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/analysis/integration/MidPointIntegrator.java?rev=1488969&r1=1488968&r2=1488969&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/analysis/integration/MidPointIntegrator.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/analysis/integration/MidPointIntegrator.java Mon Jun 3 12:10:36 2013
@@ -120,7 +120,7 @@ public class MidPointIntegrator extends
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
Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/analysis/integration/MidPointIntegratorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/analysis/integration/MidPointIntegratorTest.java?rev=1488969&r1=1488968&r2=1488969&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/analysis/integration/MidPointIntegratorTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/analysis/integration/MidPointIntegratorTest.java Mon Jun 3 12:10:36 2013
@@ -39,6 +39,25 @@ public final class MidPointIntegratorTes
* 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.
+ */
+ @Test
public void testSinFunction() {
UnivariateFunction f = new Sin();
UnivariateIntegrator integrator = new MidPointIntegrator();