Program: Two_slit.bas

Implementation Select: Implementation
Operation Select: Program: TWO_SLIT.BAS

DECLARE SUB CURVE (ydist#)
DEFDBL A-Z
'                       TWO_SLIT.BAS
'       Revision 1.0    Original                          15 Jan 1996
'       Revision 2.0    Add random single slit experiment 19 Jan 1996
'       Revision 2.1    Add # of photons for test # 5     20 Jan 1996
'       Revision 3      Divide test 1 in two parts        29 Oct 1996
'                       Add comments, improve input test  29 Oct 1996
'
DIM SHARED m1, i1%, l, totm2, height, pixel, pixel2
DIM inx(50), iny(50), display(620)
CONST pi = 3.141592653589#
CLS
SCREEN 12
height = 20
pixel = 620: pixel2 = pixel / 2
l = 1: i1% = 5: i2% = 35
fmf = 10 / l         ' freq multiply factor
LOCATE 1, 1: COLOR 12: PRINT "x";
COLOR 7: PRINT " = position slit"
LOCATE 7, 40: COLOR 12: PRINT "x"
LOCATE 11, 44: COLOR 12: PRINT "x"
COLOR 7

' experiment 1 & 2  -  1 slit

LOCATE 1, 50: PRINT "one slit"
LOCATE 7, 50: PRINT "one slit"
LOCATE 12, 50: PRINT "two slits - distance = "; l
totm1 = 0
FOR i% = 0 TO pixel
  COLOR 15
  m1 = 1 + COS((i% - pixel2) * pi / pixel2)
  totm1 = totm1 + m1
  PSET (i% + i1%, 95 - height * m1), 15
  PSET (i% + i1%, 95), 7
  PSET (i% + i1%, 155), 7
  PSET (i% + i2%, 155 - height * m1), 7
  PSET (i% + i2%, 155), 7
NEXT i%
photons = height * INT(totm1) ' # photons = surface area of shape

' experiment 3  -  2 slits

CURVE 200 + 45
  LOCATE 17, 40 + l * 4: COLOR 12: PRINT "x"
  LOCATE 17, 40 - l * 4: COLOR 12: PRINT "x"
  COLOR 7
  LOCATE 2, 50: PRINT "Total # of photons = "; photons
  LOCATE 13, 50: PRINT "Total # of photons = "; INT(photons * totm2 / totm1)

' experiment 4  -  2 slits
 
  LOCATE 18, 1: INPUT "distance between the two slits ? ", l
CURVE 300 + 45
  LOCATE 18, 50: PRINT "two slits - distance = "; l
  LOCATE 18, 1: PRINT SPACE$(40)
  IF l > 9.6 THEN l = 9.6
  LOCATE 23, 40 + l * 4: COLOR 12: PRINT "x"
  LOCATE 23, 40 - l * 4: COLOR 12: PRINT "x"
  COLOR 7
  LOCATE 19, 50: PRINT "Total # of photons = "; INT(photons * totm2 / totm1)

' experiment 5  - 2 slits
 
  LOCATE 24, 1: INPUT "distance between the two slits ? ", l
  LOCATE 24, 1: PRINT SPACE$(40)
CURVE 430 + 16
  LOCATE 24, 50: PRINT "two slits - distance = "; l
  COLOR 7
  LOCATE 25, 50: PRINT "Total # of photons = "; INT(photons * totm2 / totm1)
  IF l > 9.6 THEN l = 9.6
  LOCATE 29, 40 + l * 4: COLOR 12: PRINT "x";
  LOCATE 29, 40 - l * 4: COLOR 12: PRINT "x";

' experiment 6 - 1 slit

MAXL = 600: sigma = 1: dimmax = 50
dx = 3 * sigma / MAXL
COLOR 11
LOCATE 2, 1: INPUT "Total # of photons ? ", photons
total = 0: j% = 0

' calculate gauss curve (inx) and sum curve (iny)

FOR i% = -MAXL TO MAXL           ' - 3 * sigma to 3 * sigma
  x = i% * dx
  e1 = EXP(-(x * x) / sigma)
  total = total + e1 * dx
  IF i% MOD MAXL * 2 / dimmax = 0 THEN
'   PRINT "j "; j%; i%; TAB(12); x; TAB(18); e1; TAB(42); total
    inx(j%) = x: iny(j%) = total
    j% = j% + 1
  END IF
NEXT i%
' PRINT total; iny(dimmax); j%; inx(dimmax)

' calculate curve

FOR j% = 1 TO photons
  p = RND(1) * iny(dimmax)
  IF j% MOD 100 = 0 THEN LOCATE 3, 1: PRINT j%
  FOR i% = 0 TO dimmax
    IF iny(i%) > p THEN
      alp = (p - iny(i% - 1)) / (iny(i%) - iny(i% - 1))
      nn = alp * (inx(i%) - inx(i% - 1)) + inx(i% - 1)
      inn% = pixel * (nn + inx(dimmax)) / (2 * inx(dimmax))
'     PRINT p; i%; TAB(35); nn; TAB(60); inn%: IF j% = 100 THEN END
      IF inn% < 0 THEN inn% = 0
      IF inn% > pixel THEN inn% = pixel
      display(inn%) = display(inn%) + 1
      GOTO exp1
    END IF
  NEXT i%
exp1:
NEXT j%
LOCATE 2, 1: PRINT SPACE$(40)
LOCATE 3, 1: PRINT SPACE$(10)

' display curve

FOR i% = 0 TO pixel
  PSET (i% + i1%, 95 - display(i%)), 11
NEXT i%
LOCATE 3, 50: PRINT "Total # of photons = "; photons
COLOR 7

SUB CURVE (ydist)
totm2 = 0
IF l < .25 THEN l = .25                             ' correction input
IF l > 10 THEN l = 10
fmf = 10 / l
FOR i% = 0 TO pixel
  COLOR 15
  m1 = 1 + COS((i% - pixel2) * pi / pixel2)               ' slit 1
  m2 = 1 + COS((i% - pixel2) * pi * fmf / pixel2)         ' slit 2
  totm2 = totm2 + m1 * m2 / 2
  PSET (i% + i1%, ydist - height * m1 * m2 / 2), 15     ' curve
  PSET (i% + i1%, ydist), 7                         ' base line
NEXT i%
END SUB


Back to my home page Contents of This Document