Best代写-最专业靠谱代写IT | CS | 留学生作业 | 编程代写Java | Python |C/C++ | PHP | Matlab | Assignment Project Homework代写

Python代写 | PHYS 210 Project week 4

Python代写 | PHYS 210 Project week 4

In introductory physics courses for science students, the kinetic theory of gases is an important subject
which provides the foundations of thermodynamics and statistical physics. A general description is
given on the wikipedia page:
This theory explains the macroscopic properties of gases, such as pressure, temperature, entropy, etc…
by considering their compositions and particle motions. Of primary importance is the Maxwell-
Boltzmann (MB) distribution function which gives the probability distribution function of particle
speeds in the gas:
This is usually presented as an empirical formula with little or no discussion of its physical origin. In
general students are asked to accept the fact that the distribution of speeds in a gas is given by the MB
formula, but the whole concept remains an abstraction to many. The distribution of speeds is related to
the temperature of the gas T, as illustrated in the figure below:

In this project, you will simulate a 2-dimensional gas and recover the MB distribution of velocities. The
goal is to develop some understanding as to where the MB distribution comes from microscopically.
Your simulation will start with some arbitrary velocity distribution (very non-MB ) and you will
observe that the final velocity distribution will always be a MB distribution.
The redistribution of energy in a gas is done through elastic collisions (collisions can be inelastic, but it
is not relevant for the goal of this project). This means that every time two particles in a gas collide,
you will have to calculate the new velocities according to the conservation of energy and momentum.
There is a simple formula which allows you to do this:
If v1, v2 , x1, x2 are respectively the velocities and positions of particles 1 and 2, then the new velocities
after collision will be:

v1’=v 1u2212
u27e8 v1u2212v 2,x1u2212x2u27e9
||x1u2212x2||2 (x1u2212x2)
v 2’=v 2u2212
u27e8 v2u2212v1, x2u2212x1u27e9
||x1u2212x2||2 (x2u2212x1)
where the <A, B> refers to the dot product between vectors A and B. We have assumed that the two
particles are circles and have the same mass. The collision configuration is shown in the following


You will write a program: which follows the collisional motions of particles in a
box (see setup instructions below).
Your code should generate several output files:
x1 x2u00a0v2 v2u2019 v1u2019 v1
1) An animation: collisions.mp4 that shows the particle positions over each of the time steps
(one frame for every step).
2) After all the steps have completed, it should create a plot with two panels, showing the
probability distribution of speed f(v) of all particles on one panel, and the probability
distribution of kinetic energy, g(E) of all particles (where E=1/2 mv2 ) in the other. The plots
should be in a file called distributions.pdf.
In two dimensions, the analytical expressions for f(v) (called the Maxwell-Boltzmann
distribution of speed) and g(E) (called the Boltzmann distribution) are at the heart of classical
statistical physics, they are given by:
where kB = 1.38 x 10-23 kg s-2K-1 is the Boltzmann constant and T is the temperature of the gas.
Your code should also fit the analytical f(v) to the histogram generated by your simulation to
find the temperature T and plot the fitted function on top of the histogram. Using this same T, it
should plot the analytical g(E) on top of the corresponding histogram.
3) Finally, in a file called collisions.txt your code should write a sentence giving the value
of the temperature you found when fitting the speed distribution.
Note that all your histograms should be normalized to unity for the analytical formulae to work.
Create a new directory somewhere in your home directory with the name
yourusername_project_4 to store the files you will create for this project.

Practical implementation:

1) Start with the template program below, which prepares the gas particle distribution with following

where the left half of particles are blue, the right half are red. The template assigns the initial velocity
of the blue particles to +500 m/s and the red particles to -500 m/s along the x axis. Use the following
characteristics for the simulations:
number of particles: 400
number of time steps: 1000
time step Dt = 0.00002 s
particle size radius = 0.0015 m
particle mass (this is the mass of an O2 molecule) = 2.672 x 10-26 kg
2) Implement the particle-particle collision physics (velocity change) using the itertool.combination()
method introduced above to identify the pairs of particle that undergo a collision. The instruction to
measure distances between particles is already in the program template, you need to build it from there.

Program template:

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from itertools import combinations
npoint = 400
nframe = 1000
xmin, xmax, ymin, ymax = 0, 1, 0, 1
Dt = 0.00002
fig, ax = plt.subplots()
plt.xlim(xmin, xmax)
plt.ylim(ymin, ymax)

def update_point(num):
global x, y, vx, vy
indx = np.where((x < xmin) | (x > xmax))
indy = np.where((y < ymin) | (y > ymax))
vx[indx] = -vx[indx]
vy[indy] = -vy[indy]
xx = np.asarray(list(combinations(x, 2)))
yy = np.asarray(list(combinations(y, 2)))
dd = (xx[:, 0]-xx[:, 1])**2+(yy[:, 0]-yy[:, 1])**2
dx = Dt*vx
dy = Dt*vy
x = x + dx
y = y + dy
data = np.stack((x, y), axis=-1)
x = np.random.random(npoint)
y = np.random.random(npoint)
vx = -500.*np.ones(npoint)
vy = np.zeros(npoint)
vx[np.where(x <= 0.5)] = -vx[np.where(x <= 0.5)]
im = ax.scatter(x, y)
anim = animation.FuncAnimation(fig,
update_point, nframe, interval=10, repeat=False)
To hand the project in, generate a .tar.gz file that contains the entire directory you created for this
project (as you did for each assignment), and submit it at: Again, you can submit from the command line as
for assignment 1 u2013 but make sure you change the URL at the end of the curl command to point to
your new tar.gz file.