% MCAS10gm01Q9b.m, a vectorized versioin of MCAS10gm10Q9.m
% MCAS Question 9
% Solves question 9, 10th grade math, 2001 MCAS
% Written by E Gallagher 9/5/01
% Eugene.Gallagher@umb.edu
% Last revised 1/18/11
clf % clears the previous graph
hold on; % no graphs will be erased;
theta = 0:pi/50:2*pi;
% first draw a circle of radius 3, centered at 0
r=3;
x = r * cos(theta) + 0;
y = r * sin(theta) + 0;
plot(x, y);axis('square');
% Now draw a circle of radius 1, centered at 0
r=1;
x = r * cos(theta) + 0;
y = r * sin(theta) + 0;
plot(x, y);
% Now fill this circle with yellow;
h =fill(x,y,'y');
hold on
figure(gcf)
% Modify dart throwing code from Nahin's pisim.m
% Vectorized
rand('state',100*sum(clock))  %set new seed for generator;
tic
darts=1000;
X=rand(darts,2)*6-3;
r=sqrt(sum((X.^2)'));
i=find(r<3);
trials=length(i);
success=length(r(i)<1);
plot(X(i,1),X(i,2),'.r','MarkerSize',4);figure(gcf)
p_est=success/trials
1/9-p_est
toc
