It seems that the Math department at a rival university has

It seems that the Math department at a rival university has once again dropped the ball, and forgotten the value of n. You are to write a script which consumes a number that specifies the required accuracy and then and approximates the value of n to that accuracy. You are going to use the following algorithm based on geometric probability: Think about a quarter circle inside of a unit square (the quarter circle has area pi/4). You pick a random point inside the square. If it is in the quarter circle, you get a \"hit\" and if not, you get a \"miss\". The approximate area of the quarter circle will be given by the number of hits divided by the number of points you chose. Your script should repeat the process of counting hits and misses until at least 10,000 tries have been made, and the successive estimates of n are within the prescribed accuracy. It should produce the estimated value of pi.

Solution

%%this script will give value of pie
N = 10000; %number of tries used in the problem
hit = 0; % intialize win
for i = 1:N
point = rand(1, 2); %generate random number
x = point(1);
y = point(2);
distance = x*x + y*y; %calculate distance
if distance <= 1
hit = hit + 1; %if the target is hit
end
end
Pi = 4 * hit / N ;
%anser is coming 3.1344

 It seems that the Math department at a rival university has once again dropped the ball, and forgotten the value of n. You are to write a script which consumes

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site