📄 pisim.m
字号:
%pisim.m/created by PJNahin for "Duelling Idiots"(10/22/98)
%This m-file estimates pi by randomly tossing darts at the
%unit square and counting how many land inside a quarter-
%circle with unit radius contained in the square.
%
%
rand('state',100*sum(clock)) %set new seed for generator;
darts=0; %initialize number of darts
%inside quarter-circle region;
for i=1:10000;
x=rand; %toss a
y=rand; %dart;
r=x*x+y*y; %compute distance squared from origin to dart;
if r<1 %is dart inside quarter-circle region?
darts=darts+1; %yes
end
end
pi_estimate=4*darts/10000
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -