Random Walk on 2D Modification

조회 수: 2 (최근 30일)
Ege Tunç
Ege Tunç 2018년 12월 26일
댓글: Ege Tunç 2019년 1월 6일
I have 2D random walk code part for neutrons. However, the code includes some conditions, 2 of them are:
  • on the next step the neutron cannot step back, but only forward, left or right ,
  • the probability to go forward is twice more than changing a direction
I could not modified the code for "cannot step back" part. Also, i have no idea how to make the probability is doubled for not changing direction. Since, if it's once changed direction it has the change to go straight forward is still doubled.
Here's the code:
clc;
clearvars;
N = 100; % Length of the x-axis, also known as the length of the random walks.
M = 100; % The amount of random walks.
x_t(1) = 0;
y_t(1) = 0;
for m=1:M
for n = 1:N
A = sign(randn);
x_t(n+1) = x_t(n) + A;
A = sign(randn);
y_t(n+1) = y_t(n) + A;
end
plot(x_t, y_t);
hold on
end
grid on;
set(gcf, 'Units', 'Normalized', 'Outerposition', [0, 0.05, 1, 0.95]);
axis square;
  댓글 수: 4
Walter Roberson
Walter Roberson 2019년 1월 6일
"close" means make it invisible to the public, such as for a question that needs clarification from the author.
Ege Tunç
Ege Tunç 2019년 1월 6일
okay, i opened it. sorry for my misunderstanding

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2018년 12월 26일
편집: Walter Roberson 2018년 12월 26일
dd = randi(4)
for ss = 1:500
rr = rand;
if rr < 1/4
dd = 1+mod(dd,4) %next higher direction
elseif rr < 1/2
dd = 1+mod(dd-2,4) %next lower direction
end % 50 percent stays same direction
if dd==1
yy=yy+1; %north
elseif dd==2
xx=xx+1; %east
elseif dd==3
yy=yy-1; %south
else
xx=xx-1; %west
end
plot here probably
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Elementary Math에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by