/* * qm3.java - revised 27 Dec 07 - width 481, height 221 * @author jackord@kw.igs.net * quantum wave pulse incident on a variable thickness region ("film") where * the kinetic energy increases by a factor 1.44 followed by a region where * it increases again by a factor of 1.44 * the motion is generated either directly from the Schrodinger equation * or from an expansion in terms of the stationary states of the system */ import java.applet.Applet; import java.awt.*; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; public class qm3 extends Applet implements ActionListener { int kk=0; int plt=0; int first=0; int dl=0; // Declarations double pi=Math.PI; double e1; double [] k=new double[64]; double [][] y=new double[64][481]; String b1s="P Dens"; Button b1=new Button(b1s); String b2s="R Comp"; Button b2=new Button(b2s); String b3s="Motion"; Button b3=new Button(b3s); Choice ch=new Choice(); Checkbox ch1=new Checkbox("Series"); Image bim; Graphics bgr; public void init() { setLayout(new FlowLayout(FlowLayout.LEFT)); setBackground(new Color(211, 211, 211)); ch.setBackground(getBackground()); ch1.setBackground(getBackground()); ch.addItem("D(film)=0"); ch.addItem("D(film)=5"); ch.addItem("D(film)=10"); add(b1); b1.addActionListener(this); add(b2); b2.addActionListener(this); add(b3); b3.addActionListener(this); add(ch); add(ch1); } double f(double k1) { // The upper right... double c1, c, c2, s1, s, s2, k, k2, a, b; a=pi/240; k=Math.sqrt(k1*k1+0.44*e1); k2=Math.sqrt(k1*k1+1.076*e1); c1=Math.cos(a*k1*240); s1=Math.sin(a*k1*240); c=Math.cos(a*k*dl); s=Math.sin(a*k*dl); c2=Math.cos(a*k2*(240-dl)); s2=Math.sin(a*k2*(240-dl)); b=k*k*s*s1*s2-k1*c1*k*c*s2-k1*c1*k2*c2*s-k*c*k2*c2*s1; return b; // ...matrix element } public void findk() { // Find the k-values int cnt=0; // for which the double a, b, c, e; // matrix element = 0 a=f(4); e=0.00001; for (int i=41; i<=410; i=i+1) { // Scan for zero crossings b=f(0.1*i); // in the range of interest if (a*b<0) { cnt=cnt+1; k[cnt]=0.1*i; } a=b; } for (int i=1; i<=cnt; i=i+1) { // Use a binary search a=k[i]-.1; b=k[i]; // to refine the values while ((b-a)>e) { c=(a+b)/2; if (f(c)*f(a)>0) { a=c; } else { b=c; } } k[i]=(a+b)/2; } k[0]=cnt; } public void fey() { // Find 60 stationary states double z, v, a, c, e, s, dx; int ii, jj; c=pi/240; c=c*c; dx=0.05; for (int i=1; i<=60; i=i+1) { e=k[i]*k[i]; a=-e*c; s=0; z=0; v=1; ii=0; jj=0; for (int j=1; j<=9600; j=j+1) { z=z+v*dx; if (j==4800) { a=-(0.44*e1+e)*c; } if (j==(4800+20*dl)) { a=-(1.0736*e1+e)*c; } v=v+a*z*dx; s=s+z*z; jj=jj+1; if (jj==20) { jj=0; ii=ii+1; y[i][ii]=z; } } s=Math.sqrt(s*dx); for (int j=1; j<=480; j=j+1) { // Normalize them y[i][j]=y[i][j]/s; } } } public void paint(Graphics g) { int no, nw, nf, nk, c, jt, del, tdel, y1, y2; int n=480; double [] yr=new double[n+1]; double [] yrr=new double[n+1]; double [] dyr=new double[n+1]; double [] yi=new double[n+1]; double [] yii=new double[n+1]; double [] dyi=new double[n+1]; double [] b=new double[61]; double [] d=new double[61]; double [] w=new double[61]; double phi, s, vv, yy, dt, p2; no=104; nw=96; nf=320; nk=4; s=0; e1=0; // Constants p2=pi*pi/(n/2*n/2); c=20; dt=1.2*n/2*n/2/(4*pi*c*nf*nk*nk); // Direct solution constants dl=5*ch.getSelectedIndex(); // Film thickness g.setColor(Color.black); g.drawRect(0, 0, 480, 220); if (first==0) { bim=createImage(481, 221); // Animation buffer bgr=bim.getGraphics(); first=1; } if (kk>0) { for (int i=0; i<=nw; i=i+1) { // Initial wave pulse phi=i*2*pi/nw; yr[no+i]=2/Math.sqrt(6*nw)*(1-Math.cos(phi)); yi[no+i]=-yr[no+i]*Math.sin(phi*nk); yr[no+i]=yr[no+i]*Math.cos(phi*nk); } e1=0; for (int i=no; i<=no+nw; i=i+1) { // Calculate e1 e1=e1-yr[i]*(yr[i-1]+yr[i+1]-2*yr[i])-yi[i]*(yi[i-1]+yi[i+1]-2*yi[i]); dyr[i]=dt*(yi[i-1]+yi[i+1]-2*yi[i]); // Initialize dy's dyi[i]=-dt*(yr[i-1]+yr[i+1]-2*yr[i]); } e1=e1/p2; if (ch1.getState()==true) { // Series findk(); // Find k[i] fey(); // Find y[i][j] for (int i=1; i<=60; i=i+1) { // Expansion coefficients for (int j=1; j<=n-1; j=j+1) { b[i]=b[i]+yr[j]*y[i][j]; d[i]=d[i]+yi[j]*y[i][j]; } w[i]=1.2*pi/64*k[i]*k[i]/nf; // Frequencies (including constants) } } jt=0; y1=120; long tt=System.currentTimeMillis(); del=25; do { // Frame loop bgr.setColor(getBackground()); // Set up plot buffer bgr.fillRect(0, 0, 480, 220); bgr.setColor(Color.blue); for (int i=1; i<=n; i=i+1) { if (i==n/2) { bgr.setColor(Color.green); } if (i==n/2+dl) { bgr.setColor(Color.red); } if (kk==1) { // Probability density y2=220-(int)(6800*(yr[i]*yr[i]+yi[i]*yi[i])+.5); bgr.drawLine(i, y2, i, 220); } else { // yr[i] y2=120-(int)(480*yr[i]+.5); bgr.drawLine(i-1, y1, i, y2); y1=y2; } } bgr.setColor(Color.black); bgr.drawRect(0, 0, 480, 220); bgr.drawString("Frame "+jt+"/"+nf, 380, 20); g.drawImage(bim, 0, 0, null); // Show plot buffer jt=jt+1; if (ch1.getState()==true) { // Series for (int i=1; i<=n-1; i=i+1) { yr[i]=0; yi[i]=0; for (int j=1; j<=60; j=j+1) { yr[i]=yr[i]+y[j][i]*(b[j]*Math.cos(w[j]*jt)-d[j]*Math.sin(w[j]*jt)); yi[i]=yi[i]+y[j][i]*(b[j]*Math.sin(w[j]*jt)+d[j]*Math.cos(w[j]*jt)); } } } else { // Direct solution for (int jj=1; jj<=c; jj=jj+1) { // Accuracy loop for (int i=1; i<=n-1; i=i+1) { // Project ahead dy/2 yrr[i]=yr[i]+dyr[i]/2; yii[i]=yi[i]+dyi[i]/2; } vv=0; for (int i=1; i<=n-1; i=i+1) { if (i==n/2) { vv=-0.44*e1; } if (i==n/2+dl) {vv=-1.0736*e1; } // Schrodinger equation dyr[i]=dt*(yii[i-1]+yii[i+1]-2*yii[i]-p2*vv*yii[i]); dyi[i]=-dt*(yrr[i-1]+yrr[i+1]-2*yrr[i]-p2*vv*yrr[i]); yr[i]=yr[i]+dyr[i]; yi[i]=yi[i]+dyi[i]; } } } while (tt>System.currentTimeMillis()) { } tt=tt+del; if (jt==nf+1) { for (int i=1; i<=n/2-1; i=i+1) { // Reflection probability s=s+yr[i]*yr[i]+yi[i]*yi[i]; } s=(int)(s*1000)/10.; g.drawString("Reflection Probability = "+s+" %", 10, 45); kk=0; plt=0; } } while (plt==1); } } public void actionPerformed(ActionEvent e) { // Buttons String tst; tst=e.getActionCommand(); if (b1s.equals(tst)) { kk=1; } // P Dens if (b2s.equals(tst)) { kk=2; } // R Comp if (b3s.equals(tst)) { if (kk>0) { plt=1; } } // Motion repaint(); } }