Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. function [A] = dot2(numsteps,start)
  2. %
  3. %
  4. % Inputs:
  5. % numsteps = number of steps that should be calculated
  6. % start = [2x1]-vector which represents the x- and y-coordinates of the startposition
  7. % Outputs:
  8. % A = [numstepsx2]-matrix with the x- and y-coordinates of the point at each step
  9. %
  10.  
  11. if (nargin() == 0)
  12. error('U moet minstens 1 inputvariabele invoeren')
  13. elseif nargin() == 1
  14. disp('Geen startpositie ingevoerd: er wordt een willekeurige startpositie gekozen in het vierkant [0,1] x [0,1].')
  15. start = [rand,rand]
  16. end
  17.  
  18.  
  19. d = rand
  20. A = zeros(numsteps,2)
  21.  
  22. n = rand-0.5
  23. if n<0
  24. A(1,:) = [start(1)+ sign(rand-0.5)* d, start(2)]
  25. end
  26.  
  27. if n>0
  28. A(1,:) = [start(1), start(2)+ sign(rand-0.5)* d]
  29. end
  30.  
  31. for i=2:numsteps
  32. n = rand-0.5
  33. if n<0
  34. A(i,:) = [A(i-1,1) + sign(rand-0.5)* d, A(i-1,2)]
  35. end
  36.  
  37. if n>0
  38. A(i,:) = [A(i-1,1), A(i-1,2) + sign(rand-0.5)* d]
  39. end
  40. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement