Monte Carlo Method for Finding Area Under Curve: A MATLAB Program, Exercises of Stochastic Processes

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

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

Partial preview of the text

Download Monte Carlo Method for Finding Area Under Curve: A MATLAB Program and more Exercises Stochastic Processes in PDF only on Docsity!

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

docsity.com