Applying variational calculus with constraints (analogous in some sense to the method of Lagrange multipliers), we write the Lagrangian (or Lagrange function) L as L = ( − − k B ∑ ∑ i ρ ρ i ln ⁡ ⁡ ρ ρ i ) + λ λ 1 ( 1 − − ∑ ∑ i ρ ρ i ) + λ λ 2 ( U − − ∑ ∑ i ρ ρ i E i ) .