       Monte Carlos from scalar to list, possibly from for-loop to

• To: mathgroup at smc.vnet.net
• Subject: [mg121776] Monte Carlos from scalar to list, possibly from for-loop to
• From: "niels.gierse at gmail.com" <niels.gierse at googlemail.com>
• Date: Sat, 1 Oct 2011 03:09:05 -0400 (EDT)
• Delivered-to: l-mathgroup@mail-archive0.wolfram.com

```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

```

• Prev by Date: Re: How to catch interrupts generated by TimeConstrained?
• Next by Date: Re: help with double integration
• Previous by thread: Re: How to catch interrupts generated by TimeConstrained?
• Next by thread: Re: help with double integration