The results of the quantum harmonic oscillator can be used to look at the equilibrium situation for a quantum ideal gas in a harmonic trap, which is a harmonic potential containing a large number of particles that do not interact with each other except for instantaneous thermalizing collisions. This situation is of great practical importance since many experimental studies of Bose gases are conducted in such harmonic traps.

Using the results from either Maxwell–Boltzmann statistics, Bose–Einstein statistics or Fermi–Dirac statistics we use the Thomas–Fermi approximation (gas in a box) and go to the limit of a very large trap, and express the degeneracy of the energy states () as a differential, and summations over states as integrals. We will then be in a position to calculate the thermodynamic properties of the gas using the partition function or the grand partition function. Only the case of massive particles will be considered, although the results can be extended to massless particles as well, much as was done in the case of the ideal gas in a box. More complete calculations will be left to separate articles, but some simple examples will be given in this article.

Thomas–Fermi approximation for the degeneracy of states 
For massive particles in a harmonic well, the states of the particle are enumerated by a set of quantum numbers . The energy of a particular state is given by:
 

Suppose each set of quantum numbers specify  states where  is the number of internal degrees of freedom of the particle that can be altered by collision. For example, a spin-1/2 particle would have , one for each spin state. We can think of each possible state of a particle as a point on a 3-dimensional grid of positive integers. The Thomas–Fermi approximation assumes that the quantum numbers are so large that they may be considered to be a continuum. For large values of , we can estimate the number of states with energy less than or equal to  from the above equation as:
 
which is just  times the volume of the tetrahedron formed by the plane described by the energy equation and the bounding planes of the positive octant. The number of states with energy between  and  is therefore:
 

Notice that in using this continuum approximation, we have lost the ability to characterize the low-energy states, including the ground state where . For most cases this will not be a problem, but when considering Bose–Einstein
condensation, in which a large portion of the gas is in or near the ground state, we will need to recover the ability to deal with low energy states.

Without using the continuum approximation, the number of particles with energy  is given by:
 
where
 {|
|-
|
|   for particles obeying Maxwell–Boltzmann statistics
|-
|
|   for particles obeying Bose–Einstein statistics
|-
|
|   for particles obeying Fermi–Dirac statistics
|}

with , with  being the Boltzmann constant,  being temperature, and  being the chemical potential. Using the continuum approximation, the number of particles  with energy between  and  is now written:

Energy distribution function 
We are now in a position to determine some distribution functions for the "gas in a harmonic trap." The distribution function for any variable  is  and is equal to the fraction of particles which have values for  between  and :
 

It follows that:
 

Using these relationships we obtain the energy distribution function:

Specific examples 

The following sections give an example of results for some specific cases.

Massive Maxwell–Boltzmann particles 

For this case:
 

Integrating the energy distribution function and solving for  gives:
 

Substituting into the original energy distribution function gives:

Massive Bose–Einstein particles 

For this case:
 
where  is defined as:
 

Integrating the energy distribution function and solving for  gives:
 
where  is the polylogarithm function. The polylogarithm term must always be positive and real, which means its value will go from 0 to  as  goes from 0 to 1. As the temperature goes to zero,  will become larger and larger, until finally  will reach a critical value , where  and
 

The temperature at which  is the critical temperature at which a Bose–Einstein condensate begins to form. The problem is, as mentioned above, the ground state has been ignored in the continuum approximation. It turns out that the above expression expresses the number of bosons in excited states rather well, and so we may write:
 
where the added term is the number of particles in the ground state. (The ground state energy has been ignored.) This equation will hold down to zero temperature. Further results can be found in the article on the ideal Bose gas.

Massive Fermi–Dirac particles (e.g. electrons in a metal) 

For this case:
 

Integrating the energy distribution function gives:
 
where again,  is the polylogarithm function. Further results can be found in the article on the ideal Fermi gas.

References 
 Huang, Kerson, "Statistical Mechanics", John Wiley and Sons, New York, 1967
 A. Isihara, "Statistical Physics", Academic Press, New York, 1971
 L. D. Landau and E. M. Lifshitz, "Statistical Physics, 3rd Edition Part 1", Butterworth-Heinemann, Oxford, 1996
 C. J. Pethick and H. Smith, "Bose–Einstein Condensation in Dilute Gases", Cambridge University Press, Cambridge, 2004

Statistical mechanics