#!/usr/bin/perl
# 
# compute the amplitude of waves formed by 4-slit interference
#
# MWR 4/25/2019

$debug = 1;

$mypi = 3.14159;

# spacing between slits (m)
$a = 0.0004;
# wavelength of light (m)
$lambda = 550.0E-9;
# distance to far wall (m)
$L = 10;



# "y" will be the distance away from mid-point of the far wall
#    in other words, how far to the side of center of pattern
#   
$start_y = 0.0;
$end_y = 5.5E-1;
$d_y = 1.0E-4;

$max_amp = -1.0;

$N = 4.0;

for ($y = $start_y + $d_y; $y <= $end_y; $y += $d_y) {

  # compute the angle of this point from center of pattern
  #      as seen by the center of slit (radians)
  $theta = $y / $L;

  $arg = ($mypi*$a*$y)/($lambda*$L);
  if ($arg == 0.0) {
    $val = 1.0;
  }
  else {
    $val = sin(4.0*$arg)/sin($arg);
  }
 
  $amp = $val*$val;

  # if this is the first iteration, set the maximum amplitude
  #   to the current value -- as this is (very close to) the center
  if ($max_amp == -1) {
    $max_amp = $amp;
  }
  

  printf " y %10.5f  theta %10.5e  val %10.5e  amp %10.5e  norm_inten  %10.5e \n",
           $y, $theta, $val, $amp, ($amp / $max_amp);

}

exit 0;

  
  
  






