// Program name - harmony.java - PhD Project // written by Jeff Mirick // February 14, 1999 // There are 3 classes in the program // 1.) myfunction - defines the evolution of the // harmonic oscillator in time. // 2.) plot - Defines the ground sate for the harmonic oscillator problem // for the two values of k. // 3.) harmony - Is the main executable class defining the animation, // panels, and graphical interfaces. import java.awt.*; import java.awt.event.*; import java.util.*; import java.applet.*; import java.awt.image.ImageObserver; class myfunction { int i; double w_not,pi; double y[] = new double[500]; double potential[] = new double[500]; double fk1[] = new double[500]; double xx; int maxx,maxy,minx,miny; double xlow,xhigh,ylow,yhigh,E0; public void init() { xlow=-3.0; xhigh=3.0; ylow=0.0; yhigh=3.0; minx=0; miny=0; maxx=350; maxy=300; pi=3.14159265; } void compute(int itime, double k1, double k2) { // // Defines time evolution of harmonic oscillator // double a127_2,a125_2,a123_2,a12_2,cos2,cos4,cos6; double a1,a2,a12,a123,a125,c1,e,prob; double psi0,psi2,psi4,psi6,sa1a2,a2p,t,factor; w_not=Math.sqrt(k2); a1=Math.sqrt(k1); a2=Math.sqrt(k2); sa1a2=Math.sqrt(Math.sqrt(a1*a2)); a12=a1+a2; a2p=Math.sqrt(Math.sqrt(a2/pi)); a123=a12*a12*a12; a125=a123*a12*a12; c1=a2p*sa1a2; a12_2=Math.sqrt(2.0/a12); a123_2=Math.sqrt(2.0/a123); a125_2=Math.sqrt(2.0/a125); a127_2=Math.sqrt(2.0/a125/a12/a12); // // t=(double)(itime)/50.0; cos2=Math.cos(2.0*w_not*t); cos4=Math.cos(4.0*w_not*t); cos6=Math.cos(6.0*w_not*t); for(i=0;iminy) g.drawLine(ix,iy,ix1,iy1); iy=iy1; ix=ix1; } g.setColor(Color.green); g.drawLine(0, maxy, maxx, maxy); ix=minx; iy=maxy-2-(int)((y[0]-ylow)*(maxy-miny)/(yhigh-ylow)); for(i=1;iminy) g.drawLine(ix,iy,ix1,iy1); iy=iy1; ix=ix1; } g.setColor(Color.blue); ix=minx; iy=maxy-2-(int)((potential[0]-ylow)*(maxy-miny)/(yhigh-ylow)); for(i=1;i