Question

In: Statistics and Probability

Compute and plot the path(s) of a set of random walkers which are confined by a...

Compute and plot the path(s) of a set of random walkers which are confined by

a pair of barriers at +B units and -B units from the origin (where the walkers

all start from).

A random walk is computed by repeatedly performing the calculation

x

j+1

= x

j

+ s

where s is a number drawn from the standard normal distribution (‘randn

in

MATLAB). For example, a walk of N steps would be handled by the code fragment

x(1) = 0;

for j = 1:N

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

end

There are three possible ways that the walls can "act":

a. 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,

when x

j+1

> B,

x

j+1

= B - |B - x

j+1

|

when x

j+1

< (-B),

x

j+1

= (-B) + |(-B) - x

j+1

|

If you plot the paths, you should not see any positions that are beyond |B|

units from the origin.

b. Absorbing - In this case, if a walker hits or exceeds the wall positions, it

"dies" or is absorbed and the walk ends. For this case, it is of interest

to determine the mean lifetime of a walker (i.e., the mean and distribution

of the number of steps the "average" walker will take before being absorbed).

c. 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 (0 < p < 1) for

reflection, the pseudo-code fragment that follows uses the MATLAB uniform

random-number generator to make the reflect/absorb decision:

if rand < p

reflect

else

absorb

end

What do you do with all the walks that you generate? Compute statistics, of course.

You should answer questions like

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

What is the standard deviation of the position of the walkers as a function

of time?

Does the absorbing or reflecting character influence these summaries?

For the absorbing/partial-reflection case, a plot of the number of surviving

walkers as a function of step numbers is a very interesting thing. Useful, informative and

interesting, particularly if graphically displayed.

Report Requirement

In your project report, you need to

Describe the process of getting the answers and explain your graph or table. You have

to make it understandable to students with basic knowledge of the pre-requisites and

the course materials covered so far. In general, you should type it up in a word

document and copy and paste any relevant results from MATLAB.

Append your MATLAB programs at the end of your document or submit them as

separate files.

Organize your report according to the questions asked.

Submitting only MATLAB files will result in very few points.

Solutions

Expert Solution

  • matlab code:

    %% Program Starts here
    clc;
    close all;
    clear all;
    walkers=1000;
    %walkers=input('how many walkers do you want to simulate?')
    Nsteps = 1000;
    B=3;
    %N = input('how many steps do you want?')
    %menu for how barrier acts
    %case 1 reflect/ bounce back in
    %case 2 end walk
    %case 3 flip coin to decide bounce or end walk
    prompt = 'Please Enter your Choice for how barrier acts? ';
    option = input(prompt);
    if option==3
    prompt = 'Enter the Probability of reflection(0-1) ';
    p_val = input(prompt);
    end
    x = zeros(walkers,Nsteps);
    for w= 1:walkers
    for k = 1:Nsteps %for each walker
    x(w,k+1)= x(k)+ randn(1,1);
    switch option
    case 1
      
    if x(w,k+1)> B
    x(w,k+1)=B-abs(B-x(w,k+1));
    else
    x(w,k+1)=-B+abs(-B-x(w,k+1));
    end
      
    case 2
    if (x(w,k+1)>= B) || (x(w,k+1)<= -B)
    break;
    end
      
    case 3
    p=randn(1,1);
    if p<p_val
    if x(w,k+1)> B
    x(w,k+1)=B-abs(B-x(w,k+1));
    else
    x(w,k+1)=-B+abs(-B-x(w,k+1));
    end
    else
    if x(w,k+1)>= B || x(w,k+1)<= -B
    break;
    end
    end
    end
    end
    hold on;
    grid on;

    plot(x(w,:))
    end

    output:


Related Solutions

For a system with G(s) in forward path and H(s) in feedback path, Derive in details...
For a system with G(s) in forward path and H(s) in feedback path, Derive in details the equivalent transfer function and its zeros/poles?
Give a recursive algorithm to compute a list of all permutations of a given set S....
Give a recursive algorithm to compute a list of all permutations of a given set S. (That is, compute a list of all possible orderings of the elements of S. For example, permutations({1, 2, 3}) should return {〈1, 2, 3〉, 〈1, 3, 2〉, 〈2, 1, 3〉, 〈2, 3, 1〉, 〈3, 1, 2〉, 〈3, 2, 1〉}, in some order.) Prove your algorithm correct by induction.
Which network path is the critical path of this project?
Which network path is the critical path of this project?
# Problem 5: Use R to compute: # (a)(6 pts) Set three random vectors of 1000...
# Problem 5: Use R to compute: # (a)(6 pts) Set three random vectors of 1000 random numbers as follows: # x1: from Unif(0,5), # x2: from Binom(70,0.2), and # x3: from Exp(1). # Define y = x1 + 4*x2 + 8*x3 + 10 + Err, where Err ~ N(0,sd=10). # (b)(6 pts) Create a dataframe df containing these four variables # and create scatterplots of all pairs of these four variables. # (c) Create a multiple regression model for...
Given the sample data set s = [1,1,2,2,2,9,-5,-10,8,0] Compute the mean, median, mode, variance and standard...
Given the sample data set s = [1,1,2,2,2,9,-5,-10,8,0] Compute the mean, median, mode, variance and standard deviation on paper/ text editor. Show all calculation steps for full credit. Compute and verify the above statistical quantities using python. You can use the statistics package. Feel free to modify the sample code provided in the pre-class material. Your code must clearly print out the required quantities when executed. The display on screen must clearly say what quantity is being printed (eg: “The...
A multivariate random variable (X1, X2, X3) takes values in the following set S with equal...
A multivariate random variable (X1, X2, X3) takes values in the following set S with equal probability: S = {(1, 1, 1),(3, 0, 0),(0, 3, 0),(0, 0, 3),(1, 2, 3)}. a) Compute E[X1|X2 = i], for each i = 0, 1, 2, 3, and E[X1]. b) Compute the marginal p.m.f. of Xi for each i = 1, 2, 3.
Let R and S be equivalence relations on a set X. Which of the following are...
Let R and S be equivalence relations on a set X. Which of the following are necessarily equivalence relations? (1)R ∩ S (2)R \ S . Please show me the proof. Thanks!
Which statement(s) about state functions is(are) correct? (i) State functions are the opposite of path-dependent functions....
Which statement(s) about state functions is(are) correct? (i) State functions are the opposite of path-dependent functions. (ii) State functions have no “memory” about how they arrived at a given value. (iii) State functions are path-dependent functions. (iv) Heat and work are not state functions and neither is their sum a state function.
When activity times are known with certainty, the critical path is defined as the set of...
When activity times are known with certainty, the critical path is defined as the set of activities on a path from the project’s start event to its finish event that, if delayed, will delay the completion date of the project. Why must this definition be modified in situations where the activity times are not known with certainty? Are there dangers associated with not modifying the definition?
Using MATLAB plot path loss prediction versus distance and log distance for a cellular system you...
Using MATLAB plot path loss prediction versus distance and log distance for a cellular system you are designing with the following assumptions: PCS frequency (1900 MHz), base height 20 m, mobile 2 m, suburban area, flat terrain with moderate tree density.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT