Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function [A] = dot2(numsteps,start)
- %
- %
- % Inputs:
- % numsteps = number of steps that should be calculated
- % start = [2x1]-vector which represents the x- and y-coordinates of the startposition
- % Outputs:
- % A = [numstepsx2]-matrix with the x- and y-coordinates of the point at each step
- %
- if (nargin() == 0)
- error('U moet minstens 1 inputvariabele invoeren')
- elseif nargin() == 1
- disp('Geen startpositie ingevoerd: er wordt een willekeurige startpositie gekozen in het vierkant [0,1] x [0,1].')
- start = [rand,rand]
- end
- d = rand
- A = zeros(numsteps,2)
- n = rand-0.5
- if n<0
- A(1,:) = [start(1)+ sign(rand-0.5)* d, start(2)]
- end
- if n>0
- A(1,:) = [start(1), start(2)+ sign(rand-0.5)* d]
- end
- for i=2:numsteps
- n = rand-0.5
- if n<0
- A(i,:) = [A(i-1,1) + sign(rand-0.5)* d, A(i-1,2)]
- end
- if n>0
- A(i,:) = [A(i-1,1), A(i-1,2) + sign(rand-0.5)* d]
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement