Home > Mathematica, Mathematics > Think about the last state

Think about the last state

Mathematica Stackexchange remains a wonderful resource for answering questions and learning from experts.

I posed my theatre problem issues and almost immediately (well, given at the moment I have poor internet connectivity on a cold mountain top it seemed that way to me) got the most wonderful solutions (I emphasize the plural) from Mr.Wizard.

Instantaneously, I felt the shame of my nested conditionals with their amplifying recursion number; my lack of patience with the Law of Large Numbers(perhaps to paraphrase Jaws, “better get a bigger sample”), However, looking at the solutions I learned (and hope to learn more as I contemplate them).

I was particularly enthused by the following:

sim4 =
Compile[{{n, _Integer}},
Module[{seats, trys},
seats = ConstantArray[0, n];
trys = RandomSample @ Partition[Range@n, 2, 1];
Do[If[seats[[i]] === {0, 0}, seats[[i]] = {1, 1}], {i, trys}];
Tr @ seats

This was neat; and does all the right things as the following  graphics from my playing with it attest. My summary of  the code by Mr. Wizard:

  1. . Make a constant ary of zeroes to represent empty seats
  2. Generate a random partition of Range[n] of size two with offset 1. This generates a possible final theatre set of side by side seats and the sample elements are just the part indices for the seats
  3. Fill empty side by side seats from your random sample
  4. Use Magthematica’s generalised trace to sum to 1s for the filled seats
  5. The answer is just the complement normalized to n

The following is  histogram of 1000 runs for 10000 seat theatre:


The mean and standard deviation respectively: 0.135379, 0.00275046. (e^{-2}\approx 0.135335)

The following are ten plots of simulations of increasing theatre size:

It is gratifying when things make sense and wonderful when you learn in the process…peace to all this time of year and solace to those experiencing so much suffering from natural disasters and unexplainable human actions…

Categories: Mathematica, Mathematics
  1. December 23, 2012 at 7:00 pm

    Note: E(SIM4(10000))=e^{-2}+2\times 10^{-4}

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: