move plotting stuff to own folder
This commit is contained in:
26
programming/code/simplerandomwalk.m
Normal file
26
programming/code/simplerandomwalk.m
Normal file
@@ -0,0 +1,26 @@
|
||||
num_runs = 10;
|
||||
max_steps = 1000;
|
||||
|
||||
positions = zeros(max_steps, num_runs);
|
||||
|
||||
for run = 1:num_runs
|
||||
for step = 2:max_steps
|
||||
x = randn(1);
|
||||
if x < 0
|
||||
positions(step, run) = positions(step-1, run) + 1;
|
||||
elseif x > 0
|
||||
positions(step, run) = positions(step-1, run) - 1;
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
figure()
|
||||
hold on
|
||||
for run = 1:num_runs
|
||||
plot(1:max_steps, positions(:, run))
|
||||
end
|
||||
xlabel('Number of steps')
|
||||
ylabel('Position')
|
||||
box off
|
||||
|
||||
|
||||
Reference in New Issue
Block a user