Question for MATLAB and Monte Carlo Method Hello I have a qu
Question for MATLAB and Monte Carlo Method
Hello, I have a question about Monte Carlo Method
Can you solve this with detailed descriptions as soon as possible?
And If question is like that, How to solve this question with MATLAB code and function?
Solution
Below si the smple for the Unit Cube Volume:
Shoots = 100000;// Basic valuedeclaration
hits = 0 ; // total number of the hots
for i =1 : shoots // it is the sample whole unit cube
x = rand ();
y = rand ();
z = rand ();
// so are we are inside the sphere? , come lets check is
r = x^2 + y^2 +z^2;
if (r <1)
hits =hits +1 ; % we are inside
end;
end
ratio = hits / shoots; % This is the ratio statistically - volume ( Quarter sphere) / volume(cube)
mypi = ration * 3;
for example :
Sample the unti cube\'s three outer faces ( origin will be ereached , when it is three)
normalize() this point could to bring it onto the desired sphere surface.
Then the triangulate that mesh.
Firstly the coordinated are X and Y , will range from -1 to 1.
n= 10000;
x=(1-(-1))*rand(n,1)+(-1);
y=(1-(-1))*rand(n,1)+-1);
now one of these points (x,y) is inside the circle if the distance from the origin to that point is less than or equal to 1. The distance from the origin to the point is r= square root x2 =y2 , so calculated that for evfery point:
r=sqrt(x.^2+y.^2); %// here the element wise dot exponentiation
To find the points that lie inside the circle:
couintInsideCircle=sum(r<=1)%//here the number of points less than one unit from the origin .
Tocalculate the area of the circle we ned to know the proportion of points that lie in the circle:
proportionInsideCircle=countInsideCircle/n
then we ned to multiply by the area of the surrounding square
areaofCircle = 4*proportionInsideCircle

