- Code: Select all
(* Michel Fodje's Minkwe simulation
translated from Python to Mathematica by John Reed
13 Nov 2013 *)
(* Set run time parameters, initialize arrays *)
trials=5000000;
aliceDeg=ConstantArray[0,trials];
bobDeg=ConstantArray[0,trials];
aliceDet=ConstantArray[0,trials];
bobDet=ConstantArray[0,trials];
nPP=ConstantArray[0,361];
nNN=ConstantArray[0,361];
nPN=ConstantArray[0,361];
nNP=ConstantArray[0,361];
nA=ConstantArray[0,361];
nB=ConstantArray[0,361];
(* Detector test function *)
test[angle_,e_,\[Lambda]_]:=Module[{c,out},
c=-Cos[1(angle-e)];
If[\[Lambda]>=Abs[c],out=0,out=Sign[c]];
out]
(* Generate particle data *)
Do[
eVector=RandomReal[{0,2 \[Pi]}];
\[Lambda]=1/2 Sin[RandomReal[{0,\[Pi](0.5)}]]^2;
eLeft=RandomReal[{0,2 \[Pi]}];
eRight=eLeft+\[Pi];
aliceAngle=RandomReal[{0,2 \[Pi]}];
aliceDeg[[i]]=aliceAngle/Degree;
bobAngle=RandomReal[{0,2 \[Pi]}];
bobDeg[[i]]=bobAngle/Degree;
aliceDet[[i]]=test[aliceAngle,eLeft,\[Lambda]];
bobDet[[i]]=test[bobAngle,eRight,\[Lambda]],
{i,trials}]
(* statistical analysis of particle data *)
Do[
\[Theta]=Ceiling[(aliceDeg[[i]]-bobDeg[[i]])]-1;
aliceD=aliceDet[[i]];bobD=bobDet[[i]];
If[aliceD==1,nA[[\[Theta]]]++];
If[bobD==1,nB[[\[Theta]]]++];
If[aliceD==1&&bobD==1,nPP[[\[Theta]]]++];
If[aliceD==1&&bobD==-1,nPN[[\[Theta]]]++];
If[aliceD==-1&&bobD==1,nNP[[\[Theta]]]++];
If[aliceD==-1&&bobD==-1,nNN[[\[Theta]]]++],
{i,trials}]
(* Calculate mean values and plot *)
pPP=0; pPN=0; pNP=0;pNN=0;
mean=ConstantArray[0,361];
Do[
sum=nPP[[i]]+nPN[[i]]+nNP[[i]]+nNN[[i]];
If[sum==0,Goto[jump],
{pPP=nPP[[i]]/sum;
pNP=nNP[[i]]/sum;
pPN=nPN[[i]]/sum;
pNN=nNN[[i]]/sum;
mean[[i]]=pPP+pNN-pPN-pNP}];
Label[jump],
{i,361}]
simulation=ListPlot[mean]
cos=Plot[-Cos[x Degree],{x,0,360},PlotStyle->{Red,Thick}];
(* Compare mean values with Cosine *)
Show[simulation,cos]
Prove or not prove that if the number of trials goes to infinity and the degree increment goes to zero that we get the result of -a.b where a is the vector represented by aliceAngle above and b is represented by bobAngle above. Basically that we get a pure -cos curve.