
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
This matlab document outlines a program designed to estimate the area of a quarter circular disk using the monte carlo method. The purpose of the program, the range of x and y values, and the steps to generate a movie of the monte carlo simulation with increasing number of dots. It also includes the matlab code for the program.
Typology: Exercises
1 / 1
This page cannot be seen from the preview
Don't miss anything!

% Program name: random_1.m % Program to find area under curve by Monte Carlo method % Consider a quarter of a cirular disk in range of % 0 < x < 1 and 0 < y < 1. We are interested % to find its area using Monte Carlod method. % This generates a movie of 20 frames with % increasing number of dots thrown at the region. N = 5; hit = 0; mis = 0; xs = 1; ys = 0; rand('state', 0) % this sets the generator to an initial state nframes = 200; % number of frames for movie delta = 1.0/N for i = 1: nframes i for j = 1: N xs = xs - delta; ys = abs(sqrt(1- (xs*xs))); plot(xs, ys, '--') axis([0 1 0 1]) hold on end for k = 1: N x = rand; y = rand; plot(x, y, 'r:.') hold on end m(k)= getframe; end movie(m, 100) % play movie 30 times.