Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #5308 > unrolled thread
| Started by | "niels.gierse@gmail.com" <niels.gierse@googlemail.com> |
|---|---|
| First post | 2011-10-01 07:11 +0000 |
| Last post | 2011-10-01 07:11 +0000 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.soft-sys.math.mathematica
Monte Carlos from scalar to list, possibly from for-loop to "niels.gierse@gmail.com" <niels.gierse@googlemail.com> - 2011-10-01 07:11 +0000
| From | "niels.gierse@gmail.com" <niels.gierse@googlemail.com> |
|---|---|
| Date | 2011-10-01 07:11 +0000 |
| Subject | Monte Carlos from scalar to list, possibly from for-loop to |
| Message-ID | <j66efm$hf0$1@smc.vnet.net> |
Dear all,
I started setting up an extremely simple Monte Carlo based Mathematica
simulation.
So far it works for a single particle with this code:
For[t = 0, t < tmax, t = t + dt, {
z = z + vz ;(* move particle *)
rnd = Random[]; (* throw the dice*)
pion = ne[z]*sigvstate[Te[z]][[state]]*dt; (* compute ionization
probability in corona equilibrium *)
If[ rnd < pion, state = state + 1];
PhLoc = Append[PhLoc, z];
PhState = Append[PhState, state];
}]
the time steps are iterated in a for loop. The particle is moved, then
a random variable is taken. Ionization probability is computed and
compared with the random variable.
The ionization is accounted for in the variable 'state':
If[ rnd < pion, state = state + 1];
Obviously I would like to expand this now to many particles, possibly
created by a distribution function.
So if I design every variable to be a list of length of the number of
particles, is there a way to achieve the same functionality?
As you can see the ionization probability is of course a function of
the ionization state.
x={x1,x2,...}
rnd={rnd1,rnd2,...}
pion={pion1,pion2,...}
state={state1,state2...}
So is there a way to get the if statement to a list?
The second question is related. Is there a neat way to get rid of the
for-loop?
I played a little bit around with the Map command, but could not get
it right.
Cheers,
Niels
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web