In this problem you will use a series of identical experiments, simulated in MATLAB, to estimate the value of pi. A dart board with diameter of 1/2 is centered within a square-board with sides of unity length. A series of N identical experiments are performed. The procedure consists of throwing a dart at the square-board, and the observation is determining if the dart falls on or off the dart board. The experiment model requires that the dart always lands within the square-board, and that the dart is equally likely to hit any specific point within the square-board. Let Ni denote the number of times the dart lands within the dart board for N experiments. 1. Estimate pi as a function of N and Ni, and denote your estimate as theta. 2. The MATLAB command x = rand( [N,1]) generates a column vector of N numbers, where each number lies in the interval [0, 1], and each value in this range is equally likely to occur. Using this function, find and plot theta as a function of N for 2 <= N <= 106.
This happens to be a problem for my 400 level probability class. I'm not used to using MATLAB and i've spent a lot of time just staring at this thing tryin to figure out what to do. Right about now, i'll take anything that remotely looks like a plot described by this problem. Any help would be fantastic right about now.
The dart has an equal probability of landing anyplace on the square board. You know when the dart lands on the circle. The probability of the dart landing on the circle is proportional to its area.
Number of darts on circle / total thrown = Area of circle = pi * r ^2. Solve for pi.
This problem is solved using monte carlo simulations. I guess you probably wanted this answer a while back, but since I only joined today, better late than never. ;-)
========== Part 1. ==========
Area of circle = pi * r^2 Area of square = (2r)^2
Area circle / Area square = pi / 4
theta = Prob(dart hits circle) is directly proportional to (Area circle / Area square)
theta = num darts in circle / num darts in square = Ni / N ~= (approximates) pi / 4
clear all
close all
clc
% run Monte Carlo sim several times, for N darts
for N = 1 : 106
% generate random x,y coords simulating dart hitting square board at a
% random location
x = rand([N,1]);
y = rand([N,1]);
% reset counter for num darts hitting dartboard
in_circle = 0;
% work out whether each simulated dart hit the dartboard
for Ni = 1 : N
% test if x,y coordinates are within circle w radius 0.5
% (subtract 0.5 from each coord to compare against circle
% centered on origin)
if sqrt((x(Ni)-0.5).^2 + (y(Ni)-0.5).^2) <= 0.5
in_circle = in_circle + 1;
end
end
% calculate theta, our estimate for Pi
theta(N) = 4 * in_circle / N;
% write out theta values - should approach 3.14...
disp(['N = ' num2str(N) ', in_circle = ' num2str(in_circle) ...
', theta = ' num2str(theta(N)) ])
end
% plot thesta values
figure;plot(theta)