How would I start this problem?

4 visualizaciones (últimos 30 días)
Gaëtan Poirier
Gaëtan Poirier el 8 de Oct. de 2017
Comentada: Image Analyst el 9 de Oct. de 2017
We consider again the one-dimensional version of the drunkard problem. This time he starts out at position x (e.g., x=10), and takes unit steps left or right with equal probability. Suppose at 0 and a (a>x>0, e.g., a=30) are two bars. When he reaches either one, he is trapped forever.
We want to determine the average time t (the mean number of steps) before the drunkard is trapped. This is a diffusion problem and the 'time' t is called the first passage time. Do a simulation to compute t. (Again note that only the average of t has a meaning and it is that average that we want to compute.)

Respuesta aceptada

Image Analyst
Image Analyst el 8 de Oct. de 2017
See my attached collection of random walk programs/demos I've written. Adapt as needed.
  17 comentarios
Gaëtan Poirier
Gaëtan Poirier el 9 de Oct. de 2017
So here it is so far:
for N=1:10000 %number of "walkers"
x(1)=10; %starting position
out_of_bounds = stepNumber;
for stepNumber=20; %number of steps limited to each "walker"
g(n)=rand(); %random number
if g(n)<0.5
x(n+1)=x(n)-1; %if random number is less than, go left
else x(n+1)=x(n)+1; %else go right
end
if x(n+1)>29||x(n+1)<1 %second bar––if "walker" reaches 30, the loop terminates
break
else continue % else it continues
end
end
end
histogram(out_of_bounds);
My distribution is a square, completely filled so I obviously have something wrong. Any ideas?
Image Analyst
Image Analyst el 9 de Oct. de 2017
Look at my code again. Do you see this:
for stepNumber=20
No. That's because your for loop will execute only once, and with a value of only 20, not every integer from 1 up to 20.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Event Functions en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by