(*     Module #24:  Diffraction from Slits     *)

(*   Set wavelength of light and other paramters   *)
lambda=6500.;d=10*lambda;
c=3.*(10^8);f=c/lambda;T=1/f;omega=N[2*Pi*f]; Eo=1.;

(*    Calculate Diffraction pattern for two slits     *)
Do[Theta=N[n*Pi/2];phi=N[2*Pi*d/lambda]*Sin[Theta];
   Int[n]=(1/10)*Sum[(Eo*Sin[omega*t]+Eo*Sin[omega*t+phi])^2,
              {t,0,T-(T/10),T/10}],
    {n,0,0.5,0.005}]

(*   Graph two slit diffraction pattern     *)

data=Table[{N[n*Pi/2],Int[n]},{n,0,0.5,0.005}];
ListPlot[data]

(*   Two slit diffraction pattern with points jointed  *)

ListPlot[data, Joined->True,
                AxesLabel->{"Theta","Intensity"}, PlotRange-> All]

(*     Three slit diffraction pattern calculation    *)

lambda=6500.;d=10*lambda;
c=3.*(10^8);f=c/lambda;T=1/f;omega=N[2*Pi*f]; Eo=1.;
Do[Theta=N[n*Pi/2];phi=N[2*Pi*d/lambda]*Sin[Theta];
   Int[n]=(1/10)*Sum[(Eo*Sin[omega*t]+
                      Eo*Sin[omega*t+phi]+
                      Eo*Sin[omega*t+2*phi])^2,
                               {t,0,T-(T/10),T/10}],
   {n,0,0.25,0.0025}]

(*   Make graph of three slit pattern    *)

data=Table[{N[n*Pi/2],Int[n]},{n,0,0.25,0.0025}];
ListPlot[data,Joined->True,
                AxesLabel->{"Theta","Intensity"}, PlotRange-> All]

(*    Calculation of four slit diffraction pattern  *)

lambda=6500.;d=10*lambda;
c=3.*(10^8);f=c/lambda;T=1/f;omega=N[2*Pi*f]; Eo=1.;
Do[Theta=N[n*Pi/2];phi=N[2*Pi*d/lambda]*Sin[Theta];
   Int[n]=(1/10)*Sum[(Eo*Sum[Sin[(omega*t+k*phi)],
                            {k,0,3}])^2,
                 {t,0,T-(T/10),T/10}],
{n,0,0.1,0.001}]

(*  Make graph of four slit diffraction pattern  *)

data=Table[{N[n*Pi/2],Int[n]},{n,0,0.1,0.001}];
ListPlot[data,Joined->True,
                AxesLabel->{"Theta","Intensity"}, PlotRange-> All]

(*   Calculate ten slit diffraction pattern   *)

lambda=6500.;d=10*lambda;
c=3.*(10^8);f=c/lambda;T=1/f;omega=N[2*Pi*f]; Eo=1.;
Do[Theta=N[n*Pi/2];phi=N[2*Pi*d/lambda]*Sin[Theta];
   Int[n]=(1/10)*Sum[(Eo*Sum[Sin[(omega*t+k*phi)],
                            {k,0,9}])^2,
                 {t,0,T-(T/10),T/10}],
{n,0,0.1,0.0005}]

(*   Make graph of ten slit diffraction pattern   *)

data=Table[{N[n*Pi/2],Int[n]},{n,0,0.1,0.0005}];
ListPlot[data,PlotRange->All,
   Joined->True,AxesLabel->{"Theta","Intensity"}, PlotRange-> All]