I have a volume with $N$ molecules; I need to assign to each particle a velocity vector: $$|\mathbf{v}_{i}|=[v_{x}, v_{y}, v_{z}]^{T}$$ for the $i$-th molecule; the velocities must follow the Maxwell-Boltzmann distribution; here is the question: I know the definition of the M.B. distribution, how do I extract the velocities that I have to assign to each molecule? Basically what I want to know is how to calculate $$v_{x}=?$$ $$v_{y}=?$$ $$v_{z}=?$$ for each molecule.
Answer
The Maxwell-Boltzmann distribution is a continuous probability distribution of particles as a function of either momentum, energy, or speed. Since you want the velocity vector, we start with that: $$ p_V(v_x,v_y,v_z)= \left(\frac{m}{2\pi kT}\right)^{3/2}\exp\left(-\frac{m}{2kT} v^2\right) $$ where $v^2=v_x^2+v_y^2+v_z^2$. Note that, due to the product rule of exponential functions, you can actually write the above as $$ p_V(v_x,v_y,v_z)=p_V(v_x)p_V(v_y)p_V(v_z) $$ with $$ p_V(v_x)=\left(\frac m{2\pi kT}\right)^{1/2}\exp\left[-\frac{m}{2kT}v_x^2\right]\tag{1} $$ and likewise for $p_V(v_y)$ and $p_V(v_z)$. Thus, you can find the probability distribution of the vector velocity by finding three individual probabilities and multiplying them together.
In order to sample from the distribution in (1), you need the cumulative distribution function, defined as (for the continuous case) $$ F_X(x)\dot=\int_{-\infty}^xp_V(v_x)\,dv $$ The final result is $$ F_X(x)=\frac12\left[1+{\rm erf}\left(\frac{x}{a\sqrt{2}}\right)\right]\tag{2} $$ where $a=\sqrt{kT/m}$ and ${\rm erf}(\eta)$ is the error function. Note that $F_X(x)\in\left[0,1\right]$.
It is from this that you can draw your random velocities to match the distribution. Pick a random number in the range 0 to 1, set it as $F_X(x)$ and find the $x$ such that the two sides of (1) are equal. There are a number of ways to do this, you'll have to find the one that works best for you.
No comments:
Post a Comment