Question

(PYTHON) Use Monte-Carlo method to calculate Pi and get as accurate as Math.pi to 0.000001. Reset...

(PYTHON) Use Monte-Carlo method to calculate Pi and get as accurate as Math.pi to 0.000001. Reset random number seed at the beginning of your program. Do multiple iterations, for example, n = 1000, 10000.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The answer to the question is given below.

The python code is given below.

import random as rand
import math as m
inside = 0
iterations = int(input("Enter the number of iterations you want to perform: "))
for i in range(0, iterations):
x2 = rand.random()**2
y2 = rand.random()**2
if m.sqrt(x2 + y2) < 1.0:
inside += 1

pi = (float(inside) / iterations) * 4
print(pi)



The screenshot of the running code is given below.




The screenshot of the input-output is given below.








If the answer helped please upvote it means a lot. For any query please comment.


Add a comment
Know the answer?
Add Answer to:
(PYTHON) Use Monte-Carlo method to calculate Pi and get as accurate as Math.pi to 0.000001. Reset...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a Java program that uses the Monte Carlo method to estimate the value of PI....

    Write a Java program that uses the Monte Carlo method to estimate the value of PI. This method uses the unit circle inscribed in a square with sides of length 2 and random numbers to perform the estimation. The estimation works as follows: • Two random numbers are generated during each iteration of a loop. • The random numbers are each in the range of -1 to 1. One random number is the x-coordinate and the other is the y-coordinate....

  • 1. Use the Monte Carlo method to calculate approximations to the integrals and then compare your ...

    1. Use the Monte Carlo method to calculate approximations to the integrals and then compare your results with the actual values: dac You may use (some of) the following random numbers: 0.498 0.824 0.862 0.826 0.403 0.145 0.677 0.972 0.708 0.274 0.923 0.382 0.389 0.248 0.362 0.184 0.237 0.950 0.319 0.524 0.593 0.818 0.987 0.393 0.459 0.802 0.178 0.347 0.083 0.440 1. Use the Monte Carlo method to calculate approximations to the integrals and then compare your results with the...

  • Use Monte Carlo Simulation to approximate pi by considering the percentage of points with coordinates (x,y)...

    Use Monte Carlo Simulation to approximate pi by considering the percentage of points with coordinates (x,y) generated randomly by choosing x and y both between 0 and 1, inside the unit quarted circle Q: X^2 + y^2 = 1, x>=0 y>=0 when the quarter circle is taken to be inside the square S: 0<=x<=1 and 0<=y<=1 Use approximation pi/4 = area Q / area S. Hint: Do the simulation 10000 times and then 100000. (meaning choose the value of x...

  • Use Monte Carlo Simulation to estimate I. Calculate I = integral^5_3 integral^2_1(2x + 3y^2)dxdy (a) Write...

    Use Monte Carlo Simulation to estimate I. Calculate I = integral^5_3 integral^2_1(2x + 3y^2)dxdy (a) Write a program to estimate I that takes as input n = number of replications.

  • Assignment Specifications We are going to use the Monte Carlo Method to determine the probability of...

    Assignment Specifications We are going to use the Monte Carlo Method to determine the probability of scoring outcomes of a single turn in a game called Pig. Your Task For this assignment you will simulate a given number of hold?at?N turns of a game called Pig, and report the estimated probabilities of the possible scoring outcomes. You are NOT implementing the game of Pig, only a single turn of this game. The value of N will be acquired via user...

  • Solve the following Monte-Carlo simulation problem both with Excel data tables and @Risk. Include all your...

    Solve the following Monte-Carlo simulation problem both with Excel data tables and @Risk. Include all your answers directly in your Excel file using text boxes or comment boxes. Please show formulas used within excel. NCAA Sweatshirt Problem An enterprising OU student is trying to decide how many sweatshirts to print for an upcoming NCAA Basketball Tournament game. The final four teams have emerged from the quarterfinal round, and there is a week left until the semi-finals, which are then followed...

  • Solve the following Monte-Carlo simulation problem both with Excel data tables and @Risk. Include all your...

    Solve the following Monte-Carlo simulation problem both with Excel data tables and @Risk. Include all your answers directly in your Excel file using text boxes or comment boxes. Please show formulas used within excel. NCAA Sweatshirt Problem An enterprising OU student is trying to decide how many sweatshirts to print for an upcoming NCAA Basketball Tournament game. The final four teams have emerged from the quarterfinal round, and there is a week left until the semi-finals, which are then followed...

  • use PYTHON Assignment 4 O Let's make random IDs. Get the number of IDs from the...

    use PYTHON Assignment 4 O Let's make random IDs. Get the number of IDs from the user to make from the keyboard. Then print the IDs. O Note that the IDs should be unique. Moreover, one ID is 11-length alphabet characters including digits (i.e., A-Z, A-Z, 0-9). Template Code Example import string import random num_of_ids = int(input("Enter the number of IDs: ")) # this list contains a-z, A-Z, and digits alphabet_digit_list = string.ascii_letters + string.digits Enter the number of IDs:...

  • This program will use the Random class to generate random temperatures (integers) between some minimum (inclusive)...

    This program will use the Random class to generate random temperatures (integers) between some minimum (inclusive) and some maximum (inclusive) values. You will need to calculate the minimum and maximum given a starting temperature integer and a possible change in temperature integer. (1) Copy the following method stub into your Temperature Predictor class and complete it according to the specifications described in the header comments. * Generates a random temperature (int) within a range when given the current temperature *...

  • Python use dequeue and enqueue methods, alter the dequeue method and the enqueue method. remove items...

    Python use dequeue and enqueue methods, alter the dequeue method and the enqueue method. remove items from the first element of the list (the front of the queue) and return this value and you need to add items to the last element of the list (the rear of the queue). 4. (20 points) Programming Exercise 5 from Chapter 3 of your textbook. Name the class Queuex, and use the other method names given in Chapter 3.11 in your digital textbook....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT