Page 1 of 1

Monte_pi.m file underneath Homework Assignment: Formula for part B, P=(2*l)/(pi*d) Part (a): write a program using the M

Posted: Mon May 02, 2022 12:47 pm
by answerhappygod
Monte_pi.m file underneath
Monte Pi M File Underneath Homework Assignment Formula For Part B P 2 L Pi D Part A Write A Program Using The M 1
Monte Pi M File Underneath Homework Assignment Formula For Part B P 2 L Pi D Part A Write A Program Using The M 1 (124.58 KiB) Viewed 32 times
Homework Assignment:
Formula for part B, P=(2*l)/(pi*d)
Part (a): write a program using the Monte Carlo algorithm (you
can start from the Monte_pi.m file we did in class) to estimate pi
for the Buffon Needle experiment, for N trials of N = 10, N = 100,
N = 1000, and N = 10000. (20 points). Turn in the program and
values from your trials.
Part (b): perform the experiment by dropping N = 1000 sticks of
length equal to the width of lines spaced evenly to get an
experimental value for pi from the formula developed in class. (20
points). Report your data from the experiment and your calculation
for pi.
***************** ********** ********* ***** ******* % PI value by Monte-Carlo Method*********** % By Mahesha MG ******** clc; n=input('Number of points: '); x=rand(n,1); y=rand(n, 1); % figure('color', 'white'); hold all axis square; x1=x-0.5; y1=y-0.5; %cirle has centre at (0.5,0.5) r=x1.^2+y1.^2; m=0; %Number of points inside circle for i=1:n if r(i)<=0.25 m=m+1; % plot(x(i),y(i), 'b.'); else % plot(x(i),y(i), 'r.'); end end m/(0.25*n)