Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 and a quarter
circle inscribed inside it as shown in the figure. All points
inside the square are made of two numbers and
between and If a set of coordinates fall within the
circle then,
Eq
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,
error
Write a MATLAB script named HWpTaskUCusername.m that will prompt the user to input a
tolerance tol Your script will use a loop to generate random points inside the square, count
how many points fall inside the circle, and use Eq to compute The code should continue
generating more points until the error drops below the inputted tolerance then output the values of
to digits and the total number of points generated.
Sample Test Case:
Enter tol: e
piest
Notes:
MATLAB's inbuilt function rand will generate a random
number between and Also, MATLAB's inbuilt function pi can
be used as the exact value of pi in Eq
This algorithm involves random numbers, therefore your output for
will likely not match the sample test case. However, the value for
piest will equal the Test case value.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started