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

5. If necessary, the number = 3.141593 can be estimated by a simple simulation e

ID: 2923594 • Letter: 5

Question

5. If necessary, the number = 3.141593 can be estimated by a simple simulation experiment. The area of a square of unit sides equals l. A circle of radius r = 1 /2 can be embedded in this square. The (a) Create an n×2 matrix, such that each row contains the coordinates of a point uniformly distributed b) Count the number of such points contained in the embedded circle described above. Call this area of a circle is . Write an R function which does the following. number m (c) Use the numbers m and n to estimate . You can set n = 10000.

Explanation / Answer

n=10000
#a) defining two random variable fixing center as zero

x=runif(n,-.5,.5)
y=runif(n,-.5,.5)

data.matrix=matrix(rep(0,n*2),n,2)
data.matrix[,1]=x
data.matrix[,2]=y
m=0
# b)couning the number of points within radius 0.5 of the cercle inside
for(i in 1:n)
{
if(x[i]^2+y[i]^2<=.25)
{m=m+1}
}

m
area=m/n
area
# c) estimate ofthe value of pi
estimate.pi=area*4
estimate.pi

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