View Javadoc

1   /*
2    * @(#) Heun.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  package nl.tudelft.simulation.jstats.ode.integrators;
11  
12  import nl.tudelft.simulation.jstats.ode.DifferentialEquationInterface;
13  
14  /***
15   * The Heun numerical estimator.
16   * <p>
17   * (c) copyright 2003 <a href="http://www.simulation.tudelft.nl">Delft
18   * University of Technology </a>, the Netherlands. <br>
19   * See for project information <a
20   * href="http://www.simulation.tudelft.nl">www.simulation.tudelft.nl </a> <br>
21   * License of use: <a href="http://www.gnu.org/copyleft/gpl.html">General Public
22   * License (GPL) </a>, no warranty <br>
23   * 
24   * @author <a href="http://www.tbm.tudelft.nl/webstaf/peterja/index.htm">Peter
25   *         Jacobs </a>
26   * @version 1.2 Apr 20, 2004
27   * @since 1.4
28   */
29  public class Heun extends NumericalIntegrator
30  {
31  	/***
32  	 * constructs a new Heun
33  	 * 
34  	 * @param timeStep the timeStep
35  	 * @param equation the equation
36  	 */
37  	public Heun(final double timeStep,
38  			final DifferentialEquationInterface equation)
39  	{
40  		super(timeStep, equation);
41  	}
42  
43  	/***
44  	 * @see nl.tudelft.simulation.jstats.ode.integrators.NumericalIntegrator
45  	 *      #next(double, double[])
46  	 */
47  	public double[] next(final double x, final double[] y)
48  	{
49  		double[] f0 = this.equation.dy(x, y);
50  		double[] p = super.add(y, super.multiply(this.timeStep, f0));
51  		return super.add(y, super.multiply(0.5 * this.timeStep, super.add(f0,
52  				this.equation.dy(x + this.timeStep, p))));
53  	}
54  }