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