Answered step by step
Verified Expert Solution
Link Copied!

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 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=[] ;
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Medical Image Databases

Authors: Stephen T.C. Wong

1st Edition

1461375398, 978-1461375395

More Books

Students also viewed these Databases questions

Question

LO 10-3 Ways to construct the different parts of negative messages.

Answered: 1 week ago

Question

7. Identify six intercultural communication dialectics.

Answered: 1 week ago