ODESolverRalston


package ode1d;

/**
 * solver using Ralston method
 */
public class ODESolverRalston extends ODESolver {

  /** sets ode and initial values */
  public ODESolverRalston(ODE ode) {
    super(ode);
  }

  /** computes solution at next time step<br>
   * using the 2nd order Ralston scheme
   */
  public void nextStep(double h) {
    double k1 = ode.f(x, t);
    
    double t1 = t + 3.0 / 4.0 * h;
    double x1 = x + 3.0 / 4.0 * h * k1;
    double k2 = ode.f(x1, t1);
    
    x += (1.0 / 3.0 * k1 + 2.0 / 3.0 * k2) * h;
    t += h;
  }
}

previous    contents     next

Peter Junglas 20.12.1999