Distributions of speeds and velocities in a gas¶
Measure the distribution of the x-component of the velocity, $v_x$ in a system of $N$ particles. Is this distribution compatible with a Gaussian for all values of $N$? Measure the distribution of the speed $\sqrt{v_x^2 + v_y^2}$ and explain the result.
Measure the distribution of $v_x$ for particles which hit a vertical wall. Is this distribution the same as in 1 ?
If you start with a system far from equilibrium -- for instance only a single non-zero velocity how long does it take for the velocity distribution to equilibrate?
How does the velocity distribution change with density?
Distributions can be studied by binning, using python histogram functions, or by calculating the integrated distribution function.
One way of asking if two distributions are the same is to use the Kolmogorov-Smirnov test, which is available from Python. If you want to explore in detail talk to someone in the teaching team for an explanation. The KS test measures vertical separation between integrated distribution functions as a measure of the 'distance' between two distributions. The KS test is in scipy.
Here we generate two samples sample_1
and sample_2
and compare their distributions. the KS-statistic is small -- showing the two distributions are close. The statistic is between 0 and 1 depending on how different the distributions are. With $N$ independent samples the KS-statistic is $O(1/\sqrt{N})$ if the two distributions are identical.
# demonstration of use of KS for random, uniform samples
import numpy as np
import scipy
sample_1 = np.random.uniform(size=10_000)
sample_2 = np.random.uniform(size=10_000)
# compare samples, statistic close to 0.01=1/sqrt(10_000)
# pvalue is uniform in [0 1]
print(scipy.stats.ks_2samp(sample_1, sample_2)) # two samples
print(scipy.stats.kstest(sample_1, 'uniform')) # compare to uniform distribution
KstestResult(statistic=0.011, pvalue=0.5806415540561973, statistic_location=0.6134559215804111, statistic_sign=-1) KstestResult(statistic=0.0070306750187337785, pvalue=0.7033541270838528, statistic_location=0.7567306750187338, statistic_sign=-1)
# demonstration of histogram binning with a gaussian/normal distribution
import numpy as np
import matplotlib.htmlplot as plt
sample = np.random.normal(size=100_000)
fig, ax = plt.subplots() #
nbins=int(np.sqrt(sample.size))
_unused=ax.hist(sample, bins=nbins, histtype='step',density=True)