μ is never set directly. For the current N and T, it's whatever value makes the discrete
sum add up to exactly N:
$$N(\mu) = \sum_{n=0}^{n_{\max}} \frac{g_n}{e^{(n-\mu)/T}-1} \;\stackrel{!}{=}\; N_{\text{target}}$$
This has no closed-form inverse, so it's solved numerically. The key fact that makes it easy:
every term increases as μ increases, so N(μ) is strictly increasing on
(−∞, 0). It vanishes as μ → −∞, and diverges as
μ → 0− (the n=0 term alone blows up). So for any target N, exactly
one μ solves the equation — and bisection finds it:
1. Start with lo = a safely negative guess, hi = −10−9 (just below 0).
2. If N(lo) is still > target, lo isn't negative enough — double it and repeat.
3. Repeat ~100×: check the midpoint m = (lo+hi)/2.
If N(m) < target, the answer is above m → set lo = m.
Otherwise the answer is below m → set hi = m.
4. After 100 halvings the bracket [lo, hi] has shrunk to machine precision — return
μ = (lo+hi)/2.
Once μ is known, plugging it back into the n=0 term alone gives the condensate population
N0, and N−N0 gives everything in the excited states.