In[]:= In[]:= In[3]:= In[4]:= In[5]:= Out[5]= r : Random ri : Random Integer rdice : Random Integer,, 6 disp : Export "t.ps",, "EPS" & list Table rdice, 0 5,, 4, 6,, 3,, 3, 4,, 6, 4, 6,,, 6, 6,, 3, In[6]:= In[7]:= Statistics`DataManipulation` General::obspkg : Statistics`DataManipulation` is now obsolete. The legacy version being loaded may conflict with current Mathematica functionality. See the Compatibility Guide for updating information. In[8]:= In[9]:= Out[9]= fr : Frequencies & fr list 5,, 3,, 3, 3, 3, 4,, 5, 5, 6 In[0]:=? BarChart BarChart y, y, makes a bar chart with bar lengths y, y,. BarChart, w i y i,,, w j y j,, makes a bar chart with bar features defined by the symbolic wrappers w k. BarChart data, data, makes a bar chart from multiple datasets data i. In[]:= Graphics`Graphics` General::obspkg : Graphics`Graphics` is now obsolete. The legacy version being loaded may conflict with current Mathematica functionality. See the Compatibility Guide for updating information. Histogram::shdw : Symbol Histogram appears in multiple contexts Graphics`Graphics`, System` ; definitions in context Graphics`Graphics` may shadow or be shadowed by other definitions. BarChart::shdw : Symbol BarChart appears in multiple contexts Graphics`Graphics`, System` ; definitions in context Graphics`Graphics` may shadow or be shadowed by other definitions. BarSpacing::shdw : Symbol BarSpacing appears in multiple contexts Graphics`Graphics`, System` ; definitions in context Graphics`Graphics` may shadow or be shadowed by other definitions. PieChart::shdw : Symbol PieChart appears in multiple contexts Graphics`Graphics`, System` ; definitions in context Graphics`Graphics` may shadow or be shadowed by other definitions.
new688_probab.nb In[]:= BarChart fr list histogram 5 4 3 Out[]= 0 In[3]:= Out[3]= In[4]:= In[5]:= Out[5]= In[6]:= Mean list standard 67 0 mymean list_ : Plus list Length list mymean list 67 0 StandardDeviation list N Out[6]=.95408 In[7]:= Out[7]= In[8]:= Variance list 45 380 Sqrt N Out[8]=.95408 In[9]:= In[0]:= Out[0]= In[]:= Out[]= In[]:= In[3]:= Out[3]= Sample Space Timing list Table rdice, 00 000 ; 0.047, Null Union list sample space all distinct possibilities,, 3, 4, 5, 6,,...6 "simple events", any combinations "events" list, 4, 6, 8 ; list Table i, i, 5,, 3, 4, 5
new688_probab.nb 3 In[4]:= Out[4]= In[5]:= Out[5]= In[6]:= Out[6]= In[7]:= Out[7]= In[8]:= Out[8]= In[9]:= Out[9]= In[30]:= Out[30]= In[3]:= Out[3]= list list,, 3, 4, 5, 6, 8 or Union list, list,, 3, 4, 5, 6, 8 Join list, list, 4, 6, 8,,, 3, 4, 5 Intersection list, list, 4 or list list, 4 allist Table i, i, 0,, 3, 4, 5, 6, 7, 8, 9, 0 Complement allist, list, 3, 5, 7, 9, 0 Complement allist, list, list 7, 9, 0 In[3]:= PROBABILTY sec. 4.3 in KR. In[33]:= In[34]:= In[35]:= consider rolling of dice; "simple events" are,3,.., roll : rdice rdice roll a single "experiment Out[35]= 9 In[36]:= In[37]:= Out[37]= In[38]:= Out[38]= now try MANY experiments Timing list Table roll, 000 000 ;.96, Null Timing flist fr list 0.5, 8 078,, 55 4, 3, 83 734, 4, 468, 5, 38 36, 6, 66 56, 7, 38 656, 8, 80, 9, 83 055, 0, 55 303,, 7 8,
4 new688_probab.nb In[39]:= BarChart flist 50 000 00 000 Out[39]= 50 000 0 In[40]:= ll Length list N Out[40]=. 0 6 In[4]:= Out[4]= In[4]:= fflist Table flist i, ll, flist i, N, i, 0.08078,., 0.0554, 3., 0.083734, 4., 0.468, 5., 0.3836, 6., 0.6656, 7., 0.38656, 8., 0.8, 9., 0.083055, 0., 0.055303,., 0.078,. BarChart fflist, BarStyle Blue 0.5 0.0 Out[4]= 0.05 0.00 In[43]:= In[44]:= Out[44]= In[45]:= Out[45]= note "lucky seven" fflist N 0.08078,., 0.0554, 3., 0.083734, 4., 0.468, 5., 0.3836, 6., 0.6656, 7., 0.38656, 8., 0.8, 9., 0.083055, 0., 0.055303,., 0.078,. exact Table i 36., i, i, 6 exact probabilites 0.077778,, 0.0555556, 3, 0.0833333, 4, 0., 5, 0.38889, 6, 0.66667, 7
new688_probab.nb 5 In[46]:= Out[46]= In[47]:= Table fflist i, exact i,, i, 6 0.00808, 0.00404, 0.004808, 0.003, 0.005408, 0.000844 Note: error is small, although we had a million tries statistical experiments converge slowly to exact probabilities In[48]:= In[49]:= In[50]:= Out[50]= In[5]:= Out[5]= In[5]:= Permutations Permutations a, b, c a, b, c, a, c, b, b, a, c, b, c, a, c, a, b, c, b, a Binomial n, m Binomial n, m n m n m FullSimplify Out[5]= 0 In[53]:= In[54]:= Factorial n Gamma n FullSimplify Out[54]= 0 In[55]:= Series n, n, Infinity, Stirling formula Out[55]= Log n n O n Π n 6 Π n O 3 n In[56]:= stir n_ n n n Π n Out[56]= n n n n Π In[57]:= stir 00. Out[57]= 9.3485 0 57 In[58]:= 00 N Out[58]= 9.336 0 57 In[59]:= In[60]:= In[6]:= cummulativeprobability function cumprob n_ : Sum fflist i,, i, n N 36 cumprob Out[6]=.008
6 new688_probab.nb In[6]:= Plot cumprob n, n,,, PlotStyle Blue, AxesLabel "n", "F" 0.8 0.6 Out[6]= 0.4 0. In[63]:= In[64]:= In[65]:= mean list_ : Sum list i, list i,, i, Length list mean fflist N again, "lucky 7" Out[65]= 6.99736 In[66]:= In[67]:= var list_ : Block Μ mean list, Sum list i, Μ ^ list i,, i, Length list var fflist N Out[67]= 5.83985 In[68]:= fcoin, 0,, Out[68]=, 0,, In[69]:= Out[69]= In[70]:= Out[70]= mean fcoin var fcoin 4 In[7]:= In[7]:= In[73]:= approximation by a Gauss distribution gauss list_ : Block Μ mean list, Σ Sqrt var list, Σ Sqrt Pi Exp x Μ Σ ^
new688_probab.nb 7 In[74]:= Out[74]= gauss fflist N 0.085687 6.99736 x 0.65086 In[75]:= In[76]:= In[77]:= In[78]:= In[79]:= mybarplot list_ : Graphics Red, Table Line list i,, 0, list i,, list i,, i, Length list Show mybarplot fflist, AspectRatio Out[79]= In[80]:= Show Plot gauss fflist, x, 0,, mybarplot fflist 0.5 0.0 Out[80]= 0.05 In[8]:= binlist n_, p_ : Table Binomial n, m p ^m p ^ n m, m, m, 0, n
8 new688_probab.nb In[8]:= binlist 3, Out[8]= 8, 0, 3 8,, 3 8,, 8, 3 In[83]:= In[84]:= longbin binlist 0, ; mean longbin Out[84]= 0 In[85]:= Show Plot gauss longbin, x, 0, 0, mybarplot longbin 0.5 Out[85]= 0.0 0.05 In[86]:= In[87]:= biasbin binlist 0,.3 ; Show Plot gauss biasbin, x, 0, 0, mybarplot biasbin, PlotRange 0,. 0.0 0.5 Out[87]= 0.0 0.05 In[88]:= biasbin binlist 3,.6 ;
new688_probab.nb 9 In[89]:= Show Plot gauss biasbin, x,, 5, mybarplot biasbin, PlotRange 0,.6 0.5 0.4 Out[89]= 0.3 0. 0. In[90]:= In[9]:= Out[9]= In[9]:= Out[9]= In[93]:= Out[93]= In[94]:= Out[94]= In[95]:= Central limittheorem: we already verified that the discrete "binary distribution" 0, for a random variable X which is NON Gaussian will lead to a Gaussian for a random variable Z, which is a sum of of n elements Z X... X for a large n. We will now try a different, continuous uniformdistribution but with the same mean and average as the "binary one" f x_ L L Integrate f x, x, a, a i.e. a L for the same average and normalization a L Integrate f x x, x, L, L mean Integrate f x x ^, x, L, L L Solve 4, L this gives the spread with varianve of 4 Out[95]= L 3, L 3 In[96]:= a Sqrt 3 N; b Sqrt 3 N Out[96]=.36603 In[97]:= rr : Random Real, a, b
0 new688_probab.nb In[98]:= Table rr, 0 Out[98]= 0.86909, 0.90073, 0.83669, 0.6334, 0.66985, 0.647097, 0.3964, 0.96767, 0.396, 0.763 In[99]:= Clear sumn ; sumn n_ : Sum rr, n In[00]:= In[0]:= In[0]:= In[03]:= Out[03]= In[04]:= Do aa i 0, i, 00 ; run : Block s Floor sumn 00, aa s aa s Timing Do run, 0 000 ;.8, Null listaa Table aa i, i, 00 Out[04]= 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3,, 5, 4, 4, 39, 67, 95, 38, 00, 39, 340, 480, 53, 593, 679, 749, 796, 807, 795, 70, 59, 5, 4, 393, 55, 86, 30, 97, 5, 3, 8, 3, 5, 0,, 0, 0, 0,, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 In[05]:= In[06]:= In[07]:= Out[07]= In[08]:= normal x_ : Sqrt 00 4 Sqrt Pi Exp x 50 Sqrt 00 4 ^ normal x 50 99 x 5 Π Integrate normal x, x, Infinity, Infinity Out[08]= In[09]:= In[0]:= plolist : ListPlot listaa 0 000, PlotStyle Blue, PointSize.05 plonorm : Plot normal x, x, 0, 00, PlotStyle Red
new688_probab.nb In[]:= Show plolist, plonorm, PlotRange 0, 80, 0,., AxesOrigin 0, 0 0.0 0.08 0.06 Out[]= 0.04 0.0 0.00 In[]:= In[3]:= more on normal distribution In[4]:= cumul z_ Sqrt Pi Integrate Exp u^, u, Infinity, z Out[4]= In[5]:= Erf z cumul Infinity Out[5]= In[6]:= Plot Sqrt Pi Exp z ^, cumul z, z, 3, 3, PlotStyle Red, Blue 0.8 0.6 Out[6]= 0.4 0. 3 In[7]:= Out[7]= FindRoot cumul z, z, Chop z 0
new688_probab.nb In[8]:= Out[8]= FindRoot cumul z 0.9, z, z.855 In[9]:= In[0]:= In[]:= Gauss from binomial cgaus m_, n_ : stir n stir m stir n m ^ n cgaus n x, n Out[]= Π n x n n x n x n n n n x n n n x n n x n x n x n x In[]:= Sqrt n. x y Sqrt n Out[]= Π n n n y n n y n n y n n 3 n n n y n n y n n y n n n y n n n y n n n y In[3]:= FullSimplify, Assumptions n 0 && y 0 Out[3]= n n n n y n n n Π Π y n n y n y In[4]:= Limit, n Infinity Out[4]= In[5]:= y Π this is the gauss distribution In[6]:= Gammaand chi^ distributions In[7]:= Out[7]= In[8]:= fgam x_, t_ lamexp lam x lam x ^ t Gamma t lam x lam lam x t Gamma t Integrate fgam x, t, x, 0, Infinity, Assumptions t 0 && lam 0 Out[8]= In[9]:= Out[9]= Integrate x fgam x, t, x, 0, Infinity, Assumptions t 0 && lam 0 average t lam
new688_probab.nb 3 In[30]:= Out[30]= In[3]:= Integrate x ^ fgam x, t, x, 0, Infinity, Assumptions t 0 && lam 0 variance t lam chi x_, n_ fgam x, n. lam Out[3]= In[3]:= n x x n Gamma n Plot chi x, 5, chi x, 0, x, 0, 0, PlotStyle Red, Blue, PlotRange 0,. 0.0 0.5 Out[3]= 0.0 0.05