View Javadoc

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