One of our professors told us that during his thesis he used Mathematica in simulating it since it is about networks, I don't know how he did it but all I know is he said it took about two weeks to run it and get a result. We use it on our research as well and we're new to it of course, one of our goal is to determine the estimated time or mean of two points to meet. The meet-up is defined position1-position2=1. It is repeated 10,000 times.
This code:
For[i = 1, i <= 10000, i++,
pos1 = 2;
pos2 = -2;
t = 1; While[Abs[pos1 - pos2] > 1,
If[2 > pos1 > -2, pos1 = pos1 + RandomChoice[{-1, 0, 1}],
pos1 = pos1 + RandomChoice[{-1, 0}]];
If[2 > pos2 > -2, pos2 = pos2 + RandomChoice[{-1, 0, 1}],
pos2 = pos2 + RandomChoice[{0, 1}]]; t++];
time[i] = t]
avetime = N[Mean[Table[time[i], {i, 1, 10000}]], 5]
stdev = N[StandardDeviation[Table[time[i], {i, 1, 10000}]]]
To simply explain this, what it does is there are two points on a one-dimensional integer line, on -2 and 2. What it does is move until they meet(not joined) as defined in our meet-up position1-position2=1, as put as a test inside the while code, "Abs[pos1 - pos2] > 1" it stops once this is false which is when it becomes pos1-pos2=1. That is done 10,000 times(that is why we put it inside the 'For' code). Now this actually ran with ease and fast but when we tried -40 to 40 and -50 to 50 it started to take a long time to get a result.
Now we are trying -500 and 500 and it's been 12 hours and still got no result. Do I wait like my professor turned his computer on for about 2 weeks to get a result or is the code just inefficient? It seems simple to take a long time to run. I'm using a laptop that is not high-end, does that matter? Also if I make my laptop sleep and the screen locks, when I turn it back on does it stop the running Mathematica and resume it when I turn it on again? If the code is inefficient any comments, suggestions, or improvements are open just bear that we don't necessarily need a graphic, getting the mean is enough.
For[i = 1, i <= 10000, i++,
pos1 = 500;
pos2 = -500;
t = 1; While[Abs[pos1 - pos2] > 1,
If[500 > pos1 > -500, pos1 = pos1 + RandomChoice[{-1, 0, 1}],
pos1 = pos1 + RandomChoice[{-1, 0}]];
If[500 > pos2 > -500, pos2 = pos2 + RandomChoice[{-1, 0, 1}],
pos2 = pos2 + RandomChoice[{0, 1}]]; t++];
time[i] = t]
avetime = N[Mean[Table[time[i], {i, 1, 10000}]], 5]
stdev = N[StandardDeviation[Table[time[i], {i, 1, 10000}]]]
1.77052 seconds
just using 2 as an upper bound for yourFor
loop. So going to 10,000 iterations (assuming it scales linearly, which it may not) means it will take a few hours. I would recommend comilation $\endgroup$FirstPassageTimeDistribution
, and possibly above it with other symbolic random process/probability methods. This might be impractical for upper limit of 500 (because this would result a transition matrix of about trillion probabilities), although the matrix would be very sparse. $\endgroup$