Answered step by step
Verified Expert Solution
Link Copied!

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 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.
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases And Information Systems 1 International Baltic Conference Dbandis 2020 Tallinn Estonia June 19 2020 Proceedings

Authors: Tarmo Robal ,Hele-Mai Haav ,Jaan Penjam ,Raimundas Matulevicius

1st Edition

303057671X, 978-3030576714

Students also viewed these Databases questions

Question

Project management skills and/or experience desirable

Answered: 1 week ago