write a sage program for:

3. (a) If a and b are randomly chosen from the interval |-1,1], what is the probability S1? Draw a picture and answer that the point (a, b) lies inside the disk 2 + this using basic geometry. (b) Write a Sage program that approximates by actually performing the above ex- periment. Your code should do the following: 1. Initialize a graphics object, and start a count at zero. 2. Randomly choose a and b in -1,1 (this part might take a little ingenuity, since you only have the functions randint and random). 3. If the point (a, b) lies inside the unit disk, increase the count by 1 and plot the point in red. If it doesnt lie inside the disk, plot it in blue (but dont increase the count) 4. Repeat the above steps n times, and compute the approximate probability Then use this to calculate an approximation for π, and print this approximation.

3. (a) If a and b are randomly chosen from the interval |-1,1], what is the probability S1? Draw a picture and answer that the point (a, b) lies inside the disk 2 + this using basic geometry. (b) Write a Sage program that approximates by actually performing the above ex- periment. Your code should do the following: 1. Initialize a graphics object, and start a count at zero. 2. Randomly choose a and b in -1,1 (this part might take a little ingenuity, since you only have the functions randint and random). 3. If the point (a, b) lies inside the unit disk, increase the count by 1 and plot the point in red. If it doesn’t lie inside the disk, plot it in blue (but don’t increase the count) 4. Repeat the above steps n times, and compute the approximate probability Then use this to calculate an approximation for π, and print this approximation.



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *