cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - You can change your system assigned username to something more personal in your community settings. X

Programming

ptc-1996077
1-Newbie

Programming

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?
15 REPLIES 15

"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

"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

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.

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!

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

... you just said that there is no molecule leaving urn 1, OK, but whatever is exchanged is in term of a quantity, in fact in term of an entropy quantity, thus my interpretation and the law that governs:

N = Lot size originally in urn 1
n = sample size that found the door to urn 2
m = number that didn't pass the door

These would be the variables in the work sheet. You may have a more descriptive vocabulary, but the mathematical consequence over the laps time is to me the simple formula given. It composes itself recursively in the denominator. You can see that the process is identical to Markov where the sum of the deceased + the sick + the surviving is always equal to the original population as there is like you said no replacement. In the simple Markov, something is at constant rate ... here that something is under an other law of probability.

Rarely, you will find "scientific !!!" text meaning something. Scientists are reputed to be unskilled at putting their gray matter in image... portrait robot.

Show a typical graph of what you are talking about from a source that readers in the collab can materialize.

jmG

You fail to account for the probability that you draw a white or black ball from each urn. That is a significant probability, about .5 at steady state.

Also, be very cautious about using the logical connectives to perform multiple statements (better to just use multiple statements). The second operand may not be evaluated if its value is irrevelant to the value of the whole expression.
__________________
� � � � Tom Gutman

If you use larger numbers, you get a more consistent result, i.e., 60 and 4000. The results show that there is a systematic error in the algorithm.

I don't think that kernel is technically valid. Randomness means that you shouldn't be able to dictate what color ball is replaced in the second urn.

TTFN,
Eden
StuartBruff
23-Emerald III
(To:ptc-1996077)

On 1/28/2010 3:52:18 PM, donr671940 wrote:
== 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!

See attached.


Stuart

"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.

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.

>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

First to T. Gutman. Getting rid of the logical
"and " in the if statement worked. Simply calculating one random number (0,1), and comparing both pb1 and pw2 to this number to make a decision to increase or decrease nb1 and nw2 results in a steady state probability of 1/2 as expected.

With regard to sources for the transition matrix, and a Monte Carlo program written in Matlab - I believe - I can offer the following source I found on google search: the file "Markov Chains,Ehrenfest Model" See problem # 2 in this source. A second source - much more mathematical, which I have a difficult time following is the file "Ehrenfest Diffusion Model"

You seem missing a link,
once the entropic equilibrium of some molecule is done, that one entity is not replaced... and so on leading to the hypergeometric w/o any transition matrix, just a simple formula that I gave.

"In probability theory and statistics, the hypergeometric distribution is a discrete probability distribution that describes the number of successes in a sequence of n draws from a finite population without replacement. The hypergeometric distribution describes the probability that in a sample of n distinctive objects drawn from the URN exactly k objects are "POTENTIALLY ENTROPIC".

In general, if a random variable X follows the hypergeometric distribution with parameters N, m and n, then the probability of getting exactly k successes is given by ..." [see the formula in my sheet].

In all those papers:
where is the graph of the process evolving over the time ?
Obviously at equilibrium hypergeometric is the normal distribution. Maybe your are talking about a different process. Just plot the material you are referring to, plot over the time what you have done and concluded. But "your programme" must conclude by a simple formula. Have you ever seen a statistical distribution otherwise than represented by a formula ?

jmG

Announcements

Top Tags