self avoiding random walk
显示 更早的评论
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 个评论
Image Analyst
2013-11-18
编辑:Image Analyst
2013-11-18
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
2013-11-18
采纳的回答
更多回答(1 个)
Image Analyst
2013-11-19
0 个投票
"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 个评论
Walter Roberson
2013-11-19
The direction is random, but it appears the choices of direction are left, right, up, down.
Image Analyst
2013-11-19
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
2013-11-19
Image Analyst
2013-11-19
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
2013-11-19
Image Analyst
2013-11-19
编辑:Image Analyst
2013-11-19
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
2013-11-19
类别
在 帮助中心 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!