self avoiding random walk
Afficher commentaires plus anciens
i need help. what i think i have to do is choose a direction at random and then look at a direction i want to go to if it's empty then carry on. if the direction is used then you start another walk. 1000 walks and lenght 1 to 25. how do i calcalute the number of successful walks. the code i have is a random walk
r=[0 0];
X=[0];Y=[0];
for
t= 1:1:100
B=rand(1,1)*4;
if B<1
new_position=r+[1 0];
elseif B<2
new_position=r+[0 1];
elseif B<3
new_position=r+[-1 0];
else
new_position=r+[0 -1];
end
X=[X new_position(1)];
Y=[Y new_position(2)];
r=new_position;
end
plot(X,Y)
2 commentaires
Image Analyst
le 18 Nov 2013
Modifié(e) : Image Analyst
le 18 Nov 2013
http://www.mathworks.com/matlabcentral/answers/13205-tutorial-how-to-format-your-question-with-markup How do you define "empty"? Are you trying to avoid having the next step cross any paths on the route so far?
nawal
le 18 Nov 2013
Réponse acceptée
Plus de réponses (1)
Image Analyst
le 19 Nov 2013
0 votes
"By empty I mean the point is occupied/ already visited" - I doubt that will never happen, at least probably not in your lifetime. The chance of a pair of double precision numbers being repeated exactly is vanishingly small.
7 commentaires
Walter Roberson
le 19 Nov 2013
The direction is random, but it appears the choices of direction are left, right, up, down.
Image Analyst
le 19 Nov 2013
Is he then saying that the quadrant has one or more points in it, as opposed to landing exactly on the precise location of a prior point?
nawal
le 19 Nov 2013
Image Analyst
le 19 Nov 2013
Still unclear. What if I was at (1,0) and I stepped to (2,0). So if I step back in the general direction where I came from (back along the x axis towards the origin) and I would land at exactly (to the maximum precision allowed by the computer) (1,0) I can see that you want to stop. But like I said, you won't ever land there. So what if you'd land at (1.000000001, 0.000009), which is really really close? Do you want to stop in that case too?
nawal
le 19 Nov 2013
Image Analyst
le 19 Nov 2013
Modifié(e) : Image Analyst
le 19 Nov 2013
Still unclear. When do you want to stop it?
- If it lands anywhere in the "backwards" half plane?
- Or if it lands within a certain distance from the last point?
- Or if it lands within a certain distance from any prior point?
Which case(s)?
nawal
le 19 Nov 2013
Catégories
En savoir plus sur Logical dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!