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!