Message Boards Message Boards

0
|
5942 Views
|
3 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Can't get this old mathematica code to run...

Posted 10 years ago

Hello! I'm trying to get the following program to run. It seems like it was written with an older version of Mathematica. Any help is appreciated.

Failed = 0;

Hit = 0;

SetSharedVariable[Failed, Hit]

ParallelTable[x = Random[];

  ProbabilityStillGoing = (1 - ?/200)^j;


  If[ProbabilityStillGoing > x, Failed++, Hit++];

  If[Failed == Hit, Print[j]];

  , {j, 0, NUMBER}];    

Thanks in advance for your help.

POSTED BY: Fat Villager
3 Replies

So you want something like this --not exactly, I suspect, since I am not understanding the internals of the code, but this at least creates a list and computes a Mean:

Failed = 0;

Hit = 0;

NUMBER = 1000;

SetSharedVariable[Failed, Hit] 


N@Mean[Flatten@ParallelTable[x = Random[];
    ProbabilityStillGoing = (1 - \[Pi]/200)^j;
    If[ProbabilityStillGoing > x, Failed++, Hit++];
    If[Failed == Hit, j, {}],

    {j, 0, NUMBER}]
  ] 
POSTED BY: David Reiss
Posted 10 years ago

Hi David, thank you for your response.

This code is attempting to solve the 2D version of Olber's Paradox. The problem statement is as follows:

Robin Hood is standing in the middle of a forest. On average there is one tree of radius one meter per 200 square meters. If Robin Hood is placed at a random location in the forrest and shoots an arrow, how far will it travel?

We consider the trees as points in a 200 meter square area and the arrow as a line two meters long. We need to figure out how far the arrow has to travel before it sweeps out an area of 200 square meters. So, we get 100 meters.

The mean of all the numbers printed in the code divided by the number of times it was ran should give 100 meters. Mean[Distances] // N = approximately 100.

It comes from this site: https://sites.google.com/site/themontecarlomethod/home/robin-hood

POSTED BY: Fat Villager

What are you expecting this code to do?

Note (assuming you've given NUMBER a value) that the body of your ParallelTable command ends with a semicolon and there is a semicolon after the full ParallelTable expression. So (1) the table will contain all Nulls and the output of the calculation will be suppressed. The code runs, it just does not return anything. And the Print statements may or may not execute depending on the details of what's happening inside of the code.

POSTED BY: David Reiss
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract