1
2
3
4
5
6
7
8
9
10
11 package nl.tudelft.simulation.jstats.ode.integrators;
12
13 import nl.tudelft.simulation.jstats.ode.DifferentialEquationInterface;
14
15 /***
16 * The Adams-Bashforth-Moulton numerical estimator as described in <a
17 * href="http://mathworld.wolfram.com/AdamsMethod.html">
18 * http://mathworld.wolfram.com/AdamsMethod.html </a>
19 * <p>
20 * (c) copyright 2003 <a href="http://www.simulation.tudelft.nl">Delft
21 * University of Technology </a>, the Netherlands. <br>
22 * See for project information <a
23 * href="http://www.simulation.tudelft.nl">www.simulation.tudelft.nl </a> <br>
24 * License of use: <a href="http://www.gnu.org/copyleft/gpl.html">General Public
25 * License (GPL) </a>, no warranty <br>
26 *
27 * @author <a href="http://www.tbm.tudelft.nl/webstaf/peterja/index.htm">Peter
28 * Jacobs </a>
29 * @version 1.2 Apr 21, 2004
30 * @since 1.4
31 */
32 public class Adams extends CachingNumericalIntegrator
33 {
34 /***
35 * constructs a new Adams integrator
36 *
37 * @param timeStep the timeStep to use in the estimation.
38 * @param equation the equation to use.
39 */
40 public Adams(final double timeStep,
41 final DifferentialEquationInterface equation)
42 {
43 super(timeStep, equation, 4, NumericalIntegrator.RUNGEKUTTA4, 10);
44 }
45
46 /***
47 * constructs a new Adams integrator, indicating the starting method and
48 * number of substeps
49 *
50 * @param timeStep the timeStep to use in the estimation.
51 * @param equation the equation to use.
52 * @param integrationMethod the primer integrator to use
53 * @param startingSubSteps the number of substeps per timestep during
54 * starting of the integrator
55 */
56 public Adams(final double timeStep,
57 final DifferentialEquationInterface equation,
58 final short integrationMethod, final int startingSubSteps)
59 {
60 super(timeStep, equation, 4, integrationMethod, startingSubSteps);
61 }
62
63 /***
64 * @see nl.tudelft.simulation.jstats.ode.integrators.CachingNumericalIntegrator
65 * #next(double)
66 */
67 public double[] next(final double x)
68 {
69 double[] y0 = super.getY(0);
70 double[] dy0 = super.getDY(0);
71 double[] dy1 = super.getDY(1);
72 double[] dy2 = super.getDY(2);
73 double[] dy3 = super.getDY(3);
74 double[] sum = super.add(super.multiply(-9, dy3), super.multiply(37,
75 dy2), super.multiply(-59, dy1), super.multiply(55, dy0));
76 sum = super.multiply(this.timeStep / 24.0, sum);
77 double[] p = super.add(y0, sum);
78 sum = super.add(dy2, super.multiply(-5, dy1), super.multiply(19, dy0),
79 super.multiply(9, this.equation.dy(x + this.timeStep, p)));
80 return super.add(y0, super.multiply(this.timeStep / 24.0, sum));
81 }
82 }