flysquare.m

来自「一些常被用于教学或者参考的概率论的实例的源代码」· M 代码 · 共 19 行

M
19
字号
%flysquare.m/created by PJNahin for "Duelling Idiots"(1/19/99)
%This m-file simulates the distance-squared between 100,000
%pairs of flies, landing at random in the unit square.
%
%
rand('state',100*sum(clock))
summation=0;
for fly=1:100000
   x1=rand;
   y1=rand;
   x2=rand;
   y2=rand;
   distance2=(x1-x2)^2+(y1-y2)^2;
   if distance2>=1
      summation=summation+1;
   end
end
summation/100000

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?