Thursday, February 3, 2011

Compphys Dell Heart

(*
Stern-Gerlach Representation
Adam Hood, Andrew Cheong, Krishnan Chander
Dr. Dell
Computational Physics
Period 5
*)
(*Given two detectors where the particles have different \
orientations. However, the orientation two detectors can also differ \
thus changing the probability. Each detector has both options \
dependent on the spin of the incoming particle. The particle can \
continue to proceed or be blocked. *)
\[Sigma] = {{{0, 1}, {1, 0}}, {{0, -I}, {I, 0}}, {{1, 0}, {0, -1}}};
blochToCartesianSpin[\[Theta]_, \[Phi]_] := {Sin[\[Theta]] \
Cos[\[Phi]], Sin[\[Theta]] Sin[\[Phi]], Cos[\[Theta]]};
\[CapitalPsi][\[Theta]_, \[Phi]_] := {{Cos[\[Theta]/2]*
     Exp[-I*\[Phi]/2],
    Sin[\[Theta]/2]*
     Exp[I*\[Phi]/2]}, {-Sin[\[Theta]/2]*Exp[-I*\[Phi]/2] +
     Cos[\[Theta]/2]*Exp[I*\[Phi]/2]}};
basisVectors[\[Theta]_, \[Phi]_, up_,
   down_] := {Cos[\[Theta]/2]*Exp[-I*\[Phi]/2]*up +
    Sin[\[Theta]/2]*Exp[I*\[Phi]/2]*down, -Sin[\[Theta]/2]*
     Exp[-I*\[Phi]/2]*up + Cos[\[Theta]/2]*Exp[I*\[Phi]/2]*down};
U[p_, \[Theta]_, \[Phi]_] :=
  Cos[p]*{{1, 0}, {0, 1}} +
   I*Sin[p]*(blochToCartesianSpin[\[Theta], \[Phi]].\[Sigma]);
psiInnerProduct[\[CapitalPsi]1_, \[CapitalPsi]2_] := \
(ConjugateTranspose[\[CapitalPsi]1].\[CapitalPsi]2)[[1,
  1]]; x = 0; tot = 0.00000000001; \[Theta]thing = 0;
Manipulate[Graphics[{
   Inset[Button["1 Thing", (If[\[Theta] != \[Theta]thing, (x = 0;
        tot = 0.00000000001; \[Theta]thing = \[Theta];)];
      If[RandomReal[] < Cos[(\[Theta] - tilt)/2]^2, (x++; tot++),
       tot++])], {0.5, 3.5}],
   Inset[Button["100 Things", (If[\[Theta] != \[Theta]thing, (x = 0;
        tot = 0.00000000001; \[Theta]thing = \[Theta];)];
      For[i = 1, i <= 100, i++,
       If[RandomReal[] < Cos[(\[Theta] - tilt)/2]^2, (x++; tot++),
        tot++]])], {0.5, 2.5}],
   Inset[Button["10000 Things", (If[\[Theta] != \[Theta]thing, (x = 0;
        tot = 0.00000000001; \[Theta]thing = \[Theta];)];
      For[i = 1, i <= 10000, i++,
       If[RandomReal[] < Cos[(\[Theta] - tilt)/2]^2, (x++; tot++),
        tot++]])], {0.5, 1.5}], {Red,
    Rectangle[{0, 0}, {3, 1}]}, {Red,
    Rectangle[{6, Cos[tilt/2]}, {9, 1 - Cos[tilt/2]}]}, {Black,
    Thickness[Cos[\[Theta]/2]^2/100], Line[{{3, .75}, {6, .5}}]},
   Text[Cos[(\[Theta] - tilt)/2]^2 "(Theoretical)", {7.75, .75}],
   Text[x/tot "(Actual)", {7.75, .25}],
   Text[tot "Particles", {1.5, .5}]}], {\[Theta], 0, \[Pi]}, {tilt,
  0, \[Pi]}]