/* * h5a.java - revised 19 Apr 05 - width 601, height 301 * @author jackord@kw.igs.net */ import java.applet.Applet; import java.awt.*; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; public class h5a extends Applet implements ActionListener { int k=0; // Declarations double s, s1, b, c, yo, vo; String b1s = "BB1"; Button bb1 = new Button(b1s); String b2s = "BB2"; Button bb2 = new Button(b2s); String b3s = "BB3"; Button bb3 = new Button(b3s); String h1s = "HO1"; Button ho1 = new Button(h1s); String h2s = "HO2"; Button ho2 = new Button(h2s); String h3s = "HO3"; Button ho3 = new Button(h3s); public void init() { // Layout add(bb1); add(bb2); add(bb3); add(ho1); add(ho2); add(ho3); bb1.addActionListener(this); bb2.addActionListener(this); bb3.addActionListener(this); ho1.addActionListener(this); ho2.addActionListener(this); ho3.addActionListener(this); setBackground(new Color(211, 211, 211)); } double fey(double e, Graphics g) { // Feynman Algorithm double x, y, v, a, dx; int x1, y1, x2, y2; int i=0; int n=500; dx=.002; x=0; y=yo; v=vo; s=y*y*dx/2; x1=0; y1=(int)(150*(1-y)); if (k==1) { a=e*e*e*(x-1)*y; } else { a=e*e*(x*x-1)*y; } v=v+a*dx/2; while ((y>-1) && (y<1) && (x<3)) { i=i+1; x=x+dx; y=y+v*dx; x2=(int)(200*x); y2=(int)(150*(1-y)); g.drawLine(x1, y1, x2, y2); x1=x2; y1=y2; if (k==1) { a=e*e*e*(x-1)*y; } else { a=e*e*(x*x-1)*y; } v=v+a*dx; if ((x<1) || (v*y<0)) { // Trapezoid Algorithm s=s+y*y*dx; if (i==n) { s1=s-y*y*dx/2; } } } return y; } public void paint(Graphics g) { // Bisection Algorithm double e, de, yb, yc; g.setColor(Color.black); g.drawRect(0, 0, 600, 300); g.setFont(new Font("TimesRoman", Font.PLAIN, 14)); g.drawLine(0, 150, 600, 150); g.drawLine(200, 0, 200, 300); g.drawLine(400, 0, 400, 300); g.setColor(Color.blue); if (k>0) { de=0.00001; yb=fey(b, g); yc=fey(c, g); if (yb*yc<0) { while ((c-b)>de) { e=(b+c)/2; if (fey(e, g)*yb>0) { b=e; } else { c=e; } } g.setColor(Color.red); e=(b+c)/2; yb=fey(e, g); g.drawString("Energy EigenValue ="+(float)e, 220, 260); g.drawString("Probability z>1 ="+(float)(1-s1/s), 220, 280); } } k=0; } public void actionPerformed(ActionEvent e) { // Buttons String tst; tst=e.getActionCommand(); if (b1s.equals(tst)) { k=1; b=2; c=3; yo=0; vo=2; } if (b2s.equals(tst)) { k=1; b=3; c=5; yo=0; vo=4; } if (b3s.equals(tst)) { k=1; b=5; c=6; yo=0; vo=8; } if (h1s.equals(tst)) { k=2; b=.5; c=1.5; yo=.8; vo=0; } if (h2s.equals(tst)) { k=2; b=2; c=4; yo=0; vo=2; } if (h3s.equals(tst)) { k=2; b=4; c=6; yo=.8; vo=0; } repaint(); } }