Monte Carlo Method for Calculating the Area of a Circle, Exercises of Stochastic Processes

How to use the monte carlo method to estimate the area of a circle with a radius of 1, located in the x-y plane with coordinates between -1 and 1. Matlab code to generate a movie illustrating the method's implementation.

Typology: Exercises

2011/2012

Uploaded on 08/12/2012

ranganath
ranganath 🇮🇳

4.7

(3)

37 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
% area under curve by Monte Carlo method
% Consider a cirular disk in range of
% -1 < x < 1 and -1 < y < 1. We are interested
% to find its area using Monte Carlod method.
N = 10 ; hit = 0; mis = 0;
rand('state', 0) % this sets an initial state
nframes = 400 ; % number of frames for movie
for j = 1: nframes
j
axis([-1.2 1.2 -1.2 1.2])
hold on
for k = 1: N
x = 1.0 - 2.*rand;
y = 1.0 - 2.*rand;
if((x*x + y*y)<= 1 )
hit = hit + 1;
plot(x, y, 'r:.')
hold on
else
mis = mis + 1;
plot(x, y, '.')
end
end
m(k)= getframe;
end
movie(m, 100) % play movie 30 times.
docsity.com

Partial preview of the text

Download Monte Carlo Method for Calculating the Area of a Circle and more Exercises Stochastic Processes in PDF only on Docsity!

% area under curve by Monte Carlo method % Consider a cirular disk in range of % -1 < x < 1 and -1 < y < 1. We are interested % to find its area using Monte Carlod method. N = 10 ; hit = 0; mis = 0; rand('state', 0) % this sets an initial state nframes = 400 ; % number of frames for movie for j = 1: nframes j axis([-1.2 1.2 -1.2 1.2]) hold on for k = 1: N x = 1.0 - 2.rand; y = 1.0 - 2.rand; if((xx + yy)<= 1 ) hit = hit + 1; plot(x, y, 'r:.') hold on else mis = mis + 1; plot(x, y, '.') end end m(k)= getframe; end movie(m, 100) % play movie 30 times.

docsity.com