/** * Demonstration program to use the integrator class * to perform a RK4 integration of the Harmonic * equations with output via ptplot */ import uk.ac.ed.ph.integrator.*; // Import integrator classes import ptolemy.plot.*; // Import ptplot classes public class HarmonicTest { public static void main(String args[]) { double omega0 = 5.0; // Natural frequecy double gamma = 0.2; // Normalsied dampling double omega = 5.5; // Forcing frequecy double a = 4.0; // Forcing amplituide // Make the differential equations. HarmonicEquations eqn = new HarmonicEquations(omega0,gamma,omega,a); // Make the RK4 solver and attach the equations RungeKutta solver = new RungeKutta(eqn); // Setup initial consitions, with 2 paramter // DataPoint DataPoint initial = new DataPoint(2); initial.setX(0.0); // Set time initial.setY(0,0.0); // Position initial.setY(1,0.0); // Velocity // Set the initial consitions in the solver. solver.setStartConditions(initial); solver.setStep(0.01); // Inital step size solver.setAccuracy(1.0e-8); // Accuracy solver.setAdaptiveTestInternal(100); // Steps before adaptive test solver.setVerbose(true); // Set verbose output // Do the solve, to x = 50 with adaptive step // This stores all the data points in solver solver.solve(50.0,true); // Setup output graph Plot plot = new Plot(); // Read the data out of the solver point at a time for(int i = 0; i < solver.size(); i++ ) { DataPoint p = solver.get(i); // Get DataPoint plot.addPoint(0,p.getX(), p.getY(0),true); // Get dislacement plot.addPoint(1,p.getX(), p.getY(1),true); // Get velocity } plot.setTitle("Harmonic Plot"); // Set plot title (optional) plot.setXLabel("Time"); // Set x label plot.setYLabel("Disp/Vel"); // Set y label // Make a frame to display the plot PlotFrame frame = new PlotFrame("A plot",plot); frame.setSize(600,400); // Set size of frame (in pixels) frame.setVisible(true); // Make frame visible } }