Problem 2.1

Consider flipping 4 fair coins.  The Mathematica function Tuples[] will generate all permutations of the set {“H”, “T”}.

microstates = Tuples[{"H", "T"}, 4];

TableForm[microstates]

nstates = Length[microstates] (* Note this is the same as (2^4) *)

Count microstates with the ‘Select’ function.  For example, to find all states with 3 “H”, we simply Select[ ] all microstates that have 3 “H”s.  Then the Length[ ] function can be used to count the length of that list, i.e. 4 microstates.

Select[microstates, Count[#, "H"] == 3 &]

Length[Select[microstates, Count[#, "H"] == 3 &]]

macrostates = Table[{n, multiplicity = Length[Select[microstates, Count[#, "H"] == n &]], multiplicity/nstates}, {n, 0, 4}]

TableForm[macrostates, TableHeadings->{None, {"Number of Heads", "Multiplicity", "Probability"}}]

This is the same result we get from the combinatoric function (Binomial[n, m] in Mathematica).

TableForm[Table[{m, multiplicity = Binomial[4, m], multiplicity/(2^4)}, {m, 0, 4}],
TableHeadings->{None, {"Number of Heads", "Multiplicity", "Probability"}}]