Mathematica 9 is now available
Student Support Forum
-----
Student Support Forum: 'Basic programming help' topicStudent Support Forum > General > Archives > "Basic programming help"

Next Comment >Help | Reply To Topic
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: ,

Subject (listing for 'Basic programming help')
Author Date Posted
Basic programming help Steve Hunt 07/30/11 10:40pm
Re: Basic programming help yehuda ben-s... 08/01/11 00:15am
Re: Re: Basic programming help Steve Hunt 08/01/11 11:21pm
Next Comment >Help | Reply To Topic