Page 1 of 1

import random import numpy as np import matplotlib.pyplot as plt from matplotlib.patches import Circle,Rectangle def dra

Posted: Wed Apr 27, 2022 3:11 pm
by answerhappygod
Import Random Import Numpy As Np Import Matplotlib Pyplot As Plt From Matplotlib Patches Import Circle Rectangle Def Dra 1
Import Random Import Numpy As Np Import Matplotlib Pyplot As Plt From Matplotlib Patches Import Circle Rectangle Def Dra 1 (113.68 KiB) Viewed 36 times
import random
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.patches import Circle,Rectangle
def draw_monte_carlo(Ntotal):
# YOUR CODE HERE
raise NotImplementedError()
plt.show()
draw_monte_carlo(200)
It is possible to use different methods to compute approximations to a. One way is to use a so-called Monte Carlo method which uses random numbers to estimate n. Consider the figure below, which shows the unit disc inscribed in the square (-1, 1] x [-1, 1]. Monte Carlo Approximation to n 1.0 10 0.5 0.5 0.0 0.0 -0.5 -0.5 -1.0 -1.0 -0.5 0.0 0.5 10 х -1.0 Pae -1.0 -0.5 0.0 0.5 10 Denote the areas of the square and disc A, and Ad, respectively. Then of course As = 4 and Ad = i So T Ad A 4 In the right-hand figure, a set of N total random points (uniformly distributed) have been plotted on the unit square. The points inside and outside the disc are coloured green and red, respectively. If the number of points inside the disc are denoted N disc , then the ratio of Ndisc to N total is an approximation of the ratio of areas above, namely N disc TT N disc >= 4 Ntotal 4 N total
(b) [30 marks] Illustrate the Monte Carlo method of approximating it by writing a function draw_monte_carlo which takes as input Ntotal and draws the figures included above with two subplots of the unit square. . the left subplot should contain a green quarter circle and the rest red; • the right subplot should contain a scatter plot of N total uniformly distributed random points; • the points inside the unit circle should be coloured green and points outside coloured red; • the unit circle itself should be coloured blue; • the plot should have relevant labels, centered title and tick marks. Write the function in the next cell and call the function in the following cell to render it. Hint: you might find the functions matplotlib. patches. Circle and matplotlib. patches. Rectangle useful.