/* * mw7.java - revised 23 Apr 07 - width 481, height 241 * @author jackord@kw.igs.net * wave incident (k) on a barrier (ik/n) wave transmitted (k) * (n can have any value, but is set equal to 4 in the example) * the barrier width equals the incident wavelength * plot shows the modulus of the wavefunction and the probability density */ import java.applet.Applet; import java.awt.*; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; public class mw7 extends Applet implements ActionListener { int kk=0; // Declarations String b1s="Plot"; Button b1=new Button(b1s); public void init() { setLayout(new FlowLayout(FlowLayout.LEFT)); setBackground(new Color(211, 211, 211)); add(b1); b1.addActionListener(this); } public void paint(Graphics g) { int x1, y1, x2, y2; double a1, r1, a2, r2, t, n; double phase1, phase2, phase3, phase4; double a, r, c, s, b, f, dx; double [] yy=new double[121]; g.setFont(new Font("TimesRoman", Font.PLAIN, 14)); g.setColor(Color.black); g.drawRect(0, 0, 480, 240); g.drawLine(240, 0, 240, 240); g.drawLine(360, 0, 360, 240); if (kk==1) { n=4; dx=Math.PI/20; b=2*Math.PI/n; c=(Math.exp(-b)+Math.exp(b))/2; // Complex arithmetic s=(Math.exp(-b)-Math.exp(b))/2; f=s*(n-1/n)/2; t=1/Math.sqrt(c*c+f*f); phase1=Math.atan2(f, c); r1=(n+1/n)*s*t/2; phase2=phase1-Math.PI/2; a2=Math.sqrt(1+n*n)*t/2; r2=a2; phase4=phase1+Math.atan2(n, 1); phase3=phase1-Math.atan2(n, 1); a1=100; r1=a1*r1; a2=a1*a2; r2=a1*r2; t=a1*t; // Amplitudes (finally) for (int j=0; j<=80; j=j+1) { yy[j]=a1*a1+r1*r1+2*a1*r1*Math.cos(2*j*dx+phase2); } for (int j=81; j<=120; j=j+1) { a=a2*Math.exp((j-120)*dx/n); r=r2*Math.exp((120-j)*dx/n); yy[j]=a*a+r*r+2*a2*r2*Math.cos(phase4-phase3); } g.setColor(Color.blue); g.drawString("Probability", 380, 60); g.drawString("Amplitude", 400, 75); x1=0; y1=240-(int)Math.sqrt(yy[0]); for (int j=1; j<=120; j=j+1) { x2=3*j; y2=240-(int)(Math.sqrt(yy[j])); g.drawLine(x1, y1, x2, y2); x1=x2; y1=y2; } x2=480; y2=240-(int)t; g.drawLine(x1, y1, x2, y2); g.setColor(Color.red); g.drawString("Probability", 380, 120); g.drawString("Density", 400, 135); x1=0; y1=240-(int)(yy[0]/250); for (int j=1; j<=120; j=j+1) { x2=3*j; y2=240-(int)(yy[j]/250); g.drawLine(x1, y1, x2, y2); x1=x2; y1=y2; } x2=480; y2=240-(int)(t*t/250); g.drawLine(x1, y1, x2, y2); } kk=0; } public void actionPerformed(ActionEvent e) { String tst; tst=e.getActionCommand(); if (b1s.equals(tst)) { kk=1; } repaint(); } }