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

Rnd in Mathcad

Emerald II

Rnd in Mathcad

I think the rnd function (a procedure) in Mathcad is not so good

What can you say about it?

See please this animation http://communities.ptc.com/videos/3806

and this two pictures:

Coin

1-%D0%9E%D1%80%D0%B5%D0%BB%D0%98%D0%BB%D0%B8%D0%A0%D0%B5%D1%88%D0%BA%D0%B0.png

Dice

2-Dice.png

24 REPLIES 24

Re: Rnd in Mathcad

Valery Ochkov wrote:

I think the rnd function (a procedure) in Mathcad is not so good

Why do you think so?

What did you expect for the coin toss? Precisely 50%???

The probabilty that with 10^7 tosses you get exactly 50% heads is just about 0.025% so I wouldn't trust the random number generator if it would yield exactly 50% most of the times.

On the other hand - the probability that the percentage of heads up is inbetween 49.95% and 50.05% for 10^7 tosses is as high as 99.84% and that fits perfectly to the result you achieved.

EDIT: The coin toss routine could be written much more compact

08.12.png

Re: Rnd in Mathcad

See please the animation.

I think the point must go to the line at n-> infinity.

Re: Rnd in Mathcad

Werner Exinger wrote:

Valery Ochkov wrote:

I think the rnd function (a procedure) in Mathcad is not so good

Why do you think so?

EDIT: The coin toss routine could be written much more compact

08.12.png

Sorry more compact but not so simple for an understanding

And what about 2 dices?

Re: Rnd in Mathcad

Valery Ochkov wrote:

See please the animation.

I think the point must go to the line at n-> infinity.

For n->infinity, yes. For n=10^5 not necessarily.

But its disturbing the the calculated value is always too high.

But then, we don't see how the random numbers are generated and how it is decided if a point is inside.

BTW, I have programmed that Monte Carlo pi finding quite a number of times using different programming labguages and different compilers and it was somewhat disappointing every time. Its a very slowly converging method.

Re: Rnd in Mathcad

Sorry more compact but not so simple for an understanding

Thats true, but your point was to prove that the randon number generator in Mathcad does not work to your expectation and not to provide a sample program to be used in a basic programming course, right?

And what about 2 dices?

Interested in another harder to understand routine?

Of course we can compact that too:

08.12_2.png

The drawback of both routines is that a full vector is generated first hand and there is a (memory) limitation for creating vectors which prevents using much larger numbers for n than those given in the screenshots.

Re: Rnd in Mathcad

Thanks, Werner!

I would like to translate into English my article "Tripartite duel in Monte Carlo" from the Magazine "IT in school".

The rnd routine is the main point of the article!

See pictures here http://twt.mpei.ac.ru/ochkov/Mathcad-15/duel-pdf.pdf

The begin of the article

There is one joke. Student wakes up every morning and thinks of throwing a coin, "the winning eagle - will sleep more on the right side, rolled tails - lie on your left side, on the edge of the coin will fall - go to college, and hangs in the air - 'll coursework."
Joking aside, we often have to toss a coin - real or virtual , to randomly select one of two equally likely possibility . Football referee, for example, before the match is flipping a coin to determine which team to give certain gates. Chess player before the game in one hand grips the white pawn and the other - black and offers an opponent choose "one of two equally likely possibility" - to determine who will play the white pieces , and who - black . Shuffling a deck of cards or dominoes stirring, again we give ourselves to chance. And from this , the will of the case may depend very much... Even the person's life, if you remember the title of this article. And why not a simple ( two-sided ), and unusual ( tripartite ) duel, and even in Monte Carlo!? The fact that the problem of the tripartite duel is described in many books , such as [1, 2 ], which provides one of the particular solutions of this problem , obtained by logical reasoning . We consider a more complete solution to this problem on a computer Monte Carlo ( Monte Carlo method ) : simulate a single duel , spend quite a lot of her time and calculate the number of wins in these duels each participant [3]. If these numbers are divided by the total number of duels, and the result will be the desired probability victories.
But we begin with simple tasks bezkompyuternoe decision known.
Let us remember our lackadaisical student from a joke, using a computer to flip a coin many times and count how many times the winning eagle, and how much - tails. Fig. 1 shows the corresponding computer program - OrelIliReshka function with argument n (number of tosses of a coin), which returns the probability of coming up heads or tails .

Re: Rnd in Mathcad

I cannot duplicate the problem/error your animation shows but without seeing the code we cannot tell if there is an error in the sheet or what else could cause that effect.

At least I reproduced the Monte Carlo calculation of Pi and see a slow but good convergence.

See below some screenshots from different runs in a log scale.

An animation using a linear scale is here: http://communities.ptc.com/videos/4527

MontePi.png

Re: Rnd in Mathcad

Accuracy in Monte-Carlo simulations tends to improve with the square root of the number of trials (see http://www.cs.nyu.edu/courses/fall06/G22.2112-001/MonteCarlo.pdf for example), so to improve by 1 extra decimal place (a factor of ten) one needs 100 times as many trials. Typically, the Monte-Carlo simulation of pi gets around one decimal place accuracy after 1000 trials. This means that one might expect, at best, 2 decimal places of accuracy after 10^5 trials and three decimal places of accuracy after 10^7 trials.

Alan

Re: Rnd in Mathcad

I am not getting your point..It is really difficult to understand..What are the simplest form of it? Any one aware about teh functions of two factor authentication in Google apps ?