//this program corresponds to Section E of the report. Here we measure the seperation of two closep points in x-coordinate, which is more practical than length in phase-space. /*
*/ // Applet for plotting solutions to oscillator problem import javax.swing.*; import P251.*; public class testchaos extends P251Applet { DoubleWell dw1; // dynamics object VariableSet vars; // variables (time, x, momentum) double[] x, xplot, pplot, t; // arrays for plotting double[] xdifference, tdifference; int N; // number of time steps double deltax = 0.001; // this is the initial separation of two points. private inputPanel ip1, ip2; // declare input panel objects private graphPanel gpX, gpP, gpPS; // declare graph panel objects public void fillPanels() { ip1 = new inputPanel(); ip1.addField("dt",.01); ip1.addField("A",1.); ip1.addField("force",4.); addPanel(ip1); // adds input panel 1 to applet ip2 = new inputPanel(); ip2.addField("omega",Math.PI); ip2.addField("mass",1.); ip2.addField("damping",1.); addPanel(ip2); // adds input panel 2 to applet gpX = new graphPanel(900,300,false); gpX.setXLabel("t"); gpX.setYLabel("x"); gpX.setTitle("Position Evolution"); gpX.setDotSize(2); addPanel(gpX); // adds graph panel to applet gpP = new graphPanel(900,300,false); gpP.setXLabel("t"); gpP.setYLabel("p"); gpP.setTitle("Momentum Evolution"); gpP.setDotSize(2); addPanel(gpP); // adds graph panel to applet gpPS = new graphPanel(900,300,false); //the plot of distance separation gpPS.setXLabel("t"); gpPS.setYLabel("delta x"); gpPS.setTitle("x difference plot"); gpPS.setDotSize(2); addPanel(gpPS); // adds graph panel to applet } //end of fillPanels public void initValues() { dw1 = new DoubleWell(); // initialize object dw1.setdt(.01); // initialize DoubleWell parameters dw1.setA(1.); dw1.setforce(4.); dw1.setomega(Math.PI); dw1.setmass(1.); dw1.setdamping(1.); //initialize input field values to match the parameters above ip1.setValue(0, dw1.getdt()); //"dt" ip1.setValue(1, dw1.getA()); //"A" ip1.setValue(2, dw1.getforce()); //"force" ip2.setValue(0, dw1.getomega()); //"omega" ip2.setValue(1, dw1.getmass()); //"mass" ip2.setValue(2, dw1.getdamping()); //"damping" N = 20000; // Number of Time Steps so that tmax < 100 xplot = new double[2*(N+1)]; // array of positions pplot = new double[2*(N+1)]; // array of momenta t = new double[2*(N+1)]; // array of times xdifference = new double[N+1]; //here is array for the separation evolved in time for plot tdifference = new double[N+1]; t[0] = 0.0; // initial time xplot[0] = -1.2; // initial x pplot[0] = 0.0; // initial p x = new double[2]; // pair x and p x[0] = xplot[0]; // initial x x[1] = pplot[0]; // initial p vars = new VariableSet(0.0,x); // set initial variables dw1.setvars(vars); } //end of initValues public void compute () { int i; readValues(); //this is for the first point evolution for (i=1; i<=N; i++) { // loop to compute solution vars = dw1.nextvars(); // advance in time 1 step dw1.setvars(vars); // bring old variables up to date x = vars.getx(); // extract x and p t[i] = vars.gettime(); // extract and store t for plotting xplot[i] = x[0]; // store x for plotting pplot[i] = x[1]; // store p for plotting } //end of i loop: now trajectories have been calculated*/ t[N] = 0.0; xplot[N] = xplot[0]+deltax; pplot[N] = pplot[0]; x[0] = xplot[N]; x[1] = pplot[N]; vars.settime(0.0); vars.setx(x); dw1.setvars(vars); //this is for the second point evolution for (i=N+1; i<=2*N; i++){ vars = dw1.nextvars(); // advance in time 1 step dw1.setvars(vars); // bring old variables up to date x = vars.getx(); // extract x and p t[i] = vars.gettime(); // extract and store t for plotting xplot[i] = x[0]; // store x for plotting pplot[i] = x[1]; // store p for plotting } gpX.addData(t,xplot,"name"); gpP.addData(t,pplot,"name"); //here we extract the distance between two points over time for (i=0; i<=N; i++){ xdifference[i]= Math.abs(xplot[i]-xplot[i+N])); tdifference[i]=t[i]; } gpPS.addData(tdifference,xdifference,"name"); //plot the graph //t[0] = t[2N+1]; // setup t for next round //xplot[0] = xplot[2N+1]; // setup x for next round //pplot[0] = pplot[2N+1]; // setup p for next round //tdifference[0]=tdifference[N]; //xdifference[0]=xdifference[N]; } public void readValues() { dw1.setdt(ip1.getValue(0)); // input panel 1 dw1.setA(ip1.getValue(1)); dw1.setforce(ip1.getValue(2)); dw1.setomega(ip2.getValue(0)); // input panel 2 dw1.setmass(ip2.getValue(1)); dw1.setdamping(ip2.getValue(2)); } } //end of Oscillator