Skip to main content
GameDev.net gamedev.net
🔒 Locked

Assigning velocity to particles using probability distribution

Started by subflood Mar 28, 2009 at 4:08 PM 4 replies 1.3k views
Original Post
subflood
subflood
Hello, I want to write a simulation of the ideal gas law but I'm having some trouble with the math. I have a few particles/molecules and I want to assign to each of them velocities using the maxwell distribution (the equation is given in the "Distribution of Speeds" section of the article). However, since this is just a probability function I'm not sure how I can create a function that will fit the velocities according to the distribution. Of course a program like this has been done before but I'm just doing this for fun and learning purposes. Here is a link to what I want to achieve: link. Any help is greatly appreciated.
Bob Janova
Bob Janova
Create the cumulative distribution function, and map a set of linear random numbers [0,1) to velocities by using that.
subflood
subflood
Quote:

Create the cumulative distribution function,

I searched the internet for one but I can't find it.

Quote:

map a set of linear random numbers [0,1) to velocities by using that.

Can you elaborate a bit more on this because I'm not sure what you mean.
Emergent
Emergent
1. Generate a (realization of a) uniform random variable x on the interval [0,1].
2. Compute y = F-1(x).
3. y is a (realization of a) random variable distributed according to F.

This is the Inversion method, and it's usually the best thing to do, though occasionally you can use rejection sampling instead because it's easy.
Emergent
Emergent
Now, I realized that you're interested in vector random variables. What Bob Janova and I described works for scalar random variables. How can we generalize?

Well, in your case, we don't have to. :-) Your problem leads to some drastic simplifications actually (I needed to brush up on my physics to realize this). First, let me write the Maxwell distribution over velocities (from Wikipedia):

Notice that this can be factored (as Wikipedia points out), written as the product of independent distributions in vx, vy, and vz. Hence, to generate v=(vx,vy,vz), you can just generate vx, vy, and vz independently according to the pdf,

f(vi) = [m/(2 pi k T)]1/2 exp[-(m/(2 k T)) vi2]

which is a normal distribution; how to sample it (generate values distributed according to it) is described here.

More generally (in other problems), to sample a vector-valued random variable (z1,...,zn) what you can do is,
1. Generate z1 according to p(z1)
2. Generate z2 according to p(z2 | z1)
...
3. Generate zn according to p(zn | z1, ... zn-1)
subflood
subflood
Thanks for your help. Unfortunately, I won't have time to try this out until next week. I'll post my results then.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.