Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Figure 1: The ratio of points inside the circle to the total number of points ap

ID: 3623514 • Letter: F

Question

Figure 1: The ratio of points inside the circle to the total number of points approximates Pie/4.

6. (14 marks) Write Matlab code corresponding with Algorithm 2 from Homework 1. Include

sample output which estimates Pie(3.14) with 10 random points, 100 random points, 1000 random

points, and 10000 random points.

We want a program that approximates Pie(3.14) using the relationship between the area of a circle

with radius 1 and the area of a square with sides of length 2.

We can approximate Pie (3.14) by generating many random points (xi; yi) within a square with sides

of length 2, and counting the number of generated points which fall within an inscribed

circle of radius 1. The number of points that fall within the inscribed circle divided by

the total number of points generated gives a good approximation for Pie/4 As the number of

points used increases so does the quality of the approximation. Note that a point satisfying

x2 + y2 <= 1 falls within the circle pictured in Figure 1.

Explanation / Answer

% give Nrand as 10 100 1000 10000 points and run following program Nrand = input('How Many Random Numbers '); NInside = 0; for nloops=1:Nrand Xrand = rand; % Generate Random XY Point Yrand = rand; Rrand = Xrand^2 + Yrand^2; % Find its distance from origin if (Rrand
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote