TestOdeAdapt2


package odeadapt;

import java.awt.*;

/**
 * integrate the ODE of a damped peridically driven pendulum<br>
 * producing results at times given by the adaptation process
 */
public class TestOdeAdapt2 {
  public static void main(String[] args) {
    
    // set up the ODE
    double t0 = 0.0;
    double phi0 = Math.PI / 2.0;
    double phidot0 = 0.0;
    PendelErzwODE ode = new PendelErzwODE(phi0, phidot0, t0);
    ode.setA(115.0 / 100.0);
    
    // set up the solver 
    double tEnd = 200.0;
    double tol = 1.0 / 1000000000.0;
    ODEAdaptiveSolver solv = new ODEAdaptiveSolver(ode, tEnd);
    solv.setAbsoluteTolerance(tol);
    
    // arrays to store the results
    int maxsteps = 20000; // just a crude guess here
    double[] t = new double[maxsteps];
    double[] s = new double[maxsteps];
    t[0] = t0;
    s[0] = solv.x.get(0,0);
    
    // solve
    int nSteps = 0;
    try {
      while (t[nSteps] < tEnd - tol) {
	solv.nextStep();
	nSteps++;
	t[nSteps] = solv.t;
	s[nSteps] = solv.x.get(0,0);
      }
    } catch (Exception e) {
      // try/catch necessary for StepsizeTooSmallException
      // this catches an ArrayIndexOutOfBoundsException as well
      // Result: "works" even if the buffer is too small
      e.printStackTrace();
    }
    
    // display the results
    System.out.println("total number of steps: " + nSteps);
    Frame frame = new SimplePlot("TestOdeAdapt2", 500, 300, t, s, nSteps+1);
  }
}

previous    contents     next

Peter Junglas 20.12.1999