added the ode package from Mantissa

git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/math/trunk@512066 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Luc Maisonobe 2007-02-26 23:12:40 +00:00
parent 4b1994a2ff
commit e2ffb90572
73 changed files with 269 additions and 436 deletions

View File

@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.
package org.spaceroots.mantissa.ode;
package org.apache.commons.math.ode;
import java.io.ObjectInput;
import java.io.ObjectOutput;
@ -390,9 +390,7 @@ public abstract class AbstractStepInterpolator
try {
finalizeStep();
} catch (DerivativeException e) {
IOException ioe = new IOException();
ioe.initCause(e);
throw ioe;
throw new IOException(e.getMessage());
}
}

View File

@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.
package org.spaceroots.mantissa.ode;
package org.apache.commons.math.ode;
/**
* This abstract class holds the common part of all adaptive

View File

@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.
package org.spaceroots.mantissa.ode;
package org.apache.commons.math.ode;
/**
* This class implements the classical fourth order Runge-Kutta

View File

@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.
package org.spaceroots.mantissa.ode;
package org.apache.commons.math.ode;
/**
* This class implements a step interpolator for the classical fourth

View File

@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.
package org.spaceroots.mantissa.ode;
package org.apache.commons.math.ode;
import java.util.ArrayList;
import java.util.Iterator;
@ -316,7 +316,8 @@ public class ContinuousOutputModel
si.setInterpolatedTime(time);
} catch (DerivativeException de) {
throw new RuntimeException("unexpected DerivativeException caught", de);
throw new RuntimeException("unexpected DerivativeException caught: "
+ de.getMessage());
}
}

View File

@ -15,9 +15,9 @@
// specific language governing permissions and limitations
// under the License.
package org.spaceroots.mantissa.ode;
package org.apache.commons.math.ode;
import org.spaceroots.mantissa.MantissaException;
import org.apache.commons.math.MathException;
/**
* This exception is made available to users to report
@ -27,7 +27,7 @@ import org.spaceroots.mantissa.MantissaException;
* @version $Id: DerivativeException.java 1705 2006-09-17 19:57:39Z luc $
*/
public class DerivativeException
extends MantissaException {
extends MathException {
/** Simple constructor.
* Build an exception by translating and formating a message

View File

@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.
package org.spaceroots.mantissa.ode;
package org.apache.commons.math.ode;
/**
* This class implements the 5(4) Dormand-Prince integrator for Ordinary

View File

@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.
package org.spaceroots.mantissa.ode;
package org.apache.commons.math.ode;
/**
* This class represents an interpolator over the last step during an

View File

@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.
package org.spaceroots.mantissa.ode;
package org.apache.commons.math.ode;
/**
* This class implements the 8(5,3) Dormand-Prince integrator for Ordinary

View File

@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.
package org.spaceroots.mantissa.ode;
package org.apache.commons.math.ode;
import java.io.ObjectOutput;
import java.io.ObjectInput;
@ -270,9 +270,7 @@ class DormandPrince853StepInterpolator
// save the local attributes
finalizeStep();
} catch (DerivativeException e) {
IOException ioe = new IOException();
ioe.initCause(e);
throw ioe;
throw new IOException(e.getMessage());
}
out.writeInt(currentState.length);
for (int i = 0; i < currentState.length; ++i) {

View File

@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.
package org.spaceroots.mantissa.ode;
package org.apache.commons.math.ode;
/**
* This class is a step handler that do nothing.

View File

@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.
package org.spaceroots.mantissa.ode;
package org.apache.commons.math.ode;
import java.io.ObjectInput;
import java.io.ObjectOutput;
@ -113,9 +113,7 @@ public class DummyStepInterpolator
// we can now set the interpolated time and state
setInterpolatedTime(t);
} catch (DerivativeException e) {
IOException ioe = new IOException();
ioe.initCause(e);
throw ioe;
throw new IOException(e.getMessage());
}
}

View File

@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.
package org.spaceroots.mantissa.ode;
package org.apache.commons.math.ode;
/**
* This class implements a simple Euler integrator for Ordinary

View File

@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.
package org.spaceroots.mantissa.ode;
package org.apache.commons.math.ode;
/**
* This class implements a linear interpolator for step.

View File

@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.
package org.spaceroots.mantissa.ode;
package org.apache.commons.math.ode;
/** This class converts second order differential equations to first
* order ones.

View File

@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.
package org.spaceroots.mantissa.ode;
package org.apache.commons.math.ode;
/** This interface represents a first order differential equations set.
*

View File

@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.
package org.spaceroots.mantissa.ode;
package org.apache.commons.math.ode;
/** This interface represents a first order integrator for
* differential equations.

View File

@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.
package org.spaceroots.mantissa.ode;
package org.apache.commons.math.ode;
/**
* This interface represents a handler that should be called after

View File

@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.
package org.spaceroots.mantissa.ode;
package org.apache.commons.math.ode;
/**
* This class implements the Gill fourth order Runge-Kutta

View File

@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.
package org.spaceroots.mantissa.ode;
package org.apache.commons.math.ode;
/**
* This class implements a step interpolator for the Gill fourth

View File

@ -15,7 +15,7 @@
* limitations under the License.
*/
package org.spaceroots.mantissa.ode;
package org.apache.commons.math.ode;
/**
* This class implements a Gragg-Bulirsch-Stoer integrator for

View File

@ -15,7 +15,7 @@
* limitations under the License.
*/
package org.spaceroots.mantissa.ode;
package org.apache.commons.math.ode;
import java.io.ObjectInput;
import java.io.ObjectOutput;
@ -392,9 +392,7 @@ class GraggBulirschStoerStepInterpolator
// we can now set the interpolated time and state
setInterpolatedTime(t);
} catch (DerivativeException e) {
IOException ioe = new IOException();
ioe.initCause(e);
throw ioe;
throw new IOException(e.getMessage());
}
}

View File

@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.
package org.spaceroots.mantissa.ode;
package org.apache.commons.math.ode;
/**
* This class implements the 5(4) Higham and Hall integrator for

View File

@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.
package org.spaceroots.mantissa.ode;
package org.apache.commons.math.ode;
/**
* This class represents an interpolator over the last step during an

View File

@ -15,9 +15,9 @@
// specific language governing permissions and limitations
// under the License.
package org.spaceroots.mantissa.ode;
package org.apache.commons.math.ode;
import org.spaceroots.mantissa.MantissaException;
import org.apache.commons.math.MathException;
/**
* This exception is made available to users to report
@ -26,7 +26,7 @@ import org.spaceroots.mantissa.MantissaException;
* @version $Id: IntegratorException.java 1705 2006-09-17 19:57:39Z luc $
*/
public class IntegratorException
extends MantissaException {
extends MathException {
/** Simple constructor.
* Build an exception by translating and formating a message

View File

@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.
package org.spaceroots.mantissa.ode;
package org.apache.commons.math.ode;
/**
* This class implements a second order Runge-Kutta integrator for

View File

@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.
package org.spaceroots.mantissa.ode;
package org.apache.commons.math.ode;
/**
* This class implements a step interpolator for second order

View File

@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.
package org.spaceroots.mantissa.ode;
package org.apache.commons.math.ode;
/**
* This class implements the common part of all Runge-Kutta-Fehlberg

View File

@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.
package org.spaceroots.mantissa.ode;
package org.apache.commons.math.ode;
/**
* This class implements the common part of all fixed step Runge-Kutta

View File

@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.
package org.spaceroots.mantissa.ode;
package org.apache.commons.math.ode;
import java.io.ObjectInput;
import java.io.ObjectOutput;
@ -169,9 +169,7 @@ abstract class RungeKuttaStepInterpolator
// we can now set the interpolated time and state
setInterpolatedTime(t);
} catch (DerivativeException e) {
IOException ioe = new IOException();
ioe.initCause(e);
throw ioe;
throw new IOException(e.getMessage());
}
}

View File

@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.
package org.spaceroots.mantissa.ode;
package org.apache.commons.math.ode;
/** This interface represents a second order differential equations set.

View File

@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.
package org.spaceroots.mantissa.ode;
package org.apache.commons.math.ode;
/** This interface represents a second order integrator for
* differential equations.

View File

@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.
package org.spaceroots.mantissa.ode;
package org.apache.commons.math.ode;
/**
* This interface represents a handler that should be called after

View File

@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.
package org.spaceroots.mantissa.ode;
package org.apache.commons.math.ode;
import java.io.Externalizable;

View File

@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.
package org.spaceroots.mantissa.ode;
package org.apache.commons.math.ode;
/**
* This class wraps an object implementing {@link FixedStepHandler}

View File

@ -15,14 +15,15 @@
// specific language governing permissions and limitations
// under the License.
package org.spaceroots.mantissa.ode;
package org.apache.commons.math.ode;
import org.spaceroots.mantissa.functions.FunctionException;
import org.spaceroots.mantissa.functions.scalar.ComputableFunction;
import java.io.Serializable;
import org.spaceroots.mantissa.roots.ConvergenceChecker;
import org.spaceroots.mantissa.roots.RootsFinder;
import org.spaceroots.mantissa.roots.BrentSolver;
import org.apache.commons.math.ConvergenceException;
import org.apache.commons.math.FunctionEvaluationException;
import org.apache.commons.math.analysis.BrentSolver;
import org.apache.commons.math.analysis.UnivariateRealFunction;
import org.apache.commons.math.analysis.UnivariateRealSolver;
/** This class handles the state for one {@link SwitchingFunction
* switching function} during integration steps.
@ -39,10 +40,10 @@ import org.spaceroots.mantissa.roots.BrentSolver;
* @author L. Maisonobe
*
*/
class SwitchState
implements ComputableFunction, ConvergenceChecker {
class SwitchState implements Serializable {
private static final long serialVersionUID = 6944466361876662425L;
/** Serializable version identifier. */
private static final long serialVersionUID = 3256541562455482289L;
/** Switching function. */
private SwitchingFunction function;
@ -79,9 +80,6 @@ class SwitchState
/** Next action indicator. */
private int nextAction;
/** Interpolator valid for the current step. */
private StepInterpolator interpolator;
/** Simple constructor.
* @param function switching function
* @param maxCheckInterval maximal time interval between switching
@ -105,8 +103,6 @@ class SwitchState
increasing = true;
nextAction = SwitchingFunction.CONTINUE;
interpolator = null;
}
/** Reinitialize the beginning of the step.
@ -127,12 +123,10 @@ class SwitchState
* the end of the proposed step (this implies the step should be
* rejected)
*/
public boolean evaluateStep(StepInterpolator interpolator) {
public boolean evaluateStep(final StepInterpolator interpolator) {
try {
this.interpolator = interpolator;
double t1 = interpolator.getCurrentTime();
int n = Math.max(1, (int) Math.ceil(Math.abs(t1 - t0) / maxCheckInterval));
double h = (t1 - t0) / n;
@ -154,26 +148,36 @@ class SwitchState
// variation direction, with respect to the integration direction
increasing = (gb >= ga);
RootsFinder solver = new BrentSolver();
if (solver.findRoot(this, this, 1000, ta, ga, tb, gb)) {
if (Double.isNaN(previousEventTime)
|| (Math.abs(previousEventTime - solver.getRoot()) > convergence)) {
pendingEventTime = solver.getRoot();
if (pendingEvent
&& (Math.abs(t1 - pendingEventTime) <= convergence)) {
// we were already waiting for this event which was
// found during a previous call for a step that was
// rejected, this step must now be accepted since it
// properly ends exactly at the event occurrence
return false;
try {
UnivariateRealSolver solver = new BrentSolver(new UnivariateRealFunction() {
public double value(double t) throws FunctionEvaluationException {
try {
interpolator.setInterpolatedTime(t);
return function.g(t, interpolator.getInterpolatedState());
} catch (DerivativeException e) {
throw new FunctionEvaluationException(t, e);
}
}
});
solver.setAbsoluteAccuracy(convergence);
solver.setMaximalIterationCount(1000);
double root = solver.solve(ta, tb);
if (Double.isNaN(previousEventTime) || (Math.abs(previousEventTime - root) > convergence)) {
pendingEventTime = root;
if (pendingEvent && (Math.abs(t1 - pendingEventTime) <= convergence)) {
// we were already waiting for this event which was
// found during a previous call for a step that was
// rejected, this step must now be accepted since it
// properly ends exactly at the event occurrence
return false;
}
// either we were not waiting for the event or it has
// moved in such a way the step cannot be accepted
pendingEvent = true;
return true;
}
// either we were not waiting for the event or it has
// moved in such a way the step cannot be accepted
pendingEvent = true;
return true;
}
} else {
throw new RuntimeException("internal error");
} catch (ConvergenceException ce) {
throw new RuntimeException("internal error");
}
} else {
@ -190,9 +194,9 @@ class SwitchState
return false;
} catch (DerivativeException e) {
throw new RuntimeException("unexpected exception", e);
} catch (FunctionException e) {
throw new RuntimeException("unexpected exception", e);
throw new RuntimeException("unexpected exception: " + e.getMessage());
} catch (FunctionEvaluationException e) {
throw new RuntimeException("unexpected exception: " + e.getMessage());
}
}
@ -260,35 +264,4 @@ class SwitchState
}
/** Get the value of the g function at the specified time.
* @param t current time
* @return g function value
* @exception FunctionException if the underlying interpolator is
* unable to interpolate the state at the specified time
*/
public double valueAt(double t)
throws FunctionException {
try {
interpolator.setInterpolatedTime(t);
return function.g(t, interpolator.getInterpolatedState());
} catch (DerivativeException e) {
throw new FunctionException(e);
}
}
/** Check if the event time has been found.
* @param x0 lower bound of the interval
* @param y0 value of the function at x0
* @param x1 higher bound of the interval
* @param y1 value of the function at x1
* @return convergence indicator
*/
public int converged(double x0, double y0, double x1, double y1) {
if (Math.abs(x1 - x0) < convergence) {
return (Math.abs(y0) < Math.abs(y1))
? ConvergenceChecker.LOW : ConvergenceChecker.HIGH;
}
return ConvergenceChecker.NONE;
}
}

View File

@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.
package org.spaceroots.mantissa.ode;
package org.apache.commons.math.ode;
import java.io.Serializable;

View File

@ -15,9 +15,9 @@
// specific language governing permissions and limitations
// under the License.
package org.spaceroots.mantissa.ode;
package org.apache.commons.math.ode;
import org.spaceroots.mantissa.ode.DerivativeException;
import org.apache.commons.math.ode.DerivativeException;
import java.util.ArrayList;
import java.util.Iterator;
@ -120,7 +120,7 @@ public class SwitchingFunctionsHandler {
return first != null;
} catch (DerivativeException e) {
throw new RuntimeException("unexpected exception", e);
throw new RuntimeException("unexpected exception: " + e.getMessage());
}
}

View File

@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.
package org.spaceroots.mantissa.ode;
package org.apache.commons.math.ode;
/**
* This class implements the 3/8 fourth order Runge-Kutta

View File

@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.
package org.spaceroots.mantissa.ode;
package org.apache.commons.math.ode;
/**
* This class implements a step interpolator for the 3/8 fourth

View File

@ -1,53 +0,0 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package org.spaceroots.mantissa.ode;
import junit.framework.Test;
import junit.framework.TestSuite;
public class AllTests {
public static Test suite() {
TestSuite suite = new TestSuite("org.spaceroots.mantissa.ode");
suite.addTest(EulerStepInterpolatorTest.suite());
suite.addTest(EulerIntegratorTest.suite());
suite.addTest(MidpointIntegratorTest.suite());
suite.addTest(ClassicalRungeKuttaIntegratorTest.suite());
suite.addTest(GillIntegratorTest.suite());
suite.addTest(ThreeEighthesIntegratorTest.suite());
suite.addTest(HighamHall54IntegratorTest.suite());
suite.addTest(DormandPrince54IntegratorTest.suite());
suite.addTest(DormandPrince853IntegratorTest.suite());
suite.addTest(GraggBulirschStoerIntegratorTest.suite());
suite.addTest(FirstOrderConverterTest.suite());
suite.addTest(StepNormalizerTest.suite());
suite.addTest(ContinuousOutputModelTest.suite());
suite.addTest(ClassicalRungeKuttaStepInterpolatorTest.suite());
suite.addTest(GillStepInterpolatorTest.suite());
suite.addTest(ThreeEighthesStepInterpolatorTest.suite());
suite.addTest(DormandPrince853StepInterpolatorTest.suite());
suite.addTest(DormandPrince54StepInterpolatorTest.suite());
suite.addTest(HighamHall54StepInterpolatorTest.suite());
suite.addTest(MidpointStepInterpolatorTest.suite());
suite.addTest(GraggBulirschStoerStepInterpolatorTest.suite());
return suite;
}
}

View File

@ -15,13 +15,17 @@
// specific language governing permissions and limitations
// under the License.
package org.spaceroots.mantissa.ode;
package org.apache.commons.math.ode;
import junit.framework.*;
import org.spaceroots.mantissa.estimation.EstimationException;
import org.spaceroots.mantissa.estimation.LevenbergMarquardtEstimator;
import org.spaceroots.mantissa.fitting.PolynomialFitter;
import org.apache.commons.math.ode.ClassicalRungeKuttaIntegrator;
import org.apache.commons.math.ode.DerivativeException;
import org.apache.commons.math.ode.FirstOrderIntegrator;
import org.apache.commons.math.ode.IntegratorException;
import org.apache.commons.math.ode.StepHandler;
import org.apache.commons.math.ode.StepInterpolator;
import org.apache.commons.math.ode.SwitchingFunction;
public class ClassicalRungeKuttaIntegratorTest
extends TestCase {
@ -91,47 +95,6 @@ public class ClassicalRungeKuttaIntegratorTest
}
public void testOrder()
throws EstimationException, DerivativeException,
IntegratorException {
PolynomialFitter fitter =
new PolynomialFitter(1, new LevenbergMarquardtEstimator());
TestProblemAbstract[] problems = TestProblemFactory.getProblems();
for (int k = 0; k < problems.length; ++k) {
for (int i = 0; i < 10; ++i) {
TestProblemAbstract pb = (TestProblemAbstract) problems[k].clone();
double step = (pb.getFinalTime() - pb.getInitialTime())
* Math.pow(2.0, -(i + 1));
FirstOrderIntegrator integ = new ClassicalRungeKuttaIntegrator(step);
TestProblemHandler handler = new TestProblemHandler(pb);
integ.setStepHandler(handler);
SwitchingFunction[] functions = pb.getSwitchingFunctions();
for (int l = 0; l < functions.length; ++l) {
integ.addSwitchingFunction(functions[l],
Double.POSITIVE_INFINITY, 1.0e-6 * step);
}
integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(),
pb.getFinalTime(), new double[pb.getDimension()]);
fitter.addWeightedPair(1.0,
Math.log(Math.abs(step)),
Math.log(handler.getLastError()));
}
// this is an order 4 method
double[] coeffs = fitter.fit();
assertTrue(coeffs[1] > 3.2);
assertTrue(coeffs[1] < 4.8);
}
}
public void testSmallStep()
throws DerivativeException, IntegratorException {

View File

@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.
package org.spaceroots.mantissa.ode;
package org.apache.commons.math.ode;
import junit.framework.*;
import java.util.Random;
@ -25,6 +25,11 @@ import java.io.ObjectOutputStream;
import java.io.ObjectInputStream;
import java.io.IOException;
import org.apache.commons.math.ode.ClassicalRungeKuttaIntegrator;
import org.apache.commons.math.ode.ContinuousOutputModel;
import org.apache.commons.math.ode.DerivativeException;
import org.apache.commons.math.ode.IntegratorException;
public class ClassicalRungeKuttaStepInterpolatorTest
extends TestCase {

View File

@ -15,11 +15,17 @@
// specific language governing permissions and limitations
// under the License.
package org.spaceroots.mantissa.ode;
package org.apache.commons.math.ode;
import junit.framework.*;
import java.util.Random;
import org.apache.commons.math.ode.ContinuousOutputModel;
import org.apache.commons.math.ode.DerivativeException;
import org.apache.commons.math.ode.DormandPrince54Integrator;
import org.apache.commons.math.ode.FirstOrderIntegrator;
import org.apache.commons.math.ode.IntegratorException;
public class ContinuousOutputModelTest
extends TestCase {

View File

@ -15,7 +15,16 @@
// specific language governing permissions and limitations
// under the License.
package org.spaceroots.mantissa.ode;
package org.apache.commons.math.ode;
import org.apache.commons.math.ode.AdaptiveStepsizeIntegrator;
import org.apache.commons.math.ode.DerivativeException;
import org.apache.commons.math.ode.DormandPrince54Integrator;
import org.apache.commons.math.ode.FirstOrderIntegrator;
import org.apache.commons.math.ode.IntegratorException;
import org.apache.commons.math.ode.StepHandler;
import org.apache.commons.math.ode.StepInterpolator;
import org.apache.commons.math.ode.SwitchingFunction;
import junit.framework.*;

View File

@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.
package org.spaceroots.mantissa.ode;
package org.apache.commons.math.ode;
import junit.framework.*;
import java.util.Random;
@ -25,6 +25,11 @@ import java.io.ObjectOutputStream;
import java.io.ObjectInputStream;
import java.io.IOException;
import org.apache.commons.math.ode.ContinuousOutputModel;
import org.apache.commons.math.ode.DerivativeException;
import org.apache.commons.math.ode.DormandPrince54Integrator;
import org.apache.commons.math.ode.IntegratorException;
public class DormandPrince54StepInterpolatorTest
extends TestCase {

View File

@ -15,7 +15,16 @@
// specific language governing permissions and limitations
// under the License.
package org.spaceroots.mantissa.ode;
package org.apache.commons.math.ode;
import org.apache.commons.math.ode.DerivativeException;
import org.apache.commons.math.ode.DormandPrince853Integrator;
import org.apache.commons.math.ode.DummyStepHandler;
import org.apache.commons.math.ode.FirstOrderIntegrator;
import org.apache.commons.math.ode.IntegratorException;
import org.apache.commons.math.ode.StepHandler;
import org.apache.commons.math.ode.StepInterpolator;
import org.apache.commons.math.ode.SwitchingFunction;
import junit.framework.*;

View File

@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.
package org.spaceroots.mantissa.ode;
package org.apache.commons.math.ode;
import junit.framework.*;
import java.util.Random;
@ -25,6 +25,11 @@ import java.io.ObjectOutputStream;
import java.io.ObjectInputStream;
import java.io.IOException;
import org.apache.commons.math.ode.ContinuousOutputModel;
import org.apache.commons.math.ode.DerivativeException;
import org.apache.commons.math.ode.DormandPrince853Integrator;
import org.apache.commons.math.ode.IntegratorException;
public class DormandPrince853StepInterpolatorTest
extends TestCase {

View File

@ -15,13 +15,15 @@
// specific language governing permissions and limitations
// under the License.
package org.spaceroots.mantissa.ode;
package org.apache.commons.math.ode;
import junit.framework.*;
import org.spaceroots.mantissa.estimation.EstimationException;
import org.spaceroots.mantissa.estimation.LevenbergMarquardtEstimator;
import org.spaceroots.mantissa.fitting.PolynomialFitter;
import org.apache.commons.math.ode.DerivativeException;
import org.apache.commons.math.ode.EulerIntegrator;
import org.apache.commons.math.ode.FirstOrderIntegrator;
import org.apache.commons.math.ode.IntegratorException;
import org.apache.commons.math.ode.SwitchingFunction;
public class EulerIntegratorTest
extends TestCase {
@ -80,48 +82,6 @@ public class EulerIntegratorTest
}
public void testOrder()
throws EstimationException, DerivativeException,
IntegratorException {
PolynomialFitter fitter =
new PolynomialFitter(1, new LevenbergMarquardtEstimator());
TestProblemAbstract[] problems = TestProblemFactory.getProblems();
for (int k = 0; k < problems.length; ++k) {
for (int i = 0; i < 10; ++i) {
TestProblemAbstract pb = (TestProblemAbstract) problems[k].clone();
double step = (pb.getFinalTime() - pb.getInitialTime())
* Math.pow(2.0, -(i + 1));
FirstOrderIntegrator integ = new EulerIntegrator(step);
TestProblemHandler handler = new TestProblemHandler(pb);
integ.setStepHandler(handler);
SwitchingFunction[] functions = pb.getSwitchingFunctions();
for (int l = 0; l < functions.length; ++l) {
integ.addSwitchingFunction(functions[l],
Double.POSITIVE_INFINITY, 1.0e-6 * step);
}
integ.integrate(pb,
pb.getInitialTime(), pb.getInitialState(),
pb.getFinalTime(), new double[pb.getDimension()]);
fitter.addWeightedPair(1.0,
Math.log(Math.abs(step)),
Math.log(handler.getLastError()));
}
// this is an order 1 method
double[] coeffs = fitter.fit();
assertTrue(coeffs[1] > 0.2);
assertTrue(coeffs[1] < 1.8);
}
}
public void testSmallStep()
throws DerivativeException, IntegratorException {

View File

@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.
package org.spaceroots.mantissa.ode;
package org.apache.commons.math.ode;
import junit.framework.*;
import java.util.Random;
@ -25,6 +25,13 @@ import java.io.ObjectOutputStream;
import java.io.ObjectInputStream;
import java.io.IOException;
import org.apache.commons.math.ode.ContinuousOutputModel;
import org.apache.commons.math.ode.DerivativeException;
import org.apache.commons.math.ode.EulerIntegrator;
import org.apache.commons.math.ode.EulerStepInterpolator;
import org.apache.commons.math.ode.FirstOrderDifferentialEquations;
import org.apache.commons.math.ode.IntegratorException;
public class EulerStepInterpolatorTest
extends TestCase {

View File

@ -15,7 +15,13 @@
// specific language governing permissions and limitations
// under the License.
package org.spaceroots.mantissa.ode;
package org.apache.commons.math.ode;
import org.apache.commons.math.ode.ClassicalRungeKuttaIntegrator;
import org.apache.commons.math.ode.DerivativeException;
import org.apache.commons.math.ode.FirstOrderConverter;
import org.apache.commons.math.ode.IntegratorException;
import org.apache.commons.math.ode.SecondOrderDifferentialEquations;
import junit.framework.*;

View File

@ -15,13 +15,17 @@
// specific language governing permissions and limitations
// under the License.
package org.spaceroots.mantissa.ode;
package org.apache.commons.math.ode;
import junit.framework.*;
import org.spaceroots.mantissa.estimation.EstimationException;
import org.spaceroots.mantissa.estimation.LevenbergMarquardtEstimator;
import org.spaceroots.mantissa.fitting.PolynomialFitter;
import org.apache.commons.math.ode.DerivativeException;
import org.apache.commons.math.ode.FirstOrderIntegrator;
import org.apache.commons.math.ode.GillIntegrator;
import org.apache.commons.math.ode.IntegratorException;
import org.apache.commons.math.ode.StepHandler;
import org.apache.commons.math.ode.StepInterpolator;
import org.apache.commons.math.ode.SwitchingFunction;
public class GillIntegratorTest
extends TestCase {
@ -78,47 +82,6 @@ public class GillIntegratorTest
}
public void testOrder()
throws EstimationException, DerivativeException,
IntegratorException {
PolynomialFitter fitter =
new PolynomialFitter(1, new LevenbergMarquardtEstimator());
TestProblemAbstract[] problems = TestProblemFactory.getProblems();
for (int k = 0; k < problems.length; ++k) {
for (int i = 0; i < 10; ++i) {
TestProblemAbstract pb = (TestProblemAbstract) problems[k].clone();
double step = (pb.getFinalTime() - pb.getInitialTime())
* Math.pow(2.0, -(i + 1));
FirstOrderIntegrator integ = new GillIntegrator(step);
TestProblemHandler handler = new TestProblemHandler(pb);
integ.setStepHandler(handler);
SwitchingFunction[] functions = pb.getSwitchingFunctions();
for (int l = 0; l < functions.length; ++l) {
integ.addSwitchingFunction(functions[l],
Double.POSITIVE_INFINITY, 1.0e-6 * step);
}
integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(),
pb.getFinalTime(), new double[pb.getDimension()]);
fitter.addWeightedPair(1.0,
Math.log(Math.abs(step)),
Math.log(handler.getLastError()));
}
// this is an order 4 method
double[] coeffs = fitter.fit();
assertTrue(coeffs[1] > 3.2);
assertTrue(coeffs[1] < 4.8);
}
}
public void testSmallStep()
throws DerivativeException, IntegratorException {

View File

@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.
package org.spaceroots.mantissa.ode;
package org.apache.commons.math.ode;
import junit.framework.*;
import java.util.Random;
@ -25,6 +25,11 @@ import java.io.ObjectOutputStream;
import java.io.ObjectInputStream;
import java.io.IOException;
import org.apache.commons.math.ode.ContinuousOutputModel;
import org.apache.commons.math.ode.DerivativeException;
import org.apache.commons.math.ode.GillIntegrator;
import org.apache.commons.math.ode.IntegratorException;
public class GillStepInterpolatorTest
extends TestCase {

View File

@ -15,7 +15,15 @@
// specific language governing permissions and limitations
// under the License.
package org.spaceroots.mantissa.ode;
package org.apache.commons.math.ode;
import org.apache.commons.math.ode.DerivativeException;
import org.apache.commons.math.ode.FirstOrderIntegrator;
import org.apache.commons.math.ode.GraggBulirschStoerIntegrator;
import org.apache.commons.math.ode.IntegratorException;
import org.apache.commons.math.ode.StepHandler;
import org.apache.commons.math.ode.StepInterpolator;
import org.apache.commons.math.ode.SwitchingFunction;
import junit.framework.*;

View File

@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.
package org.spaceroots.mantissa.ode;
package org.apache.commons.math.ode;
import junit.framework.*;
import java.util.Random;
@ -25,6 +25,11 @@ import java.io.ObjectOutputStream;
import java.io.ObjectInputStream;
import java.io.IOException;
import org.apache.commons.math.ode.ContinuousOutputModel;
import org.apache.commons.math.ode.DerivativeException;
import org.apache.commons.math.ode.GraggBulirschStoerIntegrator;
import org.apache.commons.math.ode.IntegratorException;
public class GraggBulirschStoerStepInterpolatorTest
extends TestCase {

View File

@ -15,7 +15,15 @@
// specific language governing permissions and limitations
// under the License.
package org.spaceroots.mantissa.ode;
package org.apache.commons.math.ode;
import org.apache.commons.math.ode.DerivativeException;
import org.apache.commons.math.ode.FirstOrderIntegrator;
import org.apache.commons.math.ode.HighamHall54Integrator;
import org.apache.commons.math.ode.IntegratorException;
import org.apache.commons.math.ode.StepHandler;
import org.apache.commons.math.ode.StepInterpolator;
import org.apache.commons.math.ode.SwitchingFunction;
import junit.framework.*;

View File

@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.
package org.spaceroots.mantissa.ode;
package org.apache.commons.math.ode;
import junit.framework.*;
import java.util.Random;
@ -25,6 +25,11 @@ import java.io.ObjectOutputStream;
import java.io.ObjectInputStream;
import java.io.IOException;
import org.apache.commons.math.ode.ContinuousOutputModel;
import org.apache.commons.math.ode.DerivativeException;
import org.apache.commons.math.ode.HighamHall54Integrator;
import org.apache.commons.math.ode.IntegratorException;
public class HighamHall54StepInterpolatorTest
extends TestCase {

View File

@ -15,13 +15,15 @@
// specific language governing permissions and limitations
// under the License.
package org.spaceroots.mantissa.ode;
package org.apache.commons.math.ode;
import junit.framework.*;
import org.spaceroots.mantissa.estimation.EstimationException;
import org.spaceroots.mantissa.estimation.LevenbergMarquardtEstimator;
import org.spaceroots.mantissa.fitting.PolynomialFitter;
import org.apache.commons.math.ode.DerivativeException;
import org.apache.commons.math.ode.FirstOrderIntegrator;
import org.apache.commons.math.ode.IntegratorException;
import org.apache.commons.math.ode.MidpointIntegrator;
import org.apache.commons.math.ode.SwitchingFunction;
public class MidpointIntegratorTest
extends TestCase {
@ -78,47 +80,6 @@ public class MidpointIntegratorTest
}
public void testOrder()
throws EstimationException, DerivativeException, IntegratorException {
PolynomialFitter fitter =
new PolynomialFitter(1, new LevenbergMarquardtEstimator());
TestProblemAbstract[] problems = TestProblemFactory.getProblems();
for (int k = 0; k < problems.length; ++k) {
for (int i = 0; i < 10; ++i) {
TestProblemAbstract pb = (TestProblemAbstract) problems[k].clone();
double step = (pb.getFinalTime() - pb.getInitialTime())
* Math.pow(2.0, -(i + 1));
FirstOrderIntegrator integ = new MidpointIntegrator(step);
TestProblemHandler handler = new TestProblemHandler(pb);
integ.setStepHandler(handler);
SwitchingFunction[] functions = pb.getSwitchingFunctions();
for (int l = 0; l < functions.length; ++l) {
integ.addSwitchingFunction(functions[l],
Double.POSITIVE_INFINITY, 1.0e-6 * step);
}
integ.integrate(pb,
pb.getInitialTime(), pb.getInitialState(),
pb.getFinalTime(), new double[pb.getDimension()]);
fitter.addWeightedPair(1.0,
Math.log(Math.abs(step)),
Math.log(handler.getLastError()));
}
// this is an order 2 method
double[] coeffs = fitter.fit();
assertTrue(coeffs[1] > 1.2);
assertTrue(coeffs[1] < 2.8);
}
}
public void testSmallStep()
throws DerivativeException, IntegratorException {

View File

@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.
package org.spaceroots.mantissa.ode;
package org.apache.commons.math.ode;
import junit.framework.*;
import java.util.Random;
@ -25,6 +25,11 @@ import java.io.ObjectOutputStream;
import java.io.ObjectInputStream;
import java.io.IOException;
import org.apache.commons.math.ode.ContinuousOutputModel;
import org.apache.commons.math.ode.DerivativeException;
import org.apache.commons.math.ode.IntegratorException;
import org.apache.commons.math.ode.MidpointIntegrator;
public class MidpointStepInterpolatorTest
extends TestCase {

View File

@ -15,7 +15,14 @@
// specific language governing permissions and limitations
// under the License.
package org.spaceroots.mantissa.ode;
package org.apache.commons.math.ode;
import org.apache.commons.math.ode.DerivativeException;
import org.apache.commons.math.ode.DormandPrince54Integrator;
import org.apache.commons.math.ode.FirstOrderIntegrator;
import org.apache.commons.math.ode.FixedStepHandler;
import org.apache.commons.math.ode.IntegratorException;
import org.apache.commons.math.ode.StepNormalizer;
import junit.framework.*;

View File

@ -1,4 +1,7 @@
package org.spaceroots.mantissa.ode;
package org.apache.commons.math.ode;
import org.apache.commons.math.ode.FirstOrderDifferentialEquations;
import org.apache.commons.math.ode.SwitchingFunction;
public class StepProblem

View File

@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.
package org.spaceroots.mantissa.ode;
package org.apache.commons.math.ode;
/**
* This class is used in the junit tests for the ODE integrators.

View File

@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.
package org.spaceroots.mantissa.ode;
package org.apache.commons.math.ode;
/**
* This class is used in the junit tests for the ODE integrators.

View File

@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.
package org.spaceroots.mantissa.ode;
package org.apache.commons.math.ode;
/**
* This class is used in the junit tests for the ODE integrators.

View File

@ -15,7 +15,9 @@
// specific language governing permissions and limitations
// under the License.
package org.spaceroots.mantissa.ode;
package org.apache.commons.math.ode;
import org.apache.commons.math.ode.SwitchingFunction;
/**
* This class is used in the junit tests for the ODE integrators.

View File

@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.
package org.spaceroots.mantissa.ode;
package org.apache.commons.math.ode;
/**
* This class is used in the junit tests for the ODE integrators.

View File

@ -15,7 +15,10 @@
// specific language governing permissions and limitations
// under the License.
package org.spaceroots.mantissa.ode;
package org.apache.commons.math.ode;
import org.apache.commons.math.ode.FirstOrderDifferentialEquations;
import org.apache.commons.math.ode.SwitchingFunction;
/**
* This class is used as the base class of the problems that are

View File

@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.
package org.spaceroots.mantissa.ode;
package org.apache.commons.math.ode;
/**
* This class is used in the junit tests for the ODE integrators.

View File

@ -15,7 +15,11 @@
// specific language governing permissions and limitations
// under the License.
package org.spaceroots.mantissa.ode;
package org.apache.commons.math.ode;
import org.apache.commons.math.ode.DerivativeException;
import org.apache.commons.math.ode.StepHandler;
import org.apache.commons.math.ode.StepInterpolator;
/**
* This class is used to handle steps for the test problems

View File

@ -15,13 +15,17 @@
// specific language governing permissions and limitations
// under the License.
package org.spaceroots.mantissa.ode;
package org.apache.commons.math.ode;
import junit.framework.*;
import org.spaceroots.mantissa.estimation.EstimationException;
import org.spaceroots.mantissa.estimation.LevenbergMarquardtEstimator;
import org.spaceroots.mantissa.fitting.PolynomialFitter;
import org.apache.commons.math.ode.DerivativeException;
import org.apache.commons.math.ode.FirstOrderIntegrator;
import org.apache.commons.math.ode.IntegratorException;
import org.apache.commons.math.ode.StepHandler;
import org.apache.commons.math.ode.StepInterpolator;
import org.apache.commons.math.ode.SwitchingFunction;
import org.apache.commons.math.ode.ThreeEighthesIntegrator;
public class ThreeEighthesIntegratorTest
extends TestCase {
@ -78,48 +82,7 @@ public class ThreeEighthesIntegratorTest
}
public void testOrder()
throws EstimationException, DerivativeException,
IntegratorException {
PolynomialFitter fitter =
new PolynomialFitter(1, new LevenbergMarquardtEstimator());
TestProblemAbstract[] problems = TestProblemFactory.getProblems();
for (int k = 0; k < problems.length; ++k) {
for (int i = 0; i < 10; ++i) {
TestProblemAbstract pb = (TestProblemAbstract) problems[k].clone();
double step = (pb.getFinalTime() - pb.getInitialTime())
* Math.pow(2.0, -(i + 1));
FirstOrderIntegrator integ = new ThreeEighthesIntegrator(step);
TestProblemHandler handler = new TestProblemHandler(pb);
integ.setStepHandler(handler);
SwitchingFunction[] functions = pb.getSwitchingFunctions();
for (int l = 0; l < functions.length; ++l) {
integ.addSwitchingFunction(functions[l],
Double.POSITIVE_INFINITY, 1.0e-6 * step);
}
integ.integrate(pb, pb.getInitialTime(), pb.getInitialState(),
pb.getFinalTime(), new double[pb.getDimension()]);
fitter.addWeightedPair(1.0,
Math.log(Math.abs(step)),
Math.log(handler.getLastError()));
}
// this is an order 4 method
double[] coeffs = fitter.fit();
assertTrue(coeffs[1] > 3.2);
assertTrue(coeffs[1] < 4.8);
}
}
public void testSmallStep()
public void testSmallStep()
throws DerivativeException, IntegratorException {
TestProblem1 pb = new TestProblem1();

View File

@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.
package org.spaceroots.mantissa.ode;
package org.apache.commons.math.ode;
import junit.framework.*;
import java.util.Random;
@ -25,6 +25,11 @@ import java.io.ObjectOutputStream;
import java.io.ObjectInputStream;
import java.io.IOException;
import org.apache.commons.math.ode.ContinuousOutputModel;
import org.apache.commons.math.ode.DerivativeException;
import org.apache.commons.math.ode.IntegratorException;
import org.apache.commons.math.ode.ThreeEighthesIntegrator;
public class ThreeEighthesStepInterpolatorTest
extends TestCase {