step1 determine a rectangle or square which bounds the integral region
step2. Generate the random number pairs (points in 2D)
step3. Calculate the probability P of points located in the integral region
step4. integral=P*area of rectangle or square
For 3 dimension to n>3 dimension , same idea.
MCMC works very well. Easy to program in SAS or other language . I did integral from 1D to 3D many years ago.
I will send you programs if I have time and can find it.
step1 determine a rectangle or square which bounds the integral region
step2. Generate the random number pairs (points in 2D)
step3. Calculate the probability P of points located in the integral region
step4. integral=P*area of rectangle or square
For 3 dimension to n>3 dimension , same idea.
MCMC works very well. Easy to program in SAS or other language . I did integral from 1D to 3D many years ago.
I will send you programs if I have time and can find it.
MC method is the last solution if there is no way to integral. I am not sure how SAS calculates the integral. It certianly is a lot of faster than MC.
Here is an example of integal of 4xy on x=[0,1] and y=[0,x];
step1 determine a rectangle or square which bounds the integral region
step2. Generate the random number pairs (points in 2D)
step3. Calculate the probability P of points located in the integral region
step4. integral=P*area of rectangle or square
For 3 dimension to n>3 dimension , same idea.
MCMC works very well. Easy to program in SAS or other language . I did integral from 1D to 3D many years ago.
I will send you program if I have time and can find it.
MC method is the last solution if there is no way to integral. I am not sure how SAS calculates the integral. It certianly is a lot of faster than MC.
Here is an example of integal of 4xy on x=[0,1] and y=[0,x];
*****************************************
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;
全部评论 15