Question

In: Math

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

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

Solutions

Expert Solution

A)

The Python code for drawing the diagram and calculating the value of PI is given below. (500 random points are generated).

from numpy import random
import math
import matplotlib.pyplot as plt

x =-0.5+random.random_sample(500)
y = -0.5+random.random_sample(500)
x1 = x[x*x+y*y<0.25]
y1 = y[x*x+y*y<0.25]

circle = plt.Circle((0, 0),fill=None, radius=0.5)
points = [[-0.5, -0.5], [0.5, -0.5], [0.5, 0.5], [-0.5, 0.5],[-0.5,-0.5]]
line = plt.Polygon(points, fill=None, edgecolor='r')
plt.gca().add_patch(circle)
plt.gca().add_patch(line)
plt.scatter(x1,y1)
plt.axis('scaled')
pi = 4*len(x1)/500
plt.title("n=500, $\pi$=%0.4f" % pi)
plt.show()

The diagram given below.

The value of PI is .

B) For random points, . Very close to the correct .

Python Code below:

from numpy import random
import math
import matplotlib.pyplot as plt
N = 100000
x =-0.5+random.random_sample(N)
y = -0.5+random.random_sample(N)
x1 = x[x*x+y*y<0.25]
y1 = y[x*x+y*y<0.25]
pi = 4*len(x1)/N
print('PI =', pi)

C) For 5000 trials we reach close to the actual value of PI. (Change 500 in the code to 5000 everywhere)


Related Solutions

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...
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 (B) Without drawing the diagram, calculate the value...
Describe the steps needed to perform the Monte Carlo Simulation.
Describe the steps needed to perform the Monte Carlo Simulation.
What is Monte Carlo simulation? What principles underlie its use, and what steps are followed in...
What is Monte Carlo simulation? What principles underlie its use, and what steps are followed in applying it? Be detailed and give an example.
Why would you want to use the Monte Carlo Simulation to explore a decision option rather...
Why would you want to use the Monte Carlo Simulation to explore a decision option rather than solve the branch analytically?
preform a Monte Carlo simulation in R to generate the probability distribution of the sum of...
preform a Monte Carlo simulation in R to generate the probability distribution of the sum of two die (for example 1st die is 2 and second die is 3 the random variable is 2+3=5). The R-script should print out (display in R-studio) or have saved files for the following well labeled results: 1. Histrogram or barchart of probability distribution 2. Mean of probability distribution 3. Standard deviation of probability distribution
Please provide an example of a Monte Carlo simulation model (and explain). Your simulation example should...
Please provide an example of a Monte Carlo simulation model (and explain). Your simulation example should be able to: Tackle a wide variety of problems using simulation Understand the seven steps of conducting a simulation Explain the advantages and disadvantages of simulation Develop random number intervals and use them to generate outcomes Understand alternative computer simulation packages available Explain the different type of simulations Explain the basic concept of simulation
Discuss about Monte Carlo simulation, with a focus on its steps. (100% rating)
Discuss about Monte Carlo simulation, with a focus on its steps. (100% rating)
Running a Monte Carlo simulation to calculate the probability that the daily return from S&P will...
Running a Monte Carlo simulation to calculate the probability that the daily return from S&P will be > 5%. We will assume that the historical S&P daily return follows a normal distribution with an average daily return of 0.03 (%) and a standard deviation of 0.97 (%). To begin we will generate 100 random samples from the normal distribution. For the generated samples we will calculate the mean, standard deviation, and probability of occurrence where the simulation result is greater...
After applying Monte Carlo Simulation for a potential investment opportunity, you observed that the mean of...
After applying Monte Carlo Simulation for a potential investment opportunity, you observed that the mean of the NPV distribution generated from the 10,000 iterations of this investment opportunity was $320 million and the Value at Risk (VAR) was $-550 million. Present a balanced recommendation based on these simulation results regarding whether or not the firm should make this investment.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT