Brownian motion 1d COMPLETE Random Walk Simulator (1-Dimensional) Introduction I
ID: 3864661 • Letter: B
Question
Brownian motion 1d COMPLETE
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.
%%%%%%%%%%%%%%%%%%%%%%
Here is what i came up with for the final code, incase anyone else encounters this problem, it was tough to find an example for to referance anywhere, so here it is completed
%Rodney H
%MATLAB
%Random walk Brownin motion 1d
clc;
close all;
clear all;
%i put these here(above because it started doing weird things after i ran
%it a few times
tic
%i was curious how long the simulations were taking
%when i wasnt suppressing my out put it was adding a LONG time to my
%calclation
%i usually used 100-1000 walkers, 150 steps and barriers set at 2
%walker option
walkers=input('how many walkers do you want to simulate?')
%how many steps to take
Nsteps = input('how many steps do you want?')
%set barrier limits
B = input('what limits do you want the barrier splaced at?')
%input for the chance of reflecting
chance=input('what do you want the chance to reflct be if chance is selected (enter 0-100)?')
menu=menu('how do you want the barriers to act?','reflect','absorb','chance');
% = 'Please Enter your Choice for how barrier acts? ';
x = zeros(walkers,Nsteps);
%makes a matrtix of zeros for the following function to fill in
for w= 1:walkers
for k = 1:Nsteps %for each walker
x(w,k+1)= x(k)+ randn(1,1);
%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
switch menu
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=rand(1,1);
if p<(chance/100)
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;
subplot(2,2,1) %made subplot to plot all the graphs at same time
plot(x(w,:))
xlabel ('steps/time')
ylabel('position')
title('position')
end
%need to find a way to make matrix x only 150 not 151 if walkers survive to the end
x=x(:,1:Nsteps);
alive=sum(x~=0);
% plot the ones that are still alive
subplot(2,2,2)
plot(1:Nsteps,alive)
xlabel ('steps/time')
ylabel('number alive')
title('walkers remaining')
%average
average=sum(x)./sum(x~=0);
subplot(2,2,3)
plot(1:Nsteps,average)
xlabel ('steps/time')
ylabel('average position')
title('Average position')
%I was having a tough time figuring/finding how to no have the zeros affect my
%outcome, I borrowed this code from a forum and modified it to fit my
%needs
for nc = 1:Nsteps
indexToNonZero = x(:,nc)~=0;
sd(nc) = std(x(indexToNonZero,nc));
end
subplot(2,2,4)
plot(1:Nsteps,sd)
xlabel ('steps/time')
ylabel('deviation')
title('Standard Deveation')
toc
Explanation / Answer
A)
queuq area:
The rides have a fixed number of guests that can be served at any given time, so there has to be some control over additional guests who are waiting. This led to the development of formalized queue areas.queue areas can be elaborately decorated, with holding areas fostering anticipation, thus shortening the perceived wait for people in the queue by giving them something interesting to look at as they wait, or the perception that they have arrived at the threshold of the attraction.different lines tend to be handled at different speeds; some people are served quickly, while others may wait for longer periods of time. Sometimes two people who are together split up and each waits in a different line; once it is determined which line is faster, the one in the slower line joins the other. Another arrangement is for everyone to wait in a single line.Queues can be found in railway stations to book tickets, at bus stops for boarding and at temples as well
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.