| Author |
Comment/Response |
Steve Hunt
|
07/30/11 10:40pm
I'm brand new to programming in Mathematica (have some experience in R and Java) and need some sage advice. I've written a very basic (to start) simulation to model stochastic Lanchester equations. However, the code is not working and after hours now reading through the Mathematica "help" on the basics of while, if, etc. control structures, I still have no idea what I'm doing wrong.
The code is below - it's very short - and I would appreciate any help at all in pointing me in the right direction to find the error in my logic/understanding of Mathematica. Thanks much.
Steve
m0 = 4;
n0 = 2;
a = .02;
b = .01;
breakPt = 0.0;
trials = 100;
timeDist[l_] := RandomVariate[ExponentialDistribution[l]];
summary = {{0, m0, n0}};
For[i = 1, i < trials, i++,
m = m0;
n = n0;
t = 0;
While[m > breakPt || n > breakPt,
lambda = a n + b m;
t = t + timeDist[lambda]];
If[RandomReal[] <= (a n/(a n + b m)), m--,n--];
]
summary = Append[summary, {t, m, n}];
]
URL: , |
|