Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #5308

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

From "niels.gierse@gmail.com" <niels.gierse@googlemail.com>
Newsgroups comp.soft-sys.math.mathematica
Subject Monte Carlos from scalar to list, possibly from for-loop to
Date 2011-10-01 07:11 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <j66efm$hf0$1@smc.vnet.net> (permalink)

Show all headers | View raw


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 comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread


Thread

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

csiph-web