Complete self-avoiding random walk
이전 댓글 표시
Dear Matlab users,
I want to make a self-avoinding random walk. And by self avoiding I mean that the steps would never cross previous steps that have been taken until now.
So far I have written the code below:
a = 1 ; % Step size
N = 5 ; % Number of Random Walks
S = 100 ; % Number of steps
randWalkMat = [...
1 -1 0 0 0 0;
0 0 1 -1 0 0;
0 0 0 0 1 -1;
];
X = zeros(S,N);
Y = X;
Z = X;
for k = 1:N
t = randi(6, 1, S);
randWalk = randWalkMat(:, t);
X(:,k) = randWalk(1,:);
Y(:,k) = randWalk(2,:);
Z(:,k) = randWalk(3,:);
end
% Now we have the data for N number individual random seeds, and
% we have it for S number of steps:
% we get N sets of data for S random steps:
x_final = [[0,0];cumsum(X)];
y_final = [[0,0];cumsum(Y)];
z_final = [[0,0];cumsum(Z)];
% We plot the Random walk:
plot3(x_final,y_final,z_final,'x-')
grid on
axis equal
Any help is highly appreciated,
Argu
채택된 답변
추가 답변 (1개)
Ritish Kumar
2019년 5월 29일
0 개 추천
if we make a program for sef avoiding random walk for polymer than how can we approach that problem and how we calculate some parameters from that program. Any suggessions and help are highly appreciated.
댓글 수: 1
I'd start by stepping through the lines of code in the answer on this page so you can understand how it works. Here's another one:
카테고리
도움말 센터 및 File Exchange에서 Performance and Memory에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!