Question: The Monte Carlo method is a statistical technique that uses random sampling to obtain numerical results. In this case, we will use it to estimate

The Monte Carlo method is a statistical technique that
uses random sampling to obtain numerical results. In this
case, we will use it to estimate by randomly generating
points in a square and determining how many of these
points fall within a quarter circle inscribed in the square.
Consider a square with sides of length 1, and a quarter
circle inscribed inside it as shown in the figure. All points
inside the square are made of two numbers x and y
between 0 and 1. If a set of x,y coordinates fall within the
circle then,
x2+y21
Eq 1
If a large number of points are generated inside the square, the ratio points that fall inside the circle to
the total number of points will approximately equal the ratio of the area of the quarter circle to the area
of the square. Therefore,
est=numberofpointsinsidecircletotalnumberofpoints4
error =|est-|
Write a MATLAB script named HW5p2_Task1_UCusername.m that will prompt the user to input a
tolerance (tol). Your script will use a loop to generate random points (x,y) inside the square, count
how many points fall inside the circle, and use Eq 2 to compute est. The code should continue
generating more points until the error drops below the inputted tolerance then output the values of est
to 6-digits and the total number of points generated.
Sample Test Case:
Enter tol: 1 e-8
pi_est =3.141593
n=96933
Notes:
MATLAB's in-built function rand (1) will generate a random
number between 0 and 1. Also, MATLAB's in-built function pi can
be used as the exact value of pi in Eq.3
This algorithm involves random numbers, therefore your output for n
will likely not match the sample test case. However, the value for
pi_est will equal the Test case value.
 The Monte Carlo method is a statistical technique that uses random

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!