1
$\begingroup$

I need to draw from a Maxwell-Boltzmann velocity distribution to initialise a molecular dynamics simulation. I have the PDF but I'm having difficulty finding the correct CDF so that I can make random draws from it.

The PDF I am using using is:

$$f(v)=\sqrt \frac{m}{2\pi kT} \times exp \left( \frac{-mv^2}{2kT}\right) $$

I am told that to find the CDF from the PDF we perform:

$$CDF(x)= \int_{-\infty}^x PDF(x) dx $$

After integrating $ f(v) $ I get:

$$ CDF(v)= \sqrt \frac{m}{2\pi kT} \times \left( \frac{\sqrt\pi\times erf \left( \frac{mv}{2\pi kT} \right) }{2\times \left( \frac{m}{2kT} \right)} \right) $$

$$CDF(v)= _{-\infty} ^{x} \left[ {\sqrt \frac{m}{2\pi kT} \times \left( \frac{\sqrt\pi\times erf \left( \frac{mv}{2\pi kT} \right) }{2\times \left( \frac{m}{2kT} \right)} \right)} \right] $$

1)After I reach this point I am unable to proceed as I do not know how to evaluate something between $x$ and ${-\infty}$.

2)I am also concerned that I have not done the integration correctly.

3)I want to implement the CDF in C++ in the end so I can draw from it. Does anyone know if there will be a problem with doing this because of the erf, or will I be alright with this GSL implimentation ?

I am not a mathematician so please be gentle with your explanations :)

Thanks for your time

EDIT:

@bryansis2010 says that I can evaluate in the range $x$ to $0$ instead of $-\infty$.

Would this then make the CDF:

$$ CDF(v)= \sqrt \frac{m}{2\pi kT} \times \left( \frac{\sqrt\pi\times erf \left( \frac{mv}{2\pi kT} \right) }{2\times \left( \frac{m}{2kT} \right)} \right) $$

as $erf(0)=0$

$\endgroup$
11
  • $\begingroup$ How about you change the lower limit to absolute zero, ie 0 kelvin? That is a lower limit because temperatures in the universe do not fall below 0 Kelvin... $\endgroup$ Commented Feb 17, 2013 at 15:28
  • $\begingroup$ Thanks, but given the definition of the CDF, would that still be OK? $\endgroup$
    – RNs_Ghost
    Commented Feb 17, 2013 at 15:47
  • $\begingroup$ i would say it's okay since, by definition, the CDF is cumulative probability that is smaller than a value of $x$. $\endgroup$ Commented Feb 17, 2013 at 16:00
  • $\begingroup$ cheers @bryansis2010, so then my final CDF is correct? (i.e. is the integration is correct?). Also do you have any thoughts on the GSL erf implementation? $\endgroup$
    – RNs_Ghost
    Commented Feb 17, 2013 at 16:04
  • 1
    $\begingroup$ @bryansis2010 let me echo what Manishearth said. This question is off topic for us at Physics. Just a tip for the future: if you think a question is off topic for this site, you can suggest that it be migrated (if the migration is erroneous, that's easy to fix), but it's better if you don't suggest to the OP that he/she cross post the question to another site. $\endgroup$
    – David Z
    Commented Feb 17, 2013 at 20:17

1 Answer 1

2
$\begingroup$

The PDF you gave is for a Gaussian distribution. Your programming language might have a subroutine for generating Gaussian-distributed random variates; if not, inverting the CDF is not the easiest approach. The Box-Muller transform is a good place to start. You give it two uniform random numbers, and it gives you two Gaussian random numbers.

$\endgroup$
1
  • $\begingroup$ Of course! I forgot that, thanks @iannucci. According to wiki each component of the velocity vector has a normal distribution with mean 0 and st-dev sqrt(kT/m). Does this mean I can simply sample from a Gaussian CDF with those parameters and achieve the same thing? i.e. 1/2 *(1+ erf[(x-mu)/sqrt(2*sigma^2)]) $\endgroup$
    – RNs_Ghost
    Commented Feb 17, 2013 at 16:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .