
Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
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
1 / 1
This page cannot be seen from the preview
Don't miss anything!

% 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.