%%% Your task is to determine if the average length of a random walk varies
%%% as you vary the number of dimensions.
%%% Example: N=1 -- random walk on the line; N=3 Random walk in 3D space.
%-----------------------------------
% Create a simulation for computing random walks in N dimensions where N
% is to be specified by the user.
% In particular, the user will specify the number of steps to be taken,
% the number of times the simulation is repeated.
% In addition, the summary statistics will be returned: mean and standard
% deviation of the distance from the origin traveled over the e.g. 1000
% repetitions of the simulation.
% A step is taken +/- one unit along a single dimension -- it is a random
% walk on a lattice rather than on arbitrary directions in real space.
nSteps = input('Enter the number of steps in a single run: ')
nRepeats = input('Enter the number of simulation runs to do: ')
nDimensions = input('Enter the number of dimensions of the space: ')
distanceStats = zeros(1,nRepeats); % Contains distance traveled in each run.
currentParticlePosition = zeros(1, nDimensions); % Start at (0,0, ..., 0)
%----------------------------------------------------------------------------
% Fill in all the code details here (easy to do with nested for loops):
%--------------------------------------------------------------------------
distTraveled = sqrt(sum(currentParticlePosition.^2)); % Euclidean distance from origin.
distanceStats(1,i) = distTraveled;
fprintf('Final Position: %6.2f \n', currentParticlePosition);
fprintf('The distance from the origin is: %6.2f \n', distTraveled);
meanDist = mean(distStats);
stdDist = std(distStats);
fprintf('Mean: %6.2f and standard dev: %6.2f of distance traveled. \n', meadDist, stdDist);
% -------------------------------------------------------------------------
% 1. Do enough simulation runs for nDimensions = 1, 2, 3, 10
% to draw conclusions about whether the distance from the origin varies
% with the number of dimensions.
%
% 2. Plot the mean and standard deviation of distStats for 1, 2, 3, 10
% to demonstrate your conclusion.
%
%