Random walk with variable pitch


>Top, >Model

The simplest case is that of a particular movimg along an axis that can impact some object, after which it will reverse its direction of advance.

If the probability of reaching a distance between x and x+dx is P(x), the probability of impact will be equal to


If this probability is proproposal to the probability itself P, one has


and get the probability function

$p(x)dx = \displaystyle\frac{1}{\lambda}e^{-x/\lambda}dx$

We will call \lambda the free path.

ID:(9099, 0)



>Top, >Model

If the distribution is integrated

$p(x)dx = \displaystyle\frac{1}{\lambda}e^{-x/\lambda}dx$

over all possible distances x and assumes that \lambda is constant, you get

$\displaystyle\int_0^{\infty}p(x)dx = \displaystyle\int_0^{\infty}\displaystyle\frac{1}{\lambda}e^{-x/\lambda}dx=1$

which means that the function is normalized. This is not surprising since the function p(x) corresponds to a probability distribution.

ID:(9251, 0)

Free path of a photon



If the free path is given as a function of density, it can be compared between different materials. Being a function of the energy of the photon, it is obtained that the free path in bone and water are in the range 0 to 10MeV very similar:


If an estimate of the free path of the photon in water is desired, which shows a behavior very similar to that of tissue, it is sufficient to multiply the length in grams per square centimeter by the density, with which values between 0 and 30 cm are obtained.

ID:(9256, 0)

Free path of several particles



If you compare the free paths for photons, neutrons, electrons and protons in water, observe differences in powers of ten:

Free path of particles in water (ICRU report of 1970).

In this case the values are indicated in centimeters. For the range of up to 0.01 to 6 MeV the ranges (in cm) are

Particle | 0.01 MeV | 6 MeV

------------- |: ------------: |: ----------:

Photons | 0.198 | 41.7

Neutrons | 0.878 | 0.430

Electrons | 0.00032 | 0.211

Protons | - | 0.033

ID:(9257, 0)

Code structure (1)



The structure of the simulation code must have three basic units:

- the definition of the distribution function (the arrangement that collects balls in the Galton table)

- the simulator of the advance of the particle that delivers the final position

- the unit that determines the class that must be increased in the distribution function (the unit that determines in which container of the receiver of balls this is deposited)

For the first point we must define an arrangement, which initially is set to zero, which is finally populated according to the position reached.

For the first step we must first define the range in which the ball falls, that is, a minimum value x_{min} (xmin) and a maximum value x_{max} (xmax). This should be subdivided into num (num) intervals of length Dx:

\Delta x = \displaystyle\frac{x_{max}-x_{min}}{num}

If the arrangement we call it p it will be necessary first to set the num elements to zero (empty the elements of the Galton table)


// set distribution to cero

for(i = 0;i < num;i++){

p[i] = 0.0; // set to empty



Once they have been set to zero we must study the behavior of N balls/particles and determine their final position x after steps steps (see page detailing the calculation):


Position calculation


Once you have obtained the position x you can determine the box in which the ball must be deposited by simply subtracting the minimum value and dividing by the width of each container:

cls = \displaystyle\frac{x-x_{min}}{\Delta x}

With this value you can locate the container p[cls] and add a ball or particle. The corresponding code would be:


cls = round((x-xmin)/Dx); // find position in array

p[cls]++; // increment array p in posicion cls on one


where the round function (in javascript Math.round) rounds the value to get a value cls integer. The command p[cls]++ corresponds to increasing the element p[cls] in one.

ID:(9250, 0)

Path estimation


>Top, >Model

To simulate the path we must be able to randomly generate the free roads based on the distribution

$p(x)dx = \displaystyle\frac{1}{\lambda}e^{-x/\lambda}dx$

To do this, it is enough to calculate the probability of achieving a path x

P(x)=\displaystyle\int_0^x\displaystyle\frac{du}{\lambda}e^{-u/\lambda}=1-e^{-x /\lambda}

and clear the way x


we obtain an equation that if we randomly generate a number between 0 and 1 we will obtain a path x generated with the Poisson distribution.

With this you can define a function:


function exprob (len) {

     var ran = Math.random ();

     if (ran > 0) {

         return -len*Math.log (1-ran);

     } else {

         return len;




in which we considered the generation of a number between 0 and 1 at random and we considered the possibility that the value is zero which would generate problems since the logarithm would be less infinite.

ID:(9255, 0)

Code structure (2)



To calculate the final positions, you must:

- iterate over multiple particles (N)

- for each particle estimate the roads traveled

- add the roads alternating the directions of propagation

In this case it is assumed that in each collision the particle changes its propagation direction. In its beginning it always begins traveling increasing the distance which is defined as the positive direction (dir = 1). In each crash the dir sign is inverted (dir = -dir or dir = 1, this becomes dir = -1).

For the length of the step, the previously defined length generation function (exprob) is invoked, which is weighted with the address to obtain the new position with the previous position.


// particles (n de N)

for(n = 0;n < N;n++){

x = 0; // initial position

dir = 1; // initial direction

for(i = 0;i < sp;i++){

x = x + dir*exprob(len); // new position

dir = -dir; // change direction


// finish position calculation

// clasification of end position x in distribution p



ID:(9258, 0)

Simulador random walk variable pitch



In order to obtain the distribution of the particulars according to the position, it is possible to perform an iteration in which


0. A starting position and direction is defined

1. It is displaced by a distance generated randomly as a function of the distance probability in a direction

2. the direction is reversed

3. continued in 1


If we assume that we expect a definite time and that the particle moves at constant speed, we can determine the position it has after a given time or after a definite total path.

ID:(9100, 0)




Playing with the simulator we noticed that


1. It only makes sense to consider distributions of possible positions

2. The distribution is based on determining positions in discrete ranges

3. Ranges of smaller size require a greater number of iterations


ID:(9101, 0)