How would I start this problem?

1 回表示 (過去 30 日間)
Gaëtan Poirier
Gaëtan Poirier 2017 年 10 月 8 日
コメント済み: Image Analyst 2017 年 10 月 9 日
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.)

採用された回答

Image Analyst
Image Analyst 2017 年 10 月 8 日
See my attached collection of random walk programs/demos I've written. Adapt as needed.
  17 件のコメント
Gaëtan Poirier
Gaëtan Poirier 2017 年 10 月 9 日
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 2017 年 10 月 9 日
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.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by