(*********************************************************************************************
          Name: - Simulation of Coin Toss.    
     Author: - Kanwaljeet Singh Channey.
  Comments: - I have supressed the output of every command except that of graphs. If one wants to know the output a particular     command just remove the semicolumn at the end of that command. For details of each command see the pptx file.  
*********************************************************************************************)

coin:=RandomChoice[{0,1},5]
repetition[n_]:=Table[heads,{i,1,n}]
Sort[Tally[repetition[1000]]];
array=Sort[Tally[repetition[1000]]];
freqdis=ListPlot[array,Filling->Axis,Frame->True,
FrameLabel->{"Number of Heads⟶","Counts⟶"},PlotStyle->Directive[PointSize[Large],
Orange],LabelStyle->Directive[Medium,Orange]]
prob=MapAt[(#/1000)&,array,Table[{i,2},{i,1,6}]];
expprob=ListPlot[prob,Filling->Axis,PlotStyle->Directive[PointSize[Large],
Orange],Frame->True,FrameLabel->{"Number of Heads⟶","Probability⟶"},
LabelStyle->Directive[Medium,Orange]]
th1=ListPlot[Table[{x,PDF[BinomialDistribution[5,0.5],x]},{x,0,5,1}],InterpolationOrder->2,Joined->True,AxesOrigin->{0,0},PlotStyle->Directive[Red,Thick]];
th2=ListPlot[Table[{x,PDF[BinomialDistribution[5,0.4],x]},{x,0,5,1}],InterpolationOrder->2,Joined->True,AxesOrigin->{0,0},PlotStyle->Directive[Green]];
th3=ListPlot[Table[{x,PDF[BinomialDistribution[5,0.6],x]},{x,0,5,1}],InterpolationOrder->2,Joined->True,AxesOrigin->{0,0},PlotStyle->Directive[Purple]];
Show[th3,th2,th1,Frame->True,FrameLabel->{"Number of Heads⟶","Probability⟶"},LabelStyle->Directive[Orange,Medium]]
Show[th3,th2,th1,expprob,Frame->True,FrameLabel->{"Number of Heads⟶","Probability⟶"},LabelStyle->Directive[Orange,Medium]]
thx[m_]:=Table[{x,PDF[BinomialDistribution[5,m],x]},{x,0,5,1}];
subt[m_]:=thx[m]-prob
neum[m_]:=Table[subt[m][[i,2]],{i,1,6}];
denm[m_]:=Table[thx[m][[i,2]],{i,1,6}];
chi[m_]:=(((neum[m]))^2)/denm[m];
chisq[m_]:=Total[chi[m]];
tabchisq=Table[{i,chisq[i]},{i,0.2,0.8,0.02}];
ListPlot[tabchisq,Joined->True,PlotRange->{0,10},InterpolationOrder->2,Frame->True,FrameLabel->{"Probabiity of Occurence of Head⟶","Error⟶"},LabelStyle->Directive[Orange,Medium],PlotStyle->Directive[Thick,Orange]]