Wikipedia:Reference desk/Archives/Mathematics/2018 June 27

= June 27 =

Boltzmann Distribution
I'm having a lot of trouble integrating the Boltzmann distribution with respect to velocity. I haven't done calculus for a lot of years, so I'm probably making some basic error. Any help would be appreciated. First off, the form of the function is (since I'm integrating by parts, I'm using x to represent velocity, otherwise it gets confusing once I start substituting the parts for u and v):

$$ f(x)=4\pi \left ( {\frac{M}{2\pi RT}} \right )^{3/2} x^2 e^ \frac{-Mx^2}{2 \pi RT} $$

The I tried integrating by parts following the formula:

$$\int uv\ dx = u \int v\ dx - \int\left(u' \int v\ dx \right)\ dx.$$

$$ Let~u = 4\pi \left ( {\frac{M}{2\pi RT}} \right )^{3/2} x^2 $$

$$ Let~v = e^ \frac{-Mx^2}{2 \pi RT} $$

$$ \int v\ dx = e^ \frac{-Mx^2}{2 \pi RT} $$

$$ u'= 8\pi \left ( {\frac{M}{2\pi RT}} \right )^{3/2} x $$

$$\int\left(u' \int v\ dx \right)\ dx = \int \left( 8\pi \left ( {\frac{M}{2\pi RT}} \right )^{3/2} x~e^ \frac{-Mx^2}{2 \pi RT} \right) dx $$

Now to work out the integral of $$\left( u' \int v\ dx \right)$$ I will need to do integration by parts again.

$$ Let~u_1 = 8\pi \left ( {\frac{M}{2\pi RT}} \right )^{3/2} x $$

$$ Let~v_1 = e^ \frac{-Mx^2}{2 \pi RT} $$

$$ \int v_1 \ dx = e^ \frac{-Mx^2}{2 \pi RT} $$

$$ u_1 ' = 8\pi \left ( {\frac{M}{2\pi RT}} \right )^{3/2} $$

$$\int\left(u_1 ' \int v_1 \ dx \right)\ dx = \int \left( 8\pi \left ( {\frac{M}{2\pi RT}} \right )^{3/2} e^ \frac{-Mx^2}{2 \pi RT} \right) dx = \left( 8\pi \left ( {\frac{M}{2\pi RT}} \right )^{3/2} e^ \frac{-Mx^2}{2 \pi RT} \right)$$

$$\int\left(u' \int v\ dx \right)\ dx = 8\pi \left ( {\frac{M}{2\pi RT}} \right )^{3/2} x~e^ \frac{-Mx^2}{2 \pi RT} - \left( 8\pi \left ( {\frac{M}{2\pi RT}} \right )^{3/2} e^ \frac{-Mx^2}{2 \pi RT} \right)$$

Now I can substitute everything back in to get this hideous integral:

$$\int uv\ dx = 4\pi \left ( {\frac{M}{2\pi RT}} \right )^{3/2} x^2 ~e^ \frac{-Mx^2}{2 \pi RT} - \left( 8\pi \left ( {\frac{M}{2\pi RT}} \right )^{3/2} x~e^ \frac{-Mx^2}{2 \pi RT} - \left( 8\pi \left ( {\frac{M}{2\pi RT}} \right )^{3/2} e^ \frac{-Mx^2}{2 \pi RT} \right) \right) $$

Now I know it's wrong because 1) it gives crazy results when I try to determine the fractions of gas particles between particular speeds and 2) because when I plot it next to the original function it doesn't look anything like the integral of it (in fact the curve is almost the same). Clearly I'm doing something really dumb in performing this integral but I have no idea what. I've googled around a bit and came up with some references to reduction formulae which just left me more confused than when I started. 61.247.39.121 (talk) 09:18, 27 June 2018 (UTC)
 * Ok, I can see that I've been integrating $$e^{x^2}$$ wrong. Should have been $$\frac{e^{x^2}}{2}$$ rather than $$e^{x^2}$$. I fixed that and did the integration again. Obviously got a completely different formula but it still doesn't look right nor return values that make sense. 61.247.39.121 (talk) 09:36, 27 June 2018 (UTC)
 * Scratch that. I can now see that this should be treated as a Gaussian integral, so $$ e^ \frac{-Mx^2}{2 RT} $$ is rewritten to $$ e^{-x^2 \frac{M}{2 RT}}$$ and the integral is $$ \sqrt{ \frac{ \pi }{ \frac{M}{2RT} } } $$. Now I run into an even weirder problem where the two terms of the integration by parts end up with the same value and subtract to equal zero. 61.247.39.121 (talk) 10:30, 27 June 2018 (UTC)
 * First off, can you say how you reached the conclusion that the function f you specified describes the Boltzmann distribution? Because I don't think that's the case, and I think the actual function for the Boltzmann distribution is much easier to integrate (it is of the form $$x e^{-x^2}$$, and can be solved simply with substitution).
 * But since this is RD/math and not RD/science, I'll ignore that and talk a bit about integrating the function you specified, which is not as easy.
 * You should first clarify what it is you are actually trying to do - find the indefinite integral (equivalently, a function whose derivative is f), or the definite integral in some interval (such as $$[0,\infty)$$). Because you didn't specify an integration interval at first; but in your latest edit said you need to treat an expression as a Gaussian integral and reduce it to some number. The integral only reduces to a number if it's definite, otherwise you get a function, not a number. And not an elementary function, either.
 * Here we should discuss your original mistake of using $$\int e^{x^2}\ dx = e^{x^2}$$. You were probably tempted by $$\int e^{x}\ dx = e^{x}$$ but this does not work when there is a function in the exponent.
 * It's simpler with derivatives - the derivative of $$e^x$$ is $$e^x$$, but the derivative of $$e^{g(x)}$$ is not $$e^{g(x)}$$, it's $$g'(x)e^{g(x)}$$ because of the chain rule.
 * Integrals are inherently harder to calculate than derivatives, and here we're not so lucky. There's no general way to simplify $$\int e^{g(x)}\ dx$$, and sometimes we have to invent new functions just to have a concise way to describe such integrals. One such function is the error function, defined as $$\mathrm{erf}(x)=\frac{2}{\sqrt{\pi}}\int_0^xe^{-t^2}\ dt$$, and useful for integrals like the one you specified.
 * The analogous rule in integration to the chain rule is the substitution rule - $$\int g'(x)f'(g(x))\ dx = f(g(x))$$, from which we can get $$\int g'(x)e^{g(x)}\ dx=e^{g(x)}$$. For example, $$\int xe^{x^2}\ dx = e^{x^2}/2$$. But if we don't have that $$x$$ term - if we have $$\int e^{x^2}\ dx$$ or $$\int x^2e^{x^2}\ dx$$ - this is much harder and requires special functions.
 * I'm not actually sure what is the best way to try evaluating $$\int x^2 e^{-x^2}\ dx$$, but my silicon overlord tells me it's equal to $$-\frac12xe^{-x^2}+\frac14\sqrt{\pi}\mathrm{erf}(x)$$. This can be verified manually. Your integral is the same, up to constants.
 * To find a definite integral, simply subtract values at the endpoints. For your function, $$\int_0^{\infty}f(x)\ dx$$ turns out to be $$\sqrt{\pi}^{3/2}$$, rather than 1 as we would expect, another indication that the expression is not what you were looking for.
 * But as I said, this kind of integrals are not easy, and I suggest practicing first by solving much easier problems before tackling this one. -- Meni Rosenfeld (talk) 12:40, 27 June 2018 (UTC)
 * ETA: Thanks to Ruslik0's pointers, I now understand better the derivation of your formula (I didn't consider 3-dimensionality, while at the same time I assumed the distribution was based on energy rather than velocity). Anyway, the error in your formula is smaller than I thought: The $$\pi$$ in the denominator of the exponent is superfluous, it should be $$f(x)=4\pi \left ( {\frac{M}{2\pi RT}} \right )^{3/2} x^2 e^ \frac{-Mx^2}{2 RT}$$. -- Meni Rosenfeld (talk) 21:56, 27 June 2018 (UTC)
 * $$\int x^2\,e^{-x^2}\,dx$$ can be done by parts, using $$u=x$$ and $$v' = xe^{-x^2}$$. --Wrongfilter (talk) 13:09, 27 June 2018 (UTC)
 * Right, now that you mention it it seems obvious. I'm a bit out of practice myself :) -- Meni Rosenfeld (talk) 13:32, 27 June 2018 (UTC)
 * Maxwell distributions are usually integrated by using differentiation by a parameter. Let's first introduce a new variable
 * $$u=x\sqrt{\frac{M}{2\pi RT}}$$
 * then
 * $$\int\limits_{-\infty}^{\infty}f(x)dx=4\pi\int\limits_{-\infty}^{\infty}u^2e^{-u^2}du=\left.-4\pi\frac{\partial}{\partial s}\int\limits_{-\infty}^{\infty}e^{-su^2}du\right|_{s=1}=\left.-4\pi^{3/2}\frac{\partial}{\partial s}\frac{1}{\sqrt{s}}\right|_{s=1}=2\pi^{3/2}$$
 * Ruslik_ Zero 19:41, 27 June 2018 (UTC)
 * I wrongly said that this was the Boltzmann distribution, when it is in fact the Maxwell-Boltzmann distribution. Sorry for the confusion. And yes, I entered in a superfluous pi. Using the fixed version of the expression that you gave above, and integrating by parts as per Wrongfilter,


 * $$u=4 \pi \left ( {\frac{M}{2\pi RT}} \right )^{3/2} x $$
 * $$v=x e^ \frac{-Mx^2}{2 RT}$$
 * so...
 * $$u'=8 \pi \left ( {\frac{M}{2\pi RT}} \right )^{3/2} $$
 * then this is the step I'm least sure about...
 * $$\int x e^ \frac{-Mx^2}{2 RT} dx = \frac{e^ \frac{-Mx^2}{2 RT}}{2}$$
 * then...
 * $$\int 8 \pi \left ( {\frac{M}{2\pi RT}} \right )^{3/2} \frac{e^ \frac{-Mx^2}{2 RT}}{2} dx =4 \pi \left ( {\frac{M}{2\pi RT}} \right )^{3/2} \sqrt{ \frac{2 \pi RT}{M}}$$
 * and putting it all together...
 * $$\int f(x) dx =4\pi \left ( {\frac{M}{2\pi RT}} \right )^{3/2} x \frac{e^ \frac{-Mx^2}{2 RT}}{2} - 4 \pi \left ( {\frac{M}{2\pi RT}} \right )^{3/2} \sqrt{ \frac{2 \pi RT}{M}}$$
 * This can be simplified to...
 * $$=2\pi \left ( {\frac{M}{2\pi RT}} \right )^{3/2} x e^ \frac{-Mx^2}{2 RT} - \frac{2M}{RT}$$
 * Still doesn't seem right though...any ideas where the error is? 61.247.39.121 (talk) 23:05, 27 June 2018 (UTC)
 * Ok, I can see the u' is wrong. I've doubled it for no reason. Fixing that error makes the second term in the final result $$- \frac{M}{RT} $$. The result is still not right though. 61.247.39.121 (talk) 23:40, 27 June 2018 (UTC)
 * As you feared, the following step is incorrect: $$\int x e^ \frac{-Mx^2}{2 RT} dx = \frac{e^ \frac{-Mx^2}{2 RT}}{2}$$
 * Instead, it should be $$\int x e^ \frac{-Mx^2}{2 RT} dx = \frac{-RT}{M}e^ \frac{-Mx^2}{2RT}$$.
 * Try figuring out why that is the case - my comments above about the substitution rule might help.
 * Additionally, it appears you are still being very careless about whether you are calculating definite or indefinite integrals. It seems like you want the indefinite integral, but then you switch to definite when it suits you. In particular, when doing the Gaussian integral - the indefinite integral is a function of x which can be expressed with the error function. It is not just a number. If you want the definite integral, use the appropriate notation throughout.
 * I haven't checked for other errors. -- Meni Rosenfeld (talk) 00:23, 28 June 2018 (UTC)
 * I'm trying to get the indefinite integral first. Then I should be able to use that function to substitute in values to determine the definite integral at two different x values and subtract one from the other to get the area under the curve between those two points, right? 202.155.85.18 (talk) 01:21, 28 June 2018 (UTC)
 * The expression I'm looking for seems to be the cumulative distribution function given in the article Maxwell-Boltzmann distribution: $$\operatorname{erf}\left(\frac{x}{\sqrt{2} \sqrt{kT/m}}\right) -\sqrt{\frac{2}{\pi}} \frac{x e^{-x^2/\left(2 \sqrt{kT/m}^2\right)}}{\sqrt{kT/m}} $$ (just with the difference that I'm using the molar mass of the gas and the gas constant, rather than the mass of one particle and the Boltzmann constant). It allows me to get the correct answers for the fraction of gas particles within different speed ranges. And intuitively, it follows that the CDF must be the integral of the probability distribution function. It also validates what you pointed out above with the error function playing a role in the integral. But not only can I still not figure out how to integrate the Maxwell-Boltzmann to get its CDF, I can't differentiate the CDF to get the Maxwell-Boltzmann either.
 * It's not really critical, but another annoying thing about having the error function in the integral is that I cannot enter it into graphing software to directly compare the plot of the integral to the plot of the original function. I had a look at the article on the error function, and I don't understand how it works really at all. Why does the definition of erf(x) include the integral of $$e^{-t^2}$$ wrt t? What is t? 202.155.85.18 (talk) 04:43, 28 June 2018 (UTC)
 * First, I must renew my observation that it seems you are biting more than you can chew, and my suggestion to ease into this with easier exercises first. Get some muscle memory for both differentiation and integration - product rule, chain rule, substitution, integration by parts, fundamental theorem of calculus, derivatives of integrals, etc. This process will go through integrating $$\int x^2e^{-x^2}\ dx$$, which has the form but lacks all those pesky physical constants that make things more cumbersome. Math is a pyramid - you can't build up without first laying a solid foundation.
 * In order to differentiate the above expression for the CDF, you will have to use the definition of erf (from which you can find its derivative), the chain rule and the product rule.
 * As I mentioned, the only way to have a simplified expression for $$\int e^{-x^2}\ dx$$ is to invent a new function for this purpose. This is where erf comes in. It is defined in terms of this integral. In the definition stated in the WP article, t is just an integration variable. The value of erf at point x is given by some definite integral on an interval that ends on x. Since x is already taken, we need a new variable to use for the function we are integrating, so we use t. The fundamental theorem of calculus then guarantees that $$\mathrm{erf}'(x)=\frac{2}{\sqrt{\pi}}e^{-x^2}$$.
 * It's not true you can't enter erf into graphing software. That depends entirely on the software. I recommend the online Wolfram Alpha, aka poor man's Mathematica. For example, http://www.wolframalpha.com/input/?i=erf(x),+exp(-x%5E2). -- Meni Rosenfeld (talk) 11:04, 28 June 2018 (UTC)

You will have a more pleasant life by using exponents instead of fraction bars. Your formula $$ f(x)=4\pi \left ( {\frac{M}{2\pi RT}} \right )^{3/2} x^2 e^ \frac{-Mx^2}{2 \pi RT}$$ can be written $$ f(x)=2^{2^{-1}} \pi^{-2^{-1}} M^{3^1 2^{-1}}  R^{- 3^1 2^{-1}} T^{- 3^1 2^{-1}} x^2 e^{-2^{-1} \pi^{-1}  M^1 R^{-1}T^{-1}x^2}$$

Privately I let the minus sign signify the number "minus one". $$ f(x)=2^{2^-} \pi^{-2^-} M^{3^1 2^-}  R^{-3^1 2^-} T^{- 3^1 2^-} x^2 e^{-2^- \pi^-  M^1 R^- T^- x^2}$$. This convention makes my life even more pleasant than yours. Bo Jacoby (talk) 21:30, 29 June 2018 (UTC).
 * Huh? $$\left ( {\frac{M}{RT}} \right )^{3/2}$$ has immediately visible physical meaning, which is not the case of $$ M^{3^1 2^{-1}}  R^{- 3^1 2^{-1}} T^{- 3^1 2^{-1}} $$. I guess tastes vary...  Tigraan Click here to contact me 07:48, 3 July 2018 (UTC)
 * RefDesk, the place where DNFTT goes to die. --2601:142:3:F83A:611C:BD4F:C063:4BF2 (talk) 13:01, 3 July 2018 (UTC)