統計學一問(有無人可以解答我)用MATLAB

2012-11-08 6:49 am
Q1.If a frog jumps forward with jump sizes that are uniformly distributed from 0 to 1, how many jumps on average does it take for the frog to cross a river of width 1?

Please run the simulation in Matlab to solve this problem. If you can also solve this problem analytically, I will give you bonus.

回答 (2)

2012-11-09 8:13 pm
✔ 最佳答案
e.g. Takes 1000000 trials as sample.

Since Yahoo answer sucks in displaying the spaces, note that the character '-' is used to represent the space as for indentation.

Code:

clear; clc
expt = zeros(1,1e6);
for I = 1:1e6
----pos = 0;
----jump = 0;
----while pos < 1
--------pos = pos + rand;
--------jump = jump + 1;
----end
----expt(I) = jump;
end
sum(expt)/1e6

Output:
2.7183 +- ~0.001
The numerical simulation with 1 million trials still has quite a large error sd, but by running the code repeatedly you ca get it converges around 2.183
(MATLAB output in 4 dp, which is, by analaytical method, e)
2012-11-09 4:35 am
Never use Matlab before. The answer should be e.


收錄日期: 2021-04-23 23:25:57
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20121107000051KK00589

檢視 Wayback Machine 備份