Plot the geometric distribution from 1 to 20 for $p = 0.05$, $p = 0.1$ and $p = 0.25$. Add a legend. Receive 4 bonus points if you use a for loop to construct your lines.
In [24]:
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
x = np.arange(1,21)
for p in [0.05, 0.1, 0.25]:
y = p*(1 - p)**(x - 1)
plt.plot(x, y, label='$p = {}$'.format(p), marker='.')
plt.xlabel('$n$')
plt.ylabel('$P(n)$')
plt.xlim(1,20)
plt.legend()
plt.show()
The cell below is for extra credit on the previous problem. Do not delete the cell, but you make it empty so that your notebook succeeds in validation.
Plot the binomial distribution for $N = 10$ for $p = 0.1$, $p = 0.5$ and $p = 0.9$. Receive 4 bonus points if you use a for loop to construct your lines.
In [22]:
from scipy.special import binom
N = 10
x = np.arange(0,N + 1)
for p in [0.1, 0.5, 0.9]:
y = binom(N, x) * p**x * ( 1 - p)**(N - x)
plt.plot(x, y, label='$p = {}$'.format(p), marker='.')
plt.xlabel('n')
plt.ylabel('$P(n)$')
plt.legend(loc='best')
plt.show()
The cell below is for extra credit on the previous problem. Do not delete the cell, but you make it empty so that your notebook succeeds in validation.
Snow fall in Rochester has an average of 98 inches and a variance of 35 inches. Make a plot of the probability distribution function of snowfall in Rochester.
In [21]:
from math import pi
mu = 98
sigma = np.sqrt(35)
x = np.linspace(mu - 30, mu + 30, 250)
y = 1 / np.sqrt(sigma**2 * 2 * pi) * np.exp( -(mu - x)**2 / 2 / sigma**2)
plt.plot(x, y)
plt.ylabel('$P(x)$')
plt.xlabel('$x$ [snowfall in inches]')
plt.show()
Using an internet search, learn how to plot in polar coordinates. Plot $r = \cos 24 \theta \sin 16 \theta$ with a polar plot with $\theta = [0, 14\pi]$. Ensure you have sufficient points to see an interesting pattern
In [86]:
ax = plt.subplot(polar=True)
theta = np.linspace(0,14 * pi, 10000)
ax.plot(theta, np.cos(24 * theta)*np.sin(16 * theta), linewidth=0.25)
plt.show()