Isothermal changes and work done by a gas
When a gas expands so that its pressure drops with the increasing volume, but the temperature remains constant, it is called an isothermal change. The gas is still doing work, but the equation $W=p\Delta V$ cannot be used as the pressure is not constant. This change can be represented by the graph below:
The work done is still represented by the area under the graph, but the area either has to estimated by counting squares. The area can be broken into small strips, such as the one shown as δV and applying this across the area required, or by using integration. The equation that links pressure and volume is:
$$pV=nRT$$or
$$p=\frac{nRT}{V}$$This equation describes the relationship seen in the line above, so that $p\propto\frac{1}{V}$. As the gas is doing work on its surroundings as it expands it is losing internal energy and, by convention we say that the amount of work done is negative. If the gas was being compressed, we would give the work done on it a positive sign. Integrating with respect to V gives:
$ \newcommand{\quantity}[2]{ #1 \;\mathrm{#2}} $ $ \newcommand{\units}[1]{\mathrm{#1}}$ $$-\int \frac{nRT}{V}{dV}$$As $nRT$ is a constant it can be brought outside the integral so that:
$$nRT\int \frac{1}{V}{dV}=-nRT\ln{V}$$In the case of the graph above we are looking for the work done between volumes V1 and V2, so the integration becomes:
$$-\int_{V_{1}}^{V_{2}}\frac{nRT}{V}{dV}=-nRT\ln\left({V_{1}}\right)-\ln\left({V_{2}}\right)=\\ -nRT\ln\left(\frac{V_{1}}{V_{2}}\right)$$For a cycle of compression and expansion, where the gas is alternately doing work and being worked on, the graph may look like this:
In this case the net work done, the difference between the work done to compress it and the work it does in expansion is represented by the area within the loop on the graph.