  We study a thermodynamic potential during the classical gravitational
collapse of a 4D (3+1) massless scalar field to a Schwarzschild black hole in
isotropic coordinates. We track numerically the function $F(t)=-dI/dt=-L$,
where $I$ is the total action of matter plus gravitation, $L$ the total
Lagrangian and $t$ is the time measured by a stationary clock at infinity. At
late stages in the collapse, this function can be identified with the free
energy $F=E-TS$ of the black hole where $E$ is the ADM mass, $T$ the Hawking
temperature and $S$ the entropy. From standard black hole thermodynamics, the
free energy of a 4D Schwarzschild black hole is equal to $E/2$. Our numerical
simulations show that at late stages of the collapse the function $-L$
approaches a constant to within 5% of the value of $E/2$. We also present
numerical results for the thermodynamics of 5D collapse where the free energy
in this case is $E/3$. In both 4D and 5D, our numerical simulations show that
at late stages of the collapse, the metric fields are nonstationary in a thin
region just behind the event horizon (and are basically static everywhere
else). The entropy stems mostly from the nonstationary interior region where
there is a significant dip (negative contribution) to the free energy.
