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

Determining pi Experimentally: Recall that pi is the ratio of a circle\'s circum

ID: 3785698 • Letter: D

Question

Determining pi Experimentally: Recall that pi is the ratio of a circle's circumference to its diameter and that we can calculate the area of a circle with the formula A = pi r^2 Below is a circle enscribed within the unit Square. What is the ratio of the areas of the enscribed circle to that of the unit square If we pick a random point within the unit square what is the probability that the point will also lie within the circle? If we repeat this experiment an arbitrarily large number of times the ratio of the number of points which lie within the circle to the number of points within the unit square (all of them)will approach pi/4 Using the language structures we have discussed write a program that will do the above experiment an arbitary (determined at run-time)number of times and report back the approximate value of pi

Explanation / Answer

A.

Radius of circle = r
diameter = 2r = side of square
area of square = side*side = 2r*2r = 4r2
area of circle = r2

Ratio = r2/4r2 = /4

B.

Since
Probability = DesiredEvent/Sample space

in this case Desired Event is point inside circle ie it lies within area of circle.

Sample Space is the whole space in which our point can possibly lie ie the square. or the area of square.

Hence Probability = Area of Circle/Area of Square
We have already calcluated this above ie the Ratio  r2/4r2 = /4

C.

Code to find value of pi in python :

'''
This Program picks points inside the square at random and checks to see if point lies inside or outside the circle
Suppose x and y are coordinates and radius is R then we know point is inside the circle if x2 + y2 < R2.

'''

import random
import math

count_inside = 0
x = raw_input("Enter how many time you want to run the experiment: Please enter Integers otherwise it will throw a Valueerror -- ")
for count in range(0, int(x)):
d = math.hypot(random.random(), random.random()) #this function randomly creates a point and measure the euclidean distance from origin
if d < 1: count_inside += 1 #checks whether point is inside or outside the circle
count += 1
print 4.0 * count_inside / count #returns value of pi

#well .. this method of finding the value of pi is known as monte carlo method

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