View Javadoc

1   /*
2    * @(#) Gill.java Apr 20, 2004
3    * 
4    * Copyright (c) 2003 Delft University of Technology Jaffalaan 5, 2628 BX Delft,
5    * the Netherlands All rights reserved.
6    * 
7    * This software is proprietary information of Delft University of Technology
8    * The code is published under the General Public License
9    */
10  
11  package nl.tudelft.simulation.jstats.ode.integrators;
12  
13  import nl.tudelft.simulation.jstats.ode.DifferentialEquationInterface;
14  
15  /***
16   * The Gill numerical estimator as described in <a
17   * href="http://mathworld.wolfram.com/GillsMethod.html">
18   * http://mathworld.wolfram.com/GillsMethod.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 20, 2004
30   * @since 1.4
31   */
32  public class Gill extends NumericalIntegrator
33  {
34  	/*** constant: sqrt(2) */
35  	private static final double SQRT2 = Math.sqrt(2.0d);
36  
37  	/*** constant: 1/2 sqrt(2) */
38  	private static final double SQRT2D2 = 0.5d * Math.sqrt(2.0d);
39  
40  	/***
41  	 * constructs a new Gill integrator
42  	 * 
43  	 * @param timeStep the timeStep
44  	 * @param equation the differentialEquation
45  	 */
46  	public Gill(final double timeStep,
47  			final DifferentialEquationInterface equation)
48  	{
49  		super(timeStep, equation);
50  	}
51  
52  	/***
53  	 * @see nl.tudelft.simulation.jstats.ode.integrators.NumericalIntegrator
54  	 *      #next(double,double[])
55  	 */
56  	public double[] next(final double x, final double[] y)
57  	{
58  		double[] k1 = this.equation.dy(x, y);
59  		double[] k2 = this.equation.dy(x + 0.5d * this.timeStep, super.add(y,
60  				super.multiply(0.5d, k1)));
61  		double[] k3 = this.equation.dy(x + 0.5d * this.timeStep, super.add(y,
62  				super.multiply((-0.5d + Gill.SQRT2D2), k1), super.multiply(
63  						(1.0d - Gill.SQRT2D2), k2)));
64  		double[] k4 = this.equation.dy(x + this.timeStep, super.add(y, super
65  				.multiply((-Gill.SQRT2D2), k2), super.multiply(
66  				(1.0d + Gill.SQRT2D2), k3)));
67  		double[] sum = super.add(k1, super.multiply((2.0d - Gill.SQRT2), k2),
68  				super.multiply((2.0d + Gill.SQRT2), k3), k4);
69  		return super.add(y, super.multiply(this.timeStep / 6.0d, sum));
70  	}
71  }