saiyasaibing 发表于 2010-11-3 21:22 
3# gzjb
十分感谢您的帮助,我的邮箱wzyznn@gmail.com,如果您能发一段程序让我参考一下那就更好了!
*****************************************
The simplest MC. Hope you can get idea.
Suggestion: Use the right tool to do the right thing.
Don't try to know everything b/c the life is limited
******************************************
%MACRO vol_ic(n,iprt);
*iprt: #points to calculate integral once(total: int(n/iprt) times) ;
*n:total #points randomly generated;
Title "Ice Cream Cone Vol: above z^2=x^2+y^2 inside sphere with center (0,0,1) and radius 1";
option nodate nonotes;
%let seed =1234;
data icvol;
call streaminit(&seed);
keep vol;
m=0;pi=constant('Pi'); vol=0;
do i=1 to &n;
x=2*rand('uniform')-1; y=2*rand('uniform')-1; z=2*rand('uniform');
if x**2+y**2 le z**2 and x**2+y**2 le z*(2-z) then m=m+1;
if mod(i,&iprt)=0 then
do;
vol=8.0*m/i;
output;
end;
end;
run;
proc print data=icvol; run;
%MEND vol_ic;
%vol_ic(700000,100000)