first law and its application to ideal and nonideal gases