0% found this document useful (0 votes)
36 views2 pages

Math Stats HW1

The document contains code to simulate two probability experiments. The first runs 1000 coin flips with a 30% chance of heads and plots the cumulative proportion of heads against trials. The second generates 10,000 random normal variables, takes their exponential, and plots a histogram of the outputs with 500 bins. Both experiments are labeled as solutions to math statistics homework problems.

Uploaded by

Tiger Yan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views2 pages

Math Stats HW1

The document contains code to simulate two probability experiments. The first runs 1000 coin flips with a 30% chance of heads and plots the cumulative proportion of heads against trials. The second generates 10,000 random normal variables, takes their exponential, and plots a histogram of the outputs with 500 bins. Both experiments are labeled as solutions to math statistics homework problems.

Uploaded by

Tiger Yan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Math Stats HW1 9/17/19, 1'31 PM

In [7]: import matplotlib.pyplot as plt


import numpy as np

In [10]: trials = 1000 # number of flips


heads_or_tails = np.zeros((trials,1)) #storage of coin flip results
trial_numbers = range(0,trials) #label of trials
for n in trial_numbers:
heads_or_tails[n] = np.random.binomial(size=1,n=1,p=0.3)

In [11]: # add up the cumulative number of heads we've gotten


cumulative_heads=np.cumsum(heads_or_tails)

In [12]: # divide cumulative number by the trial number


cumulative_heads_divided_by_trial = np.divide(cumulative_heads,trial_n
umbers)

/Users/feihuyan/anaconda3/lib/python3.7/site-packages/ipykernel_laun
cher.py:1: RuntimeWarning: invalid value encountered in true_divide
"""Entry point for launching an IPython kernel.

In [13]: plt.plot(trial_numbers, cumulative_heads_divided_by_trial)


plt.title('Chapter, Problem 21')
plt.show()

In [1]: import matplotlib.pyplot as plt


import numpy as np

http://localhost:8890/nbconvert/html/Math%20Stats%20HW1.ipynb?download=false Page 1 of 2
Math Stats HW1 9/17/19, 1'31 PM

In [3]: #Generate random normal numbers


x = np.random.normal(loc=0,scale=1.0,size=(10000,1))
#Get the exponentials to x as output y
y = np.exp(x)

In [6]: #Plot with 500 bins


plt.hist(y,500)
plt.title('Chapter 2, Problem 13B')
plt.show()

In [ ]:

http://localhost:8890/nbconvert/html/Math%20Stats%20HW1.ipynb?download=false Page 2 of 2

You might also like