Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Gaussian random values. Experiment with the following function for generating random variables from the Gaussian distribution, which is based on generating a random point in

image text in transcribed

Gaussian random values. Experiment with the following function for generating random variables from the Gaussian distribution, which is based on generating a random point in the unit circle and using a form of the Box-Muller formula (see Exercise 1.2.24)

def gaussian(): r = 0.0 while (r >= 1.0) or (r == 0.0): x = -1.0 + 2.0 * random.random() y = -1.0 + 2.0 * random.random() r = x*x + y*y return x * math.sqrt(-2.0 * math.log(r) / r)

Take a command-line argument n and generate n random numbers, using an array a [ ] of 20 integers to count the numbers generated that fall between i * .05 and (i+1) * .05 for i from 0 to 19. Then use stddraw to plot the values and to compare your result with the normal bell curve.

The picture is the code I have so far, I don't have anything in the graphing part yet because I'm not sure how to figure out the x axis variable for each one. I saw other people asking this question but the answers didn't use stddraw at all, it is a book module function. I tried using numpy and installing it with pip a few different ways but my computer still isn't recognizing it.

import random import math import stdarray import stddraw import sys stddraw.setXscale(-5,5) stddraw.setyscale(-5,5) | def gaussian(): r = 0.0 while (r >= 1.0) or (r 0.0): X = -1.0 + 2.0 * random.random() y = -1.0 + 2.0 * random.random() r = x*x + y*y return x * math.sqrt(-2.0 * math.log(r) / r) int(sys.argv[1]) == n = random_numbers for i in range(n): random_numbers.append(gaussian()) print(random_numbers) a = []; for i in range(20): count = 0 for j in random_numbers: if i*0.5 = 1.0) or (r 0.0): X = -1.0 + 2.0 * random.random() y = -1.0 + 2.0 * random.random() r = x*x + y*y return x * math.sqrt(-2.0 * math.log(r) / r) int(sys.argv[1]) == n = random_numbers for i in range(n): random_numbers.append(gaussian()) print(random_numbers) a = []; for i in range(20): count = 0 for j in random_numbers: if i*0.5

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications 24th International Conference Dexa 2013 Prague Czech Republic August 2013 Proceedings Part 1 Lncs 8055

Authors: Hendrik Decker ,Lenka Lhotska ,Sebastian Link ,Josef Basl ,A Min Tjoa

2013 Edition

3642402844, 978-3642402845

More Books

Students also viewed these Databases questions