Question: Problem 4 : Random Walk Random walks are useful for simulating the diffusion of particles in a liquid or gas, the movement of bacteria in

Problem 4: Random Walk
Random walks are useful for simulating the diffusion of particles in a liquid or gas, the movement of bacteria in a solution, or even the escape of photons from the center of the Sun.
First we will program a random walk in one-dimension:
a) Write a program that calculates the number of steps required for a particle to move a distance of +-10 units. The position x of a particle will be computed by:
xj+1=xj+s
where s is a random number between -1 and 1. The initial position of the particle will be x=0.(Hint: Use rand (1), which generates a random number between 0 and 1, to generate a random number between -1 and
Google "concatenate array MATLAB" if you aren't sure how to add values to the end of an array.)
clear; %Clear all variables in the workspace
b) Copy your code from part (a) and past it below. Change that code so that it runs through a loop to calculate the number of steps needed to move a length L that varies from 5 to 100 units in increments of 5)=(10:5:100. The initial posiiton of the particle will always start at 0.
The code should store the number of steps needed to travel each length, L. This can be done by initializing an empty array (e.g. steps_per_L=[]) at the top of the code and then concatenating new values the the end of the array everytime you run the code for a new length, L.
Finally, make a plot that shows the number of steps needed to move each value of L.(e.g. L vs. number of steps).
clear; 8Clear all variables in the workspace
%Initialize an array to number of steps for each L distance
stepsperL=[] ;
 Problem 4: Random Walk Random walks are useful for simulating the

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!