lundi 15 mai 2017

Iterating random motion with constant drift velocity on random times in random direction

I am working on simulating random motion of particles, there are two times exponentially distributed randomly defined as t1 and t2. For time less than t1 particle is in free random motion while for time in between t1 and t2 particle have a constant drift velocity in random direction (either positive or negative direction for 1D motion). I am iterating it over and over to change t1 and t2 and to update the position of particle until i reach up to the required simulation time. The problem with the code is that it is too much inefficient because of nested for and if statements (I want to run ~10000 trajectories). Can you suggest any efficient way to do it. Thank you !

 while i<=length(time_list)

       j(:,m)=taum_list(mu); 
 % updating random numbers t1 (resting time) and    
 % t2(moving time)

    for i = k:floor(sum(j(:,m))+(i))

        if(( i-k ) < j(1,m)) 

        Xp(i,2) = Xp(i-1,2) + sqrt(2*Diff*dt)*randn(1);  

        elseif((i-k) >= j(1,m))

        Xp(i,2) = Xp(i-1,2) + sqrt(2*Diff*dt)*randn(1) + v*dt;

        end

     end

     k=i;
     i=floor(i+sum(j(:,m)));
     m=m+1;

end

Here,

time_list = time up to which I want to trace the motion,

v= velocity with which particle is moving is a parameter and taum_list(mu) is a function that returns two time value t1 and t2 exponentially randomly distributed with mean mu.

j variable stores all the t1 and t2 values to use them later on for differentiating the regions of drift and non drift motion and plotting position as a function of time on a figure

j(1,m)=t1;  j(2,m)=t2




Aucun commentaire:

Enregistrer un commentaire