📄 onion.m
字号:
%onion.m/created by PJNahin for "Duelling Idiots"(1/5/99)
%This m-file uniformly slices the unit interval, from left to right,
%ten times, and forms the sum of the widths of the slices. It does
%this 5000 times and then plots the distribution function of the sum.
%
%
rand('state',100*sum(clock)); %new seed for generator;
rsum=zeros(1,5000);
for cutting=1:5000
total_thickness=0;
L=1;
for dice=1:10
slice=L*rand;
total_thickness=total_thickness+slice;
L=slice;
end
index=round(100*total_thickness+.5); %adding the '.5' prevents
rsum(index)=rsum(index)+1; %getting a zero index;
end
x=.01:.01:5;
dist(1)=rsum(1);
for index=2:500
dist(index)=dist(index-1)+rsum(index);
end
plot(x,dist/5000)
grid
xlabel('thickness')
ylabel('probability')
title('Fig.5.2-Distribution of Total Thickness from 5,000 Cuttings')
figure(1)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -