Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 : 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 onedimension:
a Write a program that calculates the number of steps required for a particle to move a distance of units. The position of a particle will be computed by:
where is a random number between and The initial position of the particle will be Hint: Use rand which generates a random number between and to generate a random number between 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 that varies from to units in increments of :: The initial posiiton of the particle will always start at
The code should store the number of steps needed to travel each length, This can be done by initializing an empty array eg stepsperL 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,
Finally, make a plot that shows the number of steps needed to move each value of Leg L vs number of steps
clear; Clear all variables in the workspace
Initialize an array to number of steps for each L distance
stepsperL ;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started