I have come across a problem from "Biological Physics" by Philip Nelson (pg212) which involves finding the equilibrium position of a spring, $x_{eq}$, which is compressing an ideal gas whilst in contact with a heat reservoir of temperature, $T_{res}$. A diagram of the setup is shown below:
I believe that solving it involves the minimisation of the system's free energy $F$:
$$F = U - TS $$ $$dF = dU - TdS - SdT $$
which simplifies to
$$ dF = -SdT -pdV$$
using $dU = TdS - pdV$.
Since the system is at thermal equilibrium with a head bath, $dT = 0$. Also, the pressure and volume can be written in terms of the spring extension and constant: $V = A(L-x_{1})$ and $pA = \frac{1}{2} kx^{2}$ (when at equilibrium) so that $dV = -Adx_{1}$ and $ dp = \frac{k}{A}x$.
However, setting the equilibrium condition $dF=0$ leaves me with
$$ dF (=0) = dW = -pdV = \frac{1}{2}kx^{3}dx $$
which gives an extension of 0 as a (somewhat unhelpful) result.
A second attempt involved writing $dW$ as
$$ dW = fdx_{1} $$ where $f$ is the force on the compression plate so that
$$ f(x_1) = \frac{1}{2}x_{1}^{2} - pA $$
with the solutions of $f(x_1) = 0$ giving the equilibrium position of the plate assuming the ideal gas law $pV = pA(L-x_{1}) = nRT$. I believe this involves solving
$$ x_{eq}^{3} - Lx_{eq}^{2} - \frac{2nRT}{k} = 0 $$
However, this solution appears to avoid all thermodynamic arguments, and just simplify to solving a simple mechanical problem assuming ideal gas behavior, which makes me believe I have make a mistake somewhere along the derivation.
Any advice with the exercise, and on understanding the application of free energies to thermodynamic problems would be much appreciated.
---------------------EDIT-----------------------
I realise that I erred on the penultimate equation ( $f(x_{1}) = kx_{1} - pA$), which then leads to the equation $kx_{eq}(L - x_{eq}) = nRT$. This seems to suggest that the total internal energy of the system can be split into the energy of the spring, and the energy of the gas so that $$dU_{total} = dU_{gas} +dU_{spring} = -pdV + kxdx$$ It appears that my mistake was to treatthe spring as a seperate entity, and forgetting its energy addition to the total internal energy of the system