Question

This problem is also a Monte Carlo simulation, but this time in the continuous domain: must...

This problem is also a Monte Carlo simulation, but this time in the continuous domain: must use the following fact: a circle inscribed in a unit square

has as radius of 0.5 and an area of ?∗(0.52)=?4.π∗(0.52)=π4.

Therefore, if you generate num_trials random points in the unit square, and count how many land inside the circle, you can calculate an approximation of ?

For this problem, you must create code in python

(A) Draw the diagram of the unit square with inscribed circle and 500 random points, and calculate the value of ?

(B) Without drawing the diagram, calculate the value of ? you would get from 105 trials.

(C) After completing (B), try to get a more accurate value for ? by increasing the number of trials.The results will depend on your machine

Homework Answers

Answer #1

Pi value changes as the INTERVAL is changed

import random
INTERVAL=10000
circle_points = 0
square_points = 0

for i in range(0,INTERVAL * INTERVAL):
rand_x = (random.randint(0,1000) % (INTERVAL + 1)) / INTERVAL
rand_y = (random.randint(0,1000) % (INTERVAL + 1)) / INTERVAL
origin_dist = rand_x * rand_x + rand_y * rand_y
if (origin_dist <= 1):
circle_points=circle_points+1
square_points=square_points+1
pi = (4 * circle_points) / square_points
print("Final Estimation of Pi = " + pi)

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT