I have a code set up for a randomwalk already, but how would I alter it to make a 3D Random Walk?
steplenght = .01;positions = zeros(2,100000); currentPosition = [0;0];currentTimeStep = 2; while currentPosition(1,1)^2 + currentPosition(2,1)^2 < 1 randomDirection = 2*pi*rand(); unitDisplacementVector = [cos(randomDirection); sin(randomDirection)]; displacementVector = stepLength*unitDisplacementVector; currentPosition = currentPosition + displacementVector; positions(:,currentTimeStep) = currentPosition; currentTimeStep = currentTimeStep + 1;end positions = positions(:,1:currentTimeStep-1); hold on; scatter(positions(1,:),positions(2,:),2,'filled'); theta = linspace(0,2*pi);plot(cos(theta),sin(theta));
Best Answer