xplusy.m

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

M
25
字号
%sumhisto.m/created by PJNahin for "Duelling Idiots"(2/25/99)
%This m-file produces 5,000 values of the sum of N random
%variables, each variable uniform from 0 to 1, and independent.
%It then plots a histogram of the sums using 100 bins.
%
%
rand('state',100*sum(clock))
clear z
N=input('How many random variables in a sum? ');
mean=N/2;
sd=sqrt(N/12);
for sumn=1:5000
   s=0;
   for i=1:N
      s=s+rand;
   end
   s=(s-mean)/sd;
   z(sumn)=s;
end
hist(z,100)
xlabel('sum')
ylabel('number of values per bin')
title('Histogram of the Sum of N Random Variables')
figure(1)

⌨️ 快捷键说明

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