✔ 最佳答案
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)