Return-Path: Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: (qmail 19575 invoked from network); 21 Jun 2009 17:01:17 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 21 Jun 2009 17:01:16 -0000 Received: (qmail 62782 invoked by uid 500); 21 Jun 2009 17:01:27 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 62682 invoked by uid 500); 21 Jun 2009 17:01:27 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 62673 invoked by uid 99); 21 Jun 2009 17:01:27 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 21 Jun 2009 17:01:27 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 21 Jun 2009 17:01:25 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id C7F5C23888D3; Sun, 21 Jun 2009 17:01:04 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r787050 - in /commons/proper/math/trunk/src: java/org/apache/commons/math/ java/org/apache/commons/math/ode/ java/org/apache/commons/math/ode/nonstiff/ test/org/apache/commons/math/ode/nonstiff/ Date: Sun, 21 Jun 2009 17:01:04 -0000 To: commits@commons.apache.org From: luc@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090621170104.C7F5C23888D3@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: luc Date: Sun Jun 21 17:01:03 2009 New Revision: 787050 URL: http://svn.apache.org/viewvc?rev=787050&view=rev Log: removed the current point from count in multistep integrators updated documentation since now Adams-Bashforth and Adams-Moulton are adaptive stepsize integrators Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/MessagesResources_fr.java commons/proper/math/trunk/src/java/org/apache/commons/math/ode/MultistepIntegrator.java commons/proper/math/trunk/src/java/org/apache/commons/math/ode/nonstiff/AdamsBashforthIntegrator.java commons/proper/math/trunk/src/java/org/apache/commons/math/ode/nonstiff/AdamsMoultonIntegrator.java commons/proper/math/trunk/src/test/org/apache/commons/math/ode/nonstiff/AdamsBashforthIntegratorTest.java commons/proper/math/trunk/src/test/org/apache/commons/math/ode/nonstiff/AdamsMoultonIntegratorTest.java Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/MessagesResources_fr.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/MessagesResources_fr.java?rev=787050&r1=787049&r2=787050&view=diff ============================================================================== --- commons/proper/math/trunk/src/java/org/apache/commons/math/MessagesResources_fr.java (original) +++ commons/proper/math/trunk/src/java/org/apache/commons/math/MessagesResources_fr.java Sun Jun 21 17:01:03 2009 @@ -308,8 +308,8 @@ "intervalle d''int\u00e9gration trop petit : {0}" }, // org.apache.commons.math.ode.MultistepIntegrator - { "{0} is supported only for 2 points or more", - "la m\u00e9thode {0} n''est disponible que pour 2 points ou plus" }, + { "{0} method needs at least one previous point", + "la m\u00e9thode {0} n\u00e9cessite au moins un point pr\u00e9c\u00e9dent" }, // org.apache.commons.math.ode.stiff.BDFIntegrator { "unsupported order {0} for BDF methods, must be between {1} and {2}", Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/ode/MultistepIntegrator.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/MultistepIntegrator.java?rev=787050&r1=787049&r2=787050&view=diff ============================================================================== --- commons/proper/math/trunk/src/java/org/apache/commons/math/ode/MultistepIntegrator.java (original) +++ commons/proper/math/trunk/src/java/org/apache/commons/math/ode/MultistepIntegrator.java Sun Jun 21 17:01:03 2009 @@ -47,7 +47,7 @@ /** Starter integrator. */ private FirstOrderIntegrator starter; - /** Number of steps of the multistep method (including the one being computed). */ + /** Number of steps of the multistep method (excluding the one being computed). */ private final int nSteps; /** First scaled derivative (h y'). */ @@ -77,7 +77,7 @@ * some defaults settings.

* @param name name of the method * @param nSteps number of steps of the multistep method - * (including the one being computed) + * (excluding the one being computed) * @param order order of the method * @param minStep minimal step (must be positive even for backward * integration), the last step can be smaller than this @@ -94,9 +94,9 @@ super(name, minStep, maxStep, scalAbsoluteTolerance, scalRelativeTolerance); - if (nSteps <= 1) { + if (nSteps <= 0) { throw MathRuntimeException.createIllegalArgumentException( - "{0} is supported only for 2 points or more", + "{0} method needs at least one previous point", name); } @@ -104,7 +104,7 @@ scalAbsoluteTolerance, scalRelativeTolerance); this.nSteps = nSteps; - transformer = NordsieckTransformer.getInstance(nSteps); + transformer = NordsieckTransformer.getInstance(nSteps + 1); exp = -1.0 / order; @@ -122,7 +122,7 @@ * some defaults settings.

* @param name name of the method * @param nSteps number of steps of the multistep method - * (including the one being computed) + * (excluding the one being computed) * @param order order of the method * @param minStep minimal step (must be positive even for backward * integration), the last step can be smaller than this @@ -141,7 +141,7 @@ vecAbsoluteTolerance, vecRelativeTolerance); this.nSteps = nSteps; - transformer = NordsieckTransformer.getInstance(nSteps); + transformer = NordsieckTransformer.getInstance(nSteps + 1); exp = -1.0 / order; @@ -291,7 +291,7 @@ final Class cl = MultistepIntegrator.class; final Field f = cl.getDeclaredField("transformer"); f.setAccessible(true); - f.set(this, NordsieckTransformer.getInstance(nSteps)); + f.set(this, NordsieckTransformer.getInstance(nSteps + 1)); } catch (NoSuchFieldException nsfe) { IOException ioe = new IOException(); @@ -325,7 +325,7 @@ final double prev = interpolator.getPreviousTime(); final double curr = interpolator.getCurrentTime(); stepStart = prev; - stepSize = (curr - prev) / nSteps; + stepSize = (curr - prev) / (nSteps + 1); // compute the first scaled derivative interpolator.setInterpolatedTime(prev); @@ -335,8 +335,8 @@ } // compute the high order scaled derivatives - final double[][] multistep = new double[nSteps - 1][]; - for (int i = 1; i < nSteps; ++i) { + final double[][] multistep = new double[nSteps][]; + for (int i = 1; i <= nSteps; ++i) { interpolator.setInterpolatedTime(prev + stepSize * i); final double[] msI = interpolator.getInterpolatedDerivatives().clone(); for (int j = 0; j < n; ++j) { Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/ode/nonstiff/AdamsBashforthIntegrator.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/nonstiff/AdamsBashforthIntegrator.java?rev=787050&r1=787049&r2=787050&view=diff ============================================================================== --- commons/proper/math/trunk/src/java/org/apache/commons/math/ode/nonstiff/AdamsBashforthIntegrator.java (original) +++ commons/proper/math/trunk/src/java/org/apache/commons/math/ode/nonstiff/AdamsBashforthIntegrator.java Sun Jun 21 17:01:03 2009 @@ -32,7 +32,9 @@ * Differential Equations. * *

Adams-Bashforth methods (in fact due to Adams alone) are explicit - * multistep ODE solvers with fixed stepsize. The value of state vector + * multistep ODE solvers. This implementation is a variation of the classical + * one: it uses adaptive stepsize to implement error control, whereas + * classical implementations are fixed step size. The value of state vector * at step n+1 is a simple combination of the value at step n and of the * derivatives at steps n, n-1, n-2 ... Depending on the number k of previous * steps one wants to use for computing the next value, different formulas @@ -45,8 +47,7 @@ *

  • ...
  • * * - *

    A k-steps Adams-Bashforth method is of order k. There is no theoretical limit to the - * value of k, but due to an implementation limitation k must be greater than 1.

    + *

    A k-steps Adams-Bashforth method is of order k.

    * *

    Implementation details

    * @@ -112,7 +113,7 @@ * Taylor series formulas, *
  • it simplifies step changes that occur when discrete events that truncate * the step are triggered,
  • - *
  • it allows to extend the methods in order to support adaptive stepsize (not implemented yet).
  • + *
  • it allows to extend the methods in order to support adaptive stepsize.
  • *

    * *

    The Nordsieck vector at step n+1 is computed from the Nordsieck vector at step n as follows: @@ -142,8 +143,7 @@ /** * Build an Adams-Bashforth with the given order and step size. - * @param order order of the method (must be greater than 1: due to - * an implementation limitation the order 1 method is not supported) + * @param nSteps number of steps of the method excluding the one being computed * @param minStep minimal step (must be positive even for backward * integration), the last step can be smaller than this * @param maxStep maximal step (must be positive even for backward @@ -152,19 +152,18 @@ * @param scalRelativeTolerance allowed relative error * @exception IllegalArgumentException if order is 1 or less */ - public AdamsBashforthIntegrator(final int order, + public AdamsBashforthIntegrator(final int nSteps, final double minStep, final double maxStep, final double scalAbsoluteTolerance, final double scalRelativeTolerance) throws IllegalArgumentException { - super("Adams-Bashforth", order, order, minStep, maxStep, + super("Adams-Bashforth", nSteps, nSteps + 1, minStep, maxStep, scalAbsoluteTolerance, scalRelativeTolerance); } /** * Build an Adams-Bashforth with the given order and step size. - * @param order order of the method (must be greater than 1: due to - * an implementation limitation the order 1 method is not supported) + * @param nSteps number of steps of the method excluding the one being computed * @param minStep minimal step (must be positive even for backward * integration), the last step can be smaller than this * @param maxStep maximal step (must be positive even for backward @@ -173,12 +172,12 @@ * @param vecRelativeTolerance allowed relative error * @exception IllegalArgumentException if order is 1 or less */ - public AdamsBashforthIntegrator(final int order, + public AdamsBashforthIntegrator(final int nSteps, final double minStep, final double maxStep, final double[] vecAbsoluteTolerance, final double[] vecRelativeTolerance) throws IllegalArgumentException { - super("Adams-Bashforth", order, order, minStep, maxStep, + super("Adams-Bashforth", nSteps, nSteps + 1, minStep, maxStep, vecAbsoluteTolerance, vecRelativeTolerance); } Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/ode/nonstiff/AdamsMoultonIntegrator.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/ode/nonstiff/AdamsMoultonIntegrator.java?rev=787050&r1=787049&r2=787050&view=diff ============================================================================== --- commons/proper/math/trunk/src/java/org/apache/commons/math/ode/nonstiff/AdamsMoultonIntegrator.java (original) +++ commons/proper/math/trunk/src/java/org/apache/commons/math/ode/nonstiff/AdamsMoultonIntegrator.java Sun Jun 21 17:01:03 2009 @@ -36,10 +36,12 @@ * Differential Equations. * *

    Adams-Moulton methods (in fact due to Adams alone) are implicit - * multistep ODE solvers with fixed stepsize. The value of state vector + * multistep ODE solvers. This implementation is a variation of the classical + * one: it uses adaptive stepsize to implement error control, whereas + * classical implementations are fixed step size. The value of state vector * at step n+1 is a simple combination of the value at step n and of the * derivatives at steps n+1, n, n-1 ... Since y'n+1 is needed to - * compute yn+1, another method must be used to compute a first + * compute yn+1,another method must be used to compute a first * estimate of yn+1, then compute y'n+1, then compute * a final estimate of yn+1 using the following formulas. Depending * on the number k of previous steps one wants to use for computing the next @@ -52,8 +54,7 @@ *

  • ...
  • * * - *

    A k-steps Adams-Moulton method is of order k+1. There is no theoretical limit to the - * value of k, but due to an implementation limitation k must be greater than 1.

    + *

    A k-steps Adams-Moulton method is of order k+1.

    * *

    Implementation details

    * @@ -119,7 +120,7 @@ * Taylor series formulas, *
  • it simplifies step changes that occur when discrete events that truncate * the step are triggered,
  • - *
  • it allows to extend the methods in order to support adaptive stepsize (not implemented yet).
  • + *
  • it allows to extend the methods in order to support adaptive stepsize.
  • *

    * *

    The predicted Nordsieck vector at step n+1 is computed from the Nordsieck vector at step @@ -158,9 +159,8 @@ public class AdamsMoultonIntegrator extends MultistepIntegrator { /** - * Build an Adams-Moulton integrator with the given order and step size. - * @param order order of the method (must be greater than 1: due to - * an implementation limitation the order 1 method is not supported) + * Build an Adams-Moulton integrator with the given order and error control parameters. + * @param nSteps number of steps of the method excluding the one being computed * @param minStep minimal step (must be positive even for backward * integration), the last step can be smaller than this * @param maxStep maximal step (must be positive even for backward @@ -169,19 +169,18 @@ * @param scalRelativeTolerance allowed relative error * @exception IllegalArgumentException if order is 1 or less */ - public AdamsMoultonIntegrator(final int order, + public AdamsMoultonIntegrator(final int nSteps, final double minStep, final double maxStep, final double scalAbsoluteTolerance, final double scalRelativeTolerance) throws IllegalArgumentException { - super("Adams-Moulton", order, order, minStep, maxStep, + super("Adams-Moulton", nSteps, nSteps + 1, minStep, maxStep, scalAbsoluteTolerance, scalRelativeTolerance); } /** * Build an Adams-Moulton integrator with the given order and step size. - * @param order order of the method (must be greater than 1: due to - * an implementation limitation the order 1 method is not supported) + * @param nSteps number of steps of the method excluding the one being computed * @param minStep minimal step (must be positive even for backward * integration), the last step can be smaller than this * @param maxStep maximal step (must be positive even for backward @@ -190,12 +189,12 @@ * @param vecRelativeTolerance allowed relative error * @exception IllegalArgumentException if order is 1 or less */ - public AdamsMoultonIntegrator(final int order, + public AdamsMoultonIntegrator(final int nSteps, final double minStep, final double maxStep, final double[] vecAbsoluteTolerance, final double[] vecRelativeTolerance) throws IllegalArgumentException { - super("Adams-Moulton", order, order, minStep, maxStep, + super("Adams-Moulton", nSteps, nSteps + 1, minStep, maxStep, vecAbsoluteTolerance, vecRelativeTolerance); } Modified: commons/proper/math/trunk/src/test/org/apache/commons/math/ode/nonstiff/AdamsBashforthIntegratorTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/ode/nonstiff/AdamsBashforthIntegratorTest.java?rev=787050&r1=787049&r2=787050&view=diff ============================================================================== --- commons/proper/math/trunk/src/test/org/apache/commons/math/ode/nonstiff/AdamsBashforthIntegratorTest.java (original) +++ commons/proper/math/trunk/src/test/org/apache/commons/math/ode/nonstiff/AdamsBashforthIntegratorTest.java Sun Jun 21 17:01:03 2009 @@ -31,7 +31,7 @@ public void dimensionCheck() throws DerivativeException, IntegratorException { TestProblem1 pb = new TestProblem1(); FirstOrderIntegrator integ = - new AdamsBashforthIntegrator(3, 0.0, 1.0, 1.0e-10, 1.0e-10); + new AdamsBashforthIntegrator(2, 0.0, 1.0, 1.0e-10, 1.0e-10); integ.integrate(pb, 0.0, new double[pb.getDimension()+10], 1.0, new double[pb.getDimension()+10]); @@ -46,7 +46,7 @@ double[] vecAbsoluteTolerance = { 1.0e-15, 1.0e-16 }; double[] vecRelativeTolerance = { 1.0e-15, 1.0e-16 }; - FirstOrderIntegrator integ = new AdamsBashforthIntegrator(5, minStep, maxStep, + FirstOrderIntegrator integ = new AdamsBashforthIntegrator(4, minStep, maxStep, vecAbsoluteTolerance, vecRelativeTolerance); TestProblemHandler handler = new TestProblemHandler(pb, integ); @@ -69,7 +69,7 @@ double scalAbsoluteTolerance = Math.pow(10.0, i); double scalRelativeTolerance = 0.01 * scalAbsoluteTolerance; - FirstOrderIntegrator integ = new AdamsBashforthIntegrator(5, minStep, maxStep, + FirstOrderIntegrator integ = new AdamsBashforthIntegrator(4, minStep, maxStep, scalAbsoluteTolerance, scalRelativeTolerance); TestProblemHandler handler = new TestProblemHandler(pb, integ); @@ -100,7 +100,7 @@ TestProblem1 pb = new TestProblem1(); double range = pb.getFinalTime() - pb.getInitialTime(); - AdamsBashforthIntegrator integ = new AdamsBashforthIntegrator(3, 0, range, 1.0e-12, 1.0e-12); + AdamsBashforthIntegrator integ = new AdamsBashforthIntegrator(2, 0, range, 1.0e-12, 1.0e-12); TestProblemHandler handler = new TestProblemHandler(pb, integ); integ.addStepHandler(handler); integ.setMaxEvaluations(650); @@ -116,7 +116,7 @@ TestProblem5 pb = new TestProblem5(); double range = Math.abs(pb.getFinalTime() - pb.getInitialTime()); - FirstOrderIntegrator integ = new AdamsBashforthIntegrator(5, 0, range, 1.0e-12, 1.0e-12); + FirstOrderIntegrator integ = new AdamsBashforthIntegrator(4, 0, range, 1.0e-12, 1.0e-12); TestProblemHandler handler = new TestProblemHandler(pb, integ); integ.addStepHandler(handler); integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(), @@ -133,14 +133,14 @@ TestProblem6 pb = new TestProblem6(); double range = Math.abs(pb.getFinalTime() - pb.getInitialTime()); - for (int order = 2; order < 9; ++order) { + for (int nSteps = 1; nSteps < 8; ++nSteps) { AdamsBashforthIntegrator integ = - new AdamsBashforthIntegrator(order, 1.0e-6 * range, 0.1 * range, 1.0e-10, 1.0e-10); + new AdamsBashforthIntegrator(nSteps, 1.0e-6 * range, 0.1 * range, 1.0e-10, 1.0e-10); TestProblemHandler handler = new TestProblemHandler(pb, integ); integ.addStepHandler(handler); integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(), pb.getFinalTime(), new double[pb.getDimension()]); - if (order < 5) { + if (nSteps < 4) { assertTrue(integ.getEvaluations() > 160); } else { assertTrue(integ.getEvaluations() < 70); Modified: commons/proper/math/trunk/src/test/org/apache/commons/math/ode/nonstiff/AdamsMoultonIntegratorTest.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/org/apache/commons/math/ode/nonstiff/AdamsMoultonIntegratorTest.java?rev=787050&r1=787049&r2=787050&view=diff ============================================================================== --- commons/proper/math/trunk/src/test/org/apache/commons/math/ode/nonstiff/AdamsMoultonIntegratorTest.java (original) +++ commons/proper/math/trunk/src/test/org/apache/commons/math/ode/nonstiff/AdamsMoultonIntegratorTest.java Sun Jun 21 17:01:03 2009 @@ -31,7 +31,7 @@ public void dimensionCheck() throws DerivativeException, IntegratorException { TestProblem1 pb = new TestProblem1(); FirstOrderIntegrator integ = - new AdamsMoultonIntegrator(3, 0.0, 1.0, 1.0e-10, 1.0e-10); + new AdamsMoultonIntegrator(2, 0.0, 1.0, 1.0e-10, 1.0e-10); integ.integrate(pb, 0.0, new double[pb.getDimension()+10], 1.0, new double[pb.getDimension()+10]); @@ -46,9 +46,9 @@ double[] vecAbsoluteTolerance = { 1.0e-15, 1.0e-16 }; double[] vecRelativeTolerance = { 1.0e-15, 1.0e-16 }; - FirstOrderIntegrator integ = new AdamsMoultonIntegrator(5, minStep, maxStep, - vecAbsoluteTolerance, - vecRelativeTolerance); + FirstOrderIntegrator integ = new AdamsMoultonIntegrator(4, minStep, maxStep, + vecAbsoluteTolerance, + vecRelativeTolerance); TestProblemHandler handler = new TestProblemHandler(pb, integ); integ.addStepHandler(handler); integ.integrate(pb, @@ -69,9 +69,9 @@ double scalAbsoluteTolerance = Math.pow(10.0, i); double scalRelativeTolerance = 0.01 * scalAbsoluteTolerance; - FirstOrderIntegrator integ = new AdamsMoultonIntegrator(5, minStep, maxStep, - scalAbsoluteTolerance, - scalRelativeTolerance); + FirstOrderIntegrator integ = new AdamsMoultonIntegrator(4, minStep, maxStep, + scalAbsoluteTolerance, + scalRelativeTolerance); TestProblemHandler handler = new TestProblemHandler(pb, integ); integ.addStepHandler(handler); integ.integrate(pb, @@ -100,7 +100,7 @@ TestProblem1 pb = new TestProblem1(); double range = pb.getFinalTime() - pb.getInitialTime(); - AdamsMoultonIntegrator integ = new AdamsMoultonIntegrator(3, 0, range, 1.0e-12, 1.0e-12); + AdamsMoultonIntegrator integ = new AdamsMoultonIntegrator(2, 0, range, 1.0e-12, 1.0e-12); TestProblemHandler handler = new TestProblemHandler(pb, integ); integ.addStepHandler(handler); integ.setMaxEvaluations(650); @@ -116,7 +116,7 @@ TestProblem5 pb = new TestProblem5(); double range = Math.abs(pb.getFinalTime() - pb.getInitialTime()); - FirstOrderIntegrator integ = new AdamsMoultonIntegrator(5, 0, range, 1.0e-12, 1.0e-12); + FirstOrderIntegrator integ = new AdamsMoultonIntegrator(4, 0, range, 1.0e-12, 1.0e-12); TestProblemHandler handler = new TestProblemHandler(pb, integ); integ.addStepHandler(handler); integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(), @@ -133,14 +133,14 @@ TestProblem6 pb = new TestProblem6(); double range = Math.abs(pb.getFinalTime() - pb.getInitialTime()); - for (int order = 2; order < 8; ++order) { + for (int nSteps = 1; nSteps < 7; ++nSteps) { AdamsMoultonIntegrator integ = - new AdamsMoultonIntegrator(order, 1.0e-6 * range, 0.1 * range, 1.0e-9, 1.0e-9); + new AdamsMoultonIntegrator(nSteps, 1.0e-6 * range, 0.1 * range, 1.0e-9, 1.0e-9); TestProblemHandler handler = new TestProblemHandler(pb, integ); integ.addStepHandler(handler); integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(), pb.getFinalTime(), new double[pb.getDimension()]); - if (order < 5) { + if (nSteps < 4) { assertTrue(integ.getEvaluations() > 150); } else { assertTrue(integ.getEvaluations() < 90);