# Example: Free energy of an expanding gas

## Understanding the situation

Though energy conservation (the 1st law of thermodynamics) constrains what transformations of a system are possible, it doesn't constrain what direction a transformation will go in spontaneously. Thermal energy can flow from a hot object to a cold object or from a cold object to a hot object and still conserve energy. To get the direction it will tend to go (without an input of outside work to help it change its mind) by itself, we need the 2nd law of thermodynamics that says transformations occur so as to increase the total entropy of the universe.

A useful way to combine these two laws is to create the concept of free energy — a quantity that represents something like "the energy available for doing work consistent with the 2nd law". Keeping track of the thermal energy that needed to be dumped outside our system in order to keep the entropy of the universe increasing leads us to introduce free energy. Let's evaluate the example discussed in that web page explicitly to see how free energy works.

## Presenting a sample problem

Consider a perfectly insulated box with gas on one side and vacuum on the other separated by a removable dividing membrane. The membrane can be quickly slid out, doing essentially no work. When this is done:

1. What happens to the total internal energy of the gas?
2. What happens to the pressure of the gas?
3. What happens to the free energy, F = U - TS, of the gas?

## Solving this problem

1. The internal energy of a substance consists of the kinetic energy of the molecules plus the chemical energy of the molecules (negative binding energies) plus the potential energy interactions of the molecules. We are considering only fixed molecules — not considering that any chemical reactions might take place — so the chemical energy doesn't change and we can ignore it. We are considering a gas, so the molecules are so far apart that there is no significant energy from potential energies of interactions. As a result, all we have to consider is the kinetic energy of the gas molecules. The internal energy can be considered as the sum of all the kinetic energies of the molecules. Since the collisions between molecules conserve kinetic energy, this remains a constant.

When the membrane is removed, the molecules can move in a larger space, but their speeds are not changed as a result. Therefore, the total kinetic energy and therefore the internal energy, does not change when the membrane is removed.

2. The pressure of the gas arises from the molecules colliding with the walls. As discussed in the page, Kinetic theory: the ideal gas law, the pressure on the wall is $p = \frac{1}{3}nmv^2$ where $n$ is the number density of the molecules ($N/V$), $m$ is an individual molecule's mass, and $v$ is their average speed.

Since the number density decreases by a factor of 2 when the membrane is removed (number, $N$, stays the same, but $V$ doubles), the pressure drops by a factor of 2 when the volume doubles. Microscopically, this arises since the molecules have further to go before they hit a wall, so they will not hit as often, reducing the average number of strikes per second, and therefore the average force felt by the wall.

We can see this both from looking directly at the macroscopic form of the law, $pV = Nk_BT$. Since the number $N$ and the temperature $T$ are both constant, when $V$ doubles, $p$ must halve so that the product $pV$ remains constant.

3. Since this is not a constant pressure situation, the (Helmholtz) free energy, $F = U - TS$, is more appropriate to consider than the Gibbs free energy (which includes a term that corresponds to the work needed to keep the pressure constant).

To get this, we will need to figure out what the entropy change is for an ideal gas whose temperature remains constant but whose volume changes. Since there is no thermal energy exchanged, we have to use the statistical form of the entropy, $S = k_B \ln W$, where $W$ is the number of microstates.

Since volume is one of those continuous variables, counting has to be done by breaking up the variable into discrete pieces, counting, figuring out the change, and then taking the limit as our discrete pieces get small. (In fact, often the size of the discrete pieces becomes irrelevant to the change so we don't actually have to take this limit.) Let's break our volume up into a lot of small pieces of size $V_0$. Then define

$M = V/V_0$, the number of little volumes $V_0$ present in our big volume, $V$.

Then how many ways are there to put our $N$ molecules into a volume $V$? Since there are $M$ bins, each molecules can go into $M$ different places. So we get the number of different ways is $M \times M \times M ... \times M$ with one factor of $M$ for each molecule - so $M^N$. The initial entropy is then

$$S_i = k_B \ln W = k_B \ln(M^N) = Nk_B \ln M = Nk_B \ln(V/V_0)$$

When we double $V$, the final entropy becomes

$$S_i = Nk_B \ln(2V/V_0)$$

But since $\ln(ab) = \ln(a) + \ln(b)$ (logarithms convert multiplication into addition) this is just

$$S_f = Nk_B \ln (2) + Nk_B \ln (V/V_0)$$

As we had hoped, the change in entropy is independent of our choice of the small volume, $V_0$:

$$ΔS = S_f - S_i = Nk_B \ln (2)$$

Doubling the volume increases the entropy by $k_B \ln(2)$ for each molecule.

Since the internal energy doesn't change, the resulting change in the free energy is

$$ΔF = F_f - F_i = {U_f - TS_f } - {U_i - TS_i} = -TΔS =-Nk_B T \ln (2)$$

So the free energy decreases, indicating that the process should progress spontaneously.

## What about the Gibbs free energy?

Since the pressure does NOT remain constant, the Gibbs free energy is not necessarily the appropriate function to calculate to see if the reaction processes spontaneously. But because the Gibbs free energy is a thermodynamic state function — well defined for every state in thermodynamic equilibrium — and since the initial and final states are states of thermodynamic equilibrium, we can calculate $\Delta G$:

$$G = U +pV -TS$$

so $G = F + pV$. Since, as we have seen, $pV$ doesn't change here, the change in $G$ is equal to the change in $F$ and is also negative. This doesn't always work!

Joe Redish 2/7/16

Article 609