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!