How can a rapid change in the volume of a gas cause changes in its temperature? We were learning about Boyle's law (pressure is inversely proportional to volume of a gas) and in the experiment to prove the law, we were told that we cannot change the volume of a gas too rapidly without affecting its temperature.
I have two questions about this:


*

*Why does temperature of a gas change when its volume changes very rapidly?

*This process (rapid changes in volume) is used in the liquefaction of gases. How is this done?

 A: The temperature has to be constant for $pV=constant$ to be true, because the ideal gas law states $pV=nRT$. If you wait long enough after a volume change, the temperature of the gas will go back to the temperature of the surrounding (which can be assumed constant).
But during this period some amount of energy will be exchanged between the gas container and the surrounding.
If you do not wait, there will not have been any exchange of energy. This process is called adiabatic and has the relationship $pV^\gamma=constant$, with $\gamma=\frac{c_p}{c_v}$ also called the adiabatic index.
So the relation between pressure can be written as $p_2=p_1\left(\frac{V_1}{V_2}\right)^\gamma$, however the ideal gas law still holds, 
$$\frac{p_1V_1}{T_1}=nR=\frac{p_2V_2}{T_2}=\frac{p_1\left(\frac{V_1}{V_2}\right)^\gamma V_2}{T_2}$$
and this can be rewritten to find an expression for the temperature,
$$T_2=T_1\left(\frac{V_1}{V_2}\right)^{\gamma-1}$$
A: A rapid change of volume means that there is little time for heat to escape (Adiabatic process). When you compress a gas, you are doing $P \Delta V$ work on the gas, and the internal energy of the gas must change. There is nowhere for this energy to go and since the internal energy of the gas is proportional to temperature (equipartition theorem / ideal gas properties) the temperature must change.
If you compress said gas and then it reach thermal equilibrium with its surroundings, then you can again extract some of this energy in the form of heat, so that it reaches room temperature. Now, if you let it expand again, it's temperature will further drop. Repeating this process you eventually reach a point in its phase diagram where the gas is a liquid.
