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:Mfor n = 1:NA = sign(randn);x_t(n+1) = x_t(n) + A;A = sign(randn);y_t(n+1) = y_t(n) + A;endplot(x_t, y_t);hold onendgrid on;set(gcf, 'Units', 'Normalized', 'Outerposition', [0, 0.05, 1, 0.95]);axis square;