ODESolverRalston


package odeadapt;

import Jama.*;

/**
 * ODESolverRalston.java
 * solves a given ODE by giving the "next" value for x 
 * using Ralston method
 */
public class ODESolverRalston extends ODESingleStepSolver {

  /**
   * construct solver for a given ODE
   */
  public ODESolverRalston(ODE ode) {
    super(ode);
    order = 2;
  }

  /*
   * integrate until t + h
   * using the second order Ralston scheme
   */
  public int nextStep(double h) {
    Matrix k1 = ode.f(x, t);
    double t1 = t + 3.0 / 4.0 * h;
    
    // x1 = x + 3.0/4.0*h*k1;
    Matrix x1 = x.plus(k1.times(3.0 / 4.0 * h));
    Matrix k2 = ode.f(x1, t1);
    
    // x += (1.0/3.0*k1 + 2.0/3.0*k2)*h;
    x.plusEquals(k1.times(h / 3.0));
    x.plusEquals(k2.times(h * 2.0 / 3.0));
    t += h;
    return 1;
  }
}

previous    contents     next

Peter Junglas 20.12.1999