This repository has been archived on 2021-05-17. You can view files and clone it, but cannot push or open issues or pull requests.
scientificComputing/programming/exercises/randomwalk.m

14 lines
288 B
Matlab

function [time, position] = randomwalk(numbersteps)
% 1-D random walk for numbersteps time steps
time = 1:numbersteps;
position = zeros(numbersteps, 1);
for i = time(2:end)
r = rand(1);
if r > 0.5
position(i) = position(i-1) + 1;
else
position(i) = position(i-1) - 1;
end
end
end