  A new method for calculating the free energy of an inhomogeneous
superconductor is presented. This method is based on the quasiclassical limit
(or Andreev approximation) of the Bogoliubov-de Gennes (or wave function)
formulation of the theory of weakly coupled superconductors. The method is
applicable to any pure bulk superconductor described by a pair potential with
arbitrary spatial dependence, in the presence of supercurrents and external
magnetic field. We find that both the local density of states and the free
energy density of an inhomogeneous superconductor can be expressed in terms of
the diagonal resolvent of the corresponding Andreev Hamiltonian, resolvent
which obeys the so-called Gelfand-Dikii equation. Also, the connection between
the well known Eilenberger equation for the quasiclassical Green's function and
the less known Gelfand-Dikii equation for the diagonal resolvent of the Andreev
Hamiltonian is established. These results are used to construct a general
algorithm for calculating the (gauge invariant) gradient expansion of the free
energy density of an inhomogeneous superconductor at arbitrary temperatures.
