Question

In: Computer Science

Python program to simulate estimate the probability that a random chord on a unit-circle (radius one),...

Python program to simulate estimate the probability that a random chord on a unit-circle (radius one), exceeds the radius of the circle? Repeat the experiment of generating random chords 1,000 times. Record the estimate of the probability that the chord length exceeds the radius

Please use comments to help explain

Solutions

Expert Solution

Code:-

import random # to generate random angles using randrange function
import math # to access the sin,cos and radians function.

def ranLengthChord():
""" here the function takes no input & returns
a chord of randome length inside a unit circle"""

#calculate the random angles.

A1Deg = random.randrange(0,361)
A1Rad = math.radians(A1Deg)
A2Deg = random.randrange(0,361)
A2Rad = math.radians(A2Deg)

#calculate the coordinates of the end points of the chord.
pointx1=math.cos(A1Rad)
pointy1=math.sin(A1Rad)
pointx2=math.cos(A2Rad)
pointy2=math.sin(A2Rad)

#calculate the distance between the points using distance formula
d=((pointx1-pointx2)**2+(pointy1-pointy2)**2)
dist = math.sqrt(d)

# return the length of the chord
return dist
  


exceeded=0 # storing the exceeds where chord length is greater than unity

"""loop to call the randLengthChord func. 10000 times
and checks if the length is greater than unity """
for i in range(10000):
dist1 = ranLengthChord()
if dist1>1:
exceeded+=1
  
#output
print("Probability that chord exceeds the radius:",exceeded/10000)

Output:-

Screenshot of Code:-

if u like my answer then please give a thumbs up..!!


Related Solutions

Python: I am making a program that prints a circle of random size, random location, with...
Python: I am making a program that prints a circle of random size, random location, with user_inputed (using entry) color, when 'DRAW' button is clicked. I am stuck on passing variables on the while loop. Please Help from graphics import* import sys import random from time import sleep def main(): win = GraphWin ('What Color', 500, 600) win.setCoords(0, 0, 500, 600) DB = Rectangle(Point(350, 580), Point(400, 560)) DB.setFill('light Green') DB.draw(win) QB = Rectangle(Point(430, 580), Point(480, 560)) QB.setFill('red') QB.draw(win) DB_t =...
A circle of radius r has area A = πr2. If a random circle has a...
A circle of radius r has area A = πr2. If a random circle has a radius that is uniformly distributed on the interval (0, 1), what are the mean and variance of the area of the circle? Change the distribution of the radius to an exponential distribution with paramter β = 2. Also find the probability that the area of the circle exceeds 3, if it is known that the area exceeds 2.
1) A circle of radius r has area A = π r2. If a random circle...
1) A circle of radius r has area A = π r2. If a random circle has a radius that is evenly distributed in the interval (0, 1), what are the mean and variance of the area of ​​the circle? choose the correct answer A) 1/3 and 1/12 B) Pi/3 and 1/12 C) Pi/3 and 1/5 D) Pi/3 and (4/45)*Pi^2
Python program to simulate breaking a unit-length pencil into two places. Repeat the experiment 100,000 times...
Python program to simulate breaking a unit-length pencil into two places. Repeat the experiment 100,000 times and determine the average size of the smallest, middle-size, and the largest pieces. Record the estimate of the average sizes in your program Please use comments to better explain what is happening in the code
Circle Object Python program Compute the area and perimeter of a circle using Python classes. take...
Circle Object Python program Compute the area and perimeter of a circle using Python classes. take the radius from the user and find the area and perimeter of a circle please use comments to explain so i better understand
Let A0.A1,A2,A3,A4 devide a unit circle (circle of radius one) into five equal parts. Prove that...
Let A0.A1,A2,A3,A4 devide a unit circle (circle of radius one) into five equal parts. Prove that the chords A0 A1, A0 A2 satisfy: (A0 A1 * A0 A2)^2 = 5.
Write a C++ program that prompts the user for the radius of a circle and then...
Write a C++ program that prompts the user for the radius of a circle and then calls inline function circleArea to calculate the area of that circle. It should do it repeatedly until the user enters -1. Use the constant value 3.14159 for π Sample: Enter the radius of your circle (-1 to end): 1 Area of circle with radius 1 is 3.14159 Enter the radius of your circle (-1 to end): 2 Area of circle with radius 2 is...
(Display a Circle and Its Attributes) Write a program that displays a circle of random size...
(Display a Circle and Its Attributes) Write a program that displays a circle of random size and calculates and displays the area, radius, diameter and circumference. Use the following equations: diameter = 2 × radius, area = π × radius2, circumference = 2 × π × radius. Use the constant Math.PI for pi (π). All drawing should be done on a subclass of JPanel, and the results of the calculations should be displayed in a read-only JTextArea.
I. Simulate a binomial random variable. Consider a class with 60 students, and the probability that...
I. Simulate a binomial random variable. Consider a class with 60 students, and the probability that a student does not turn in a homework is 0.10 (a “success”). Assume all students are independent of all other students, and the probability does not change.(a) Use sample to simulate drawing 60 students who either do, or do not, turn in their homework, and then find the total (out of 60) who did not turn in their homework. You should return one number,X=...
Write a program in Python to simulate a Craps game: 1. When you bet on the...
Write a program in Python to simulate a Craps game: 1. When you bet on the Pass Line, you win (double your money) if the FIRST roll (a pair of dice) is a 7 or 11, you lose if it is ”craps” (2, 3, or 12). Otherwise, if it is x ∈ {4, 5, 6, 8, 9, 10}, then your point x is established, and you win when that number is rolled again before ’7’ comes up. The game is...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT