In five card study, a poker player is dealt five cards from a standard deck of 52 cards.
In [9]:
import numpy as np
from scipy import linalg #contains certain operators you may need for class
import matplotlib.pyplot as plt #contains everything you need to create plots
import sympy as sy
from scipy.integrate import quad
In [10]:
import math
total=math.factorial(52)/math.factorial(52-5)/math.factorial(5)
print('Different 5-card hands =\t',total) # Pick 5 cards from 52 cards 5C52
In [11]:
print('The probability of being dealt four of a kind =\t',round(13*(52-4)/total,9))
# First pick a kind (1C13), then one card from the remaining 48 cards (1C48)
# round() returns x rounded to n digits from the decimal point
In [12]:
print('The probability of being dealt a flush =\t',round(4*math.factorial(13)/math.factorial(13-5)/math.factorial(5)/total,9))
#4 suites * 5C13 (Pick 5 cards from 13 cards)
The probability distribution function for a random variable $x$ is given by $P(x)=x e^{-2x}, 0\le x < \infty$.
In [13]:
# First define a function that you want to integrate
def integrand(x):
return x*math.exp(-2*x) #Return Probability distribution
I = quad(integrand,0,np.inf)
print(I)
# I has two values, the first value is the estimation of the integration, the second value is the upper bound on the error.
# Notice that the upper bound on the error is extremely small, this is a good estimation.
X = np.linspace(0,10,1000)
Y=[]
for i in range(np.size(X)):
x=X[i]
y=integrand(x)/I[0]
Y.append(y)
plt.plot(X,Y)
plt.xlabel('x');
plt.ylabel('Normalized P(x)');
plt.title('Normalized P(x)')
plt.show()
In [14]:
X[np.argmax(Y)]
Out[14]:
In [15]:
def integrand1(x):
return x*integrand(x)/I[0] # Return nomalized probability distribution * v
I1 = quad(integrand1,0,np.inf)
print(I1)
In [16]:
def integrand2(x):
return x*x*integrand(x)/I[0] # Return nomalized probability distribution * v^2
I2 = quad(integrand2,0,np.inf)
var=I2[0]-I1[0]**2 # Variance can be calculated as <P(x)^2>-<P(x)>^2
print(var)
It's late on a Friday night and people are stumbling up Notre Dame Ave. to their dorms. You observe one particularly impaired individual who is taking steps of equal length 1m to the north or south (i.e., in one dimension), with equal probability.
In [17]:
n=20
print('The furthest distance the person could travel after 20 steps = \t',n)
In [18]:
print('The probability that the person will not have traveled any net distance at all after 20 steps = \t',math.factorial(20)/math.factorial(10)/math.factorial(10)/2**20,)
# Going nowhere - 10 steps south + 10 steps north 10C20
# Total 2^20
In [19]:
print('The probability that the person has traveled half the maximun distance after 20 steps = \t',2*math.factorial(20)/math.factorial(5)/math.factorial(15)/2**20,)
# Going half the maximun distance - 15 steps south + 5 steps north or 15 steps north + 5 steps south
# Total 2_20
In [20]:
X=[]
Y=[]
for x in range(21): # x stps going south
y=math.factorial(20)/math.factorial(x)/math.factorial(20-x)/2**20 # Pick x steps from 20 steps xC20 / Total
X.append(x-(20-x))
# X means the final distance. The steps going south - the steps going north. If x=0, X=-20 ... If x=20, X=20. Postive means south
Y.append(y)
plt.bar(X,Y)
plt.xlabel('distance');
plt.ylabel('P(x)');
plt.title('Probability distribution')
plt.show()
The Boltzmann distribution tells us that, at thermal equilibrium, the probability of a particle having an energy $E$ is proportional to $\exp(-E/k_\text{B}T)$, where $k_\text{B}$ is the Boltzmann constant. Suppose a bunch of gas particles of mass $m$ are in thermal equilibrium at temperature $T$ and are traveling back and forth in one dimension with various velocities $v$ and kinetic energies $K=mv^2/2$.
$P = Ce^{-\frac{mv^2}{2k_B T}},-\infty\le v < \infty$.
$\int_{-\infty} ^{\infty} vCe^{-\frac{mv^2}{2k_B T}} dv = 0$
$V = \frac{\int_{0}^{\infty} vCe^{-\frac{mv^2}{2k_B T}} dv}{\int_{0}^{\infty} Ce^{-\frac{mv^2}{2k_B T}} dv} =0$
In [21]:
from sympy import *
v = Symbol('x')
C=Symbol('C',positive=True)
m=Symbol('m',positive=True)
kB=Symbol('kB',positive=True)
T=Symbol('T',positive=True)
#Next create a function
function = integrate(C*exp(-m*v**2/2/kB/T),(v,-oo,+oo)) #Denominator
function2 = integrate(v*C*exp(-m*v**2/2/kB/T)/function,(v,-oo,+oo)) #Numerator
print('The expectation value of velocity is',function2/function)
$\int_{-\infty}^{\infty} Ce^{-\frac{mv^2}{2k_B T}} dv = C(\frac{2k_B T\pi}{m})^\frac{1}{2} $
$\int_{-\infty}^{\infty} \frac{mv^2}{2}Ce^{-\frac{mv^2}{2k_B T}} dv = \frac{Ck_B T}{2}(\frac{2k_B T\pi}{m})^\frac{1}{2} $
$K = \frac{\int_{-\infty}^{\infty} \frac{mv^2}{2}Ce^{-\frac{mv^2}{2k_B T}} dv}{\int_{-\infty}^{\infty} Ce^{-\frac{mv^2}{2k_B T}} dv} =\frac{k_B T}{2}$
K will increase when temperature increases(linear relationship), but unrelated to the particle mass.
Hint:
$\int_{0}^{\infty} e^{-ax^2} dx = \frac{1}{2}(\frac{pi}{a})^\frac{1}{2} $
$\int_{0}^{\infty} xe^{-ax^2} dx = \frac{1}{2a}$
$\int_{0}^{\infty} x^2e^{-ax^2} dx = \frac{1}{4a}(\frac{pi}{a})^\frac{1}{2} $
In [22]:
function3 = integrate(m*v**2/2*C*exp(-m*v**2/2/kB/T)/function,(v,-oo,+oo)) #Numerator
print('The expectation value of kinetic energy K is',function3)
In [ ]: