Random walk code - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Random walk code

DgraymanDgrayman Posts: 4Member
Hello, this is the Question:
Suppose you want to know how often a single source of fungus will spread more than one foot from a fallen tree. You will be using a computer simulation to answer the question.

i found this code using the m file ranwalk2d.m:

2-dimensional random walk
ranwalk2d.m

Plots the points (u(k),v(k)), k=1:n, in the (u,v)-plane, where (u(k)) and (v(k)) are one-dimensional random walks. The sample code plots four trajectories of the same walk, four different colors.

n=100000;
colorstr=['b' 'r' 'g' 'y'];
for k=1:4
z=2.*(rand(2,n)<0.5)-1;
x=[zeros(1,2); cumsum(z')];
col=colorstr(k);
plot(x(:,1),x(:,2),col);
hold on
end
grid



The problem is i don't want the graph to go below 0 on the y axis. In other words pertaining to the problem, the fungus cant go back to its starting point.

I'm not a computer science person so i'm not that knowledgeable. Can Someone please guide me on how to do random walks on matlab?

Comments

Sign In or Register to comment.