Complete self-avoiding random walk
Ältere Kommentare anzeigen
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
Akzeptierte Antwort
Weitere Antworten (1)
Ritish Kumar
am 29 Mai 2019
0 Stimmen
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 Kommentar
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:
Kategorien
Mehr zu Performance and Memory finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!