clc;clear all;
p = 10^(-6);M = 10000;dt = 0.001;T = 5; %仿真参数
N = T/dt; %仿真的时间段
randCount = 20; %试验次数
s = [];
for round = 1:randCount
x = zeros(1,N); %初始化每部电话的呼叫次数
x = ( rand(M,N) < p); %模拟每部电话在每个时间段是否呼叫
x = sum(x); %对所有电话的呼叫求和
for jj = 1:N
z(jj) = sum(x(1:jj)); %统计第jj个时间段之前的总呼叫次数
end
s = [s,z(jj)];
end
L = 10*ones(1,20);
plot((1:randCount),L);
hold on;
plot((1:randCount),s/5,'--o','MarkerSize',10,'MarkerFaceColor','m','MarkerEdgeColor','b','LineWidth',1.5)
xlabel('试验次数');ylabel('平均呼叫次数(次/秒)');
axis([1,20,4,16])
legend('理论平均值2','试验平均次数')
grid on;