/* file DoubleWell.java class for calculating motion in double well potential extends class DiffEqSystem */ import java.awt.*; public class DoubleWell extends DiffEqSystem { private double A; // parameter in double-well potential: V(x) = x*x(x*x-A*A) private double force; private double omega; private double mass; private double damping; public VariableSet resetvars; // constructor DoubleWell() { super(); // first call constructor of DiffEqSystem class A = 1.; // set default parameters force = 1.; omega = 2.*Math.PI*(0.2); mass = 1.; damping = 1.; // set # of degrees of freedom and initial conditions n_var = 2; double resetarray[] = {-A, 0}; resetvars = new VariableSet(0, resetarray); myvars = resetvars; } // constructor when initial conditions are given DoubleWell(VariableSet v) { this(); // first call no-argument constructor setvars(v); // set variables to those given } public double[] timederiv(double t, double[] xvec) { // equations of motion double x = xvec[0]; // x = position double p = xvec[1]; // p = momentum double[] temp = new double[n_var]; // array [dx/dt, dp/dt] temp[0] = p/mass; // dx/dt = p/mass temp[1] = ( force*Math.cos(omega*t) - damping * p/mass -4.*x*x*x + 2.*A*A*x ); return temp; } // methods for calculating potential in which particle moves public double potential(double x) { return x*x*(x*x - A*A); } public double potential(double x, double t) { return x*x*(x*x - A*A) - x*force*Math.cos(omega*t); } public double maxpotential(double xmin, double xmax) { // maximum value of potential in range [xmin, xmax] if(xmax < A) { return 0.; } else { if (Math.abs(xmax) > Math.abs(xmin)) { return potential(xmax); } else { return potential(xmin); } } } public double minpotential(double xmin, double xmax) { return potential(A/Math.sqrt(2)); } // set and get methods for system parameters public void setA(double aparam) { A = aparam; } public double getA() {return A;} public void setmass(double m) {mass=m;} public double getmass() {return mass;} public void setforce(double f) { force = f; } public double getforce() { return force; } public void setdamping(double d) {damping = d;} public double getdamping() {return damping;} public void setomega( double o ) { omega = o; } public double getomega() { return omega; } }