Skip to main content
1-Visitor
January 27, 2010
Question

Programming

  • January 27, 2010
  • 5 replies
  • 5862 views
This is a program to simulate the diffusion of "molecules" in a closed container using the Ehrenfest Duffusion model; i.e. drawing balls from urns with replacememt.

I have, probably, some simple error in syntac that is giving me a message " this index is not appropriate for this array". What is the problem?

5 replies

1-Visitor
January 27, 2010
"drawing balls from urns with replacement."
_____________________________

Is the default model for plant quality control.
The function is the "Hypergeometric distribution".
But I don't understand "replacement".
If so much is gone, so much is not there anymore ?

jmG
1-Visitor
January 27, 2010
1-Visitor
January 27, 2010
"The Ehrenfest model is considered as a good example of a Markov chain."
__________________________

Several work sheets in the collab,
Also, visit the PTC repository.

jmG
1-Visitor
January 28, 2010
"Probability of drawing a black ball from urn 1 over time"
_____________________________

What it all does and only does:
shift the normal PDF [rnd]
Try rgamma(,,) and adapt the programme.

Thanks Stuart, better wait the collab sources the abstract.
The abstract is incorrect, therefore the underlying law.

jmG

PS: Seed is built-in and does not result in Mathcad 11.2a.
1-Visitor
January 30, 2010
Thanks, I will try separating the if/other statemants instead of using the logical "and" to connect them. If I determine the sample mean and variance of b1 = rnd(1), it is pretty close to 1/2 amd 1/12 the theoretical values. Does not seem biased.

There is an analytical solution to the problem - see attached, which indeed predicts a steady state value of 1/2 for the fraction of white balls in urn 1 - and thus 1/2 for the fraction of black balls in urn 2. This should be the state of lowest entropy.

The idea of the first program was to simulate by Monte Carlo method.
1-Visitor
January 30, 2010
>There is an analytical solution to the problem<<br>
Accepted,
but show from source, not from a work sheet conceptually incorrect whereas at least two collabs have pointed. Your concept is incorrect in the sense that you are assuming only two colors but the physics says otherwise. i.e: not a simple random � ..�, rather a "combined probability", thus leading to the hypergeometric, therefore a must rgamma in the generation. The other point is why a program invented in-situ rather than the already existing formula, that I gave and that you can source.

For a larger audience (as you wish),
"Save as" version as low as your version allows.
Your ws is restricted to your version or higher.

A programme is not a substitute to mathematically developing the model.

jmG
12-Amethyst
January 28, 2010
On 1/27/2010 7:24:48 PM, donr671940 wrote:

>I have, probably, some simple
>error in syntac that is giving
>me a message " this index is
>not appropriate for this
>array". What is the problem?

You don't assign a value for pb1 greather than 0, so in the for loop there are not value for k=1. You must to initialize the entire vectors pb1 and pw2. I can't check if for the logic of the program you can take pb1[k & pw2[k instead pb1[0 & pw2[0, but this 'solve' the problem, to the next failure.

Next problem that you have it is assigning pb1[k+1 with b1[k+1: b1 is defined only at the k-th element, can't use b1[k+1 or b2[k+1. Actually this is the same situation.

In other words: you want to write a recursive algorithm but have problems in the initialization of the recursion values.

Regards. Alvaro.
1-Visitor
January 28, 2010
I did find an error in the program and got it to run. To answer the question regarding "drawing from urns with replacement" - consider that each urn represents a partion in a chamber. Draw one ball from urn 1, put it in urn 2. Draw one ball from urn 2, put it in urn1. The total number of balls in each urn stays at n0 (n at time zero). The program model simulates equimolar counter diffusion.

However, though the new program runs, it still does not seem right. At steady state, I think one would expect each urn - side of the partion - to be half black and half white. The program does not give that it seems!
1-Visitor
January 28, 2010
Because of the specific name, I visited quick the web. It looks like none gave any form of executable maths. Conclusion: a view of the mind. Your equimolar balance is defendable, but if the molecule has moved from urn 1, it is no longer in it ! I have seen no EHENFEST diagram. It looks possible to modify the Markov model to include your illusion. "Save as" version 11 and a much larger audience will look at it. You can save as low as your version allows. For sure, the shape of the "entropy" diagram vs time will be an hypergeometric distribution, that's what I concluded from some savant diagram found in the web, but could not be modeled [I mean no mathematical model offered].

Maybe revisit: combin(n, k)
Returns the number of subsets each of size k that can be formed from n objects, where n is greater than or equal to k. Each subset is known as a combination. n and k are integers greater than or equal to zero.

jmG