How to simulate random motion with constant drift velocity which is also in random direction applied on a particle for some random time

3 次查看(过去 30 天)
I am working on 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 code written is very inefficient and takes too much time. Also it is not giving the required results. Please let me know about the errors in my code. And please describe a better approach to this problem. 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;
t1 is the time for which particle is in random motion only, while t2 is the time for which particle has both random motion and a constant drift velocity , both the times are randomly exponentially distributed.
As a general example, for a time span 0 : 1, let say the times t1 and t2 came out to be, t1(1) = 0.3 and t2(1) = 0.4 then again t1(2)=0.2 and t2(2)=0.1+Num (where Num is of no concern because it is out of the simulation time, which is 1 = 0.3+0.4+0.2+0.1) ). So for all t1, particle has only random state and for all t2 there is another term v*dt that defines its position vector along with the random motion.

回答(1 个)

Pravija Raj
Pravija Raj 2019-8-19
Hello,
I am working on a similar scenario. Were you able to figure out the code for the raised question. Kindly share.

类别

Help CenterFile Exchange 中查找有关 Mathematics 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by