Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is a programming project for MATLAB I am working on and it is proving difficult, any assistance would be appreciated, I realize there are

This is a programming project for MATLAB I am working on and it is proving difficult, any assistance would be appreciated, I realize there are a few parts to this question but i feel thet it is better asked all as one post for continuity. feel free to charge me more than 1 question out of my question bank if needed

Random Walk Simulator (1-Dimensional) Introduction Imagine a person standing on a one-dimensional number line. Every so often, the person takes a step of varying length in either the positive or negative direction. This process repeats until the person reaches a barrier, which is a fixed distance away from the origin point. Because the length and direction of the step are random, this scenario is sometimes called a random walk.

3 2 1 0 1 2 3

The Project You will compute and plot the paths of a set of many1 random walkers, which are confined by a pair of barriers at +B and B. Assume all of the walkers start at x = 0.

A random walk is computed by repeatedly performing the calculation

xk+1 = xk + s

where s is a number from the standard normal distribution (randn in MATLAB). For example, one walker taking N steps could be handled by the code fragment

x(1) = 0;

for k = 1:N

x(k+1) = x(k) + randn(1,1);

end

There are three ways in which the barriers can act:

1. Reflecting - In this case, when the new position is outside the walls, the walker is bounced back by the amount that it exceeded the barrier. That is, whenever xk+1 > B, then xk+1 = B |B xk+1|, and whenever xk+1 < (B), then xk+1 = (B) + |(B) xk+1|. If you plot the paths, you should not see any positions that are beyond |B| units from the origin.

2. Absorbing - In this case, if a walker hits or exceeds the wall positions, it is absorbed and the walk ends. For this case, it would be of interest to determine the mean lifetime of a walker (that is, the mean and distribution of the number of steps the average walker will take before being absorbed). 1 In this case, many means about 1000.

3. Partially absorbing - This case is a combination of the previous two cases. When a walker encounters a wall, a coin is flipped to see if the walker reflects or is absorbed. Assuming a probability p, with 0 < p < 1, the pseudo-code fragment below uses the MATLAB uniform random-number generator to make the reflect/absorb decision:

if rand < p

%reflect

else

%absorb

end

Of course, you will have to supply the code that does the reflection or absorption.

Writing the Code

Maybe start with a smaller number of walkers, like 10. Set up the code to generate the paths of the walkers (using matrices) and let it generate some random walks and get a graph going. Play around with the time (number of steps) to see how long it takes them to hit the barriers.

For graphing: plot the distance from the origin in the y-direction, and time (step number) in the x-direction.

Once you have that working, implement the barriers acting as reflectors only. Start with a fixed B, maybe B = 3. Try setting B at a different number and see what happens. You could also let the user choose a value of B.

After that works, implement the barriers as absorbers. Run that version a few times and see what happens to the walkers.

Then, add an option at the beginning with a menu for the user to decide whether the barriers should act as reflectors or absorbers or as a combination. If they choose combination, ask the user to give you the probability of reflection, p.

Now ramp up the number of walkers to 1000.

In addition to drawing plots of the paths

Compute statistics.

What is the average position of the walkers as a function of time?

Create an array and plot it to answer this question.

What is the standard deviation of the walkers positions as a function of time?

Does the absorbing or reflecting option influence your answers to the previous two questions?

For the absorbing/partial-reflection case, a plot of the number of surviving walkers as a function of step number (or time), it is a very interesting and It is useful and informative, particularly if graphically displayed.

Thanks for the help

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

Database Processing Fundamentals Design

Authors: Marion Donnie Dutton Don F. Seaman

14th Edition Globel Edition

1292107634, 978-1292107639

More Books

Students also viewed these Databases questions

Question

2. How can competencies be used in employee development?

Answered: 1 week ago