Programming
In[79]:=
spread[lis_]:=Drop[FoldList[Plus,0,lis],1] (* spread[{a,b,c}] *)
In[80]:=
pvector[s_,r_]:=With[{d=Switch[r,
18,0.40,
30,0.80,
50,0.80,
60,1.22,
70,1.22,
90,1.22
]},
pvector[d/r,s,x10arrow/2/r]]
In[81]:=
(* s is the mrad of the shooter's ability, and r is meters to the target *)
getweights[s_,r_]:=spread[pvector[s,r]]
(* this function returns a vector of the cumulative probabilities starting with the X ring *)
In this function we provide the cumulative probability vector (determined above) and "roll" a shot that's consistent with the shooter's skill. The way we simulate (say) an end of three arrows is to "roll" three times!
In[86]:=
(* provide a weight vector and this function "rolls" one arrow *)
roll[wv_]:=With[{r=Random[]},
Which[(*r<=wv[[1]], 11,--only use this for testing X's*)
(* this is the fastest order of evaluation *)
r<=wv[[2]], 10,
r<=wv[[3]], 9,
r<=wv[[4]], 8,
r<=wv[[5]], 7,
r<=wv[[6]], 6,
r<=wv[[7]], 5,
r<=wv[[8]], 4,
r<=wv[[9]], 3,
r<=wv[[10]], 2,
r<=wv[[11]], 1,
True, 0]]
In[88]:=
(* this rolls n arrows and returns their sum *)
roll[wv_,n_]:=Sum[roll[wv],{n}]
In[90]:=
(* this "rolls" a male FITA, at 30m, 50m, 70m, and 90m *)
rollfita[male,s_]:=roll[getweights[s,30],36]+
roll[getweights[s,50],36]+
roll[getweights[s,70],36]+
roll[getweights[s,90],36]
In[92]:=
rollfita[female,s_]:=roll[getweights[s,30],36]+
roll[getweights[s,50],36]+
roll[getweights[s,60],36]+
roll[getweights[s,70],36]
In[93]:=
<<Graphics`Graphics`
In[94]:=
SetAttributes[hello,Listable]
In[104]:=
hello[sex_,score_]:=With[{s=findmrad[sex,score]/1000},
Module[{histo=Array[0&,1440]},
Do[With[{e=rollfita[sex,s]},histo[[e]]++],{20000}];
With[{m=mean[histo],
sigma=Sqrt[sigma2[histo]]},
Print[sex, " ", score, " shooter, ", N[1000 s,2], "mrad"];
Print["simulated tournaments: ", Total[histo]];
Print[" mean is ", N[m,4], " points, sigma is ", N[sigma,3], " points"];
Print[" 68% of the time the score is within ", N[m - sigma,4], " and ", N[m + sigma,4]];
Print[" 95% of the time the score is within ", N[m - 2 sigma,4], " and ", N[m + 2 sigma,4]];
With[{p1=ListPlot[converttopoints[histo],
DisplayFunction->Identity],
p2=Plot[Exp[-((sc-m)/sigma)^2/2]/sigma/Sqrt[2 Pi],
{sc,m-3 sigma, m+3 sigma},
DisplayFunction->Identity]
},
Show[p1,p2,DisplayFunction->$DisplayFunction]
]]]]
In[96]:=
mean[histo_]:= Sum[i histo[[i]], {i, Length[histo]}]/Total[histo]
In[97]:=
sigma2[histo_]:=With[{m=mean[histo]},
Sum[histo[[i]] (i - m)^2,{i, Length[histo]}] / Total[histo]]
In[98]:=
converttopoints[histo_]:=Module[{res={},
count=Total[histo]},
Do[If[histo[[i]]>0,
res=Prepend[res,
{i,histo[[i]]/count}
]
],
{i, Length[histo]}];
res]
Created by Mathematica (June 28, 2005)