?? onion.m
字號(hào):
%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)
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -