Internal energy according to the van der Waals equation I am trying to derive the internal energy of a gas which obeys the van der Waals equation.
I have however encountered some problems. I calculate the integral of $dU$ from $V=0,T=0$ to $V=V, T=\infty$ to $V=V,T=T$. 
I can calculate the work:
$$\left(p+\left(\frac{a}{n}\right)^2\right)(V-nb)=nRT \implies p=\frac{nRT}{V-nb}-\frac{an^2}{V^2}$$
For the second part of the path $V$ is constant so $W=0$.
$$W=-\int\limits_\infty^V p\textrm dV=\int\limits_V^\infty \frac{nRT}{V-nb}-\frac{an^2}{V^2} \textrm dV\\=nRT\ln(V-nb)|_V^\infty+\frac{an^2}{V}|_V^\infty\\=
\infty-\infty +\frac{an^2}{\infty}-\frac{an^2}{V}=-\frac{an^2}{V}$$
I know I haven't been mathematically rigorous but that is not really important to me at the moment. I think this is right.
I can't however think of how i should calculate the heat involved in following this path.
Any help on how to do this is appreciated.
EDIT: I see now that the work I calculated is wrong as well as $$nRT\ln(V-nb)|_V^\infty\neq\infty-\infty$$
 A: A mathematicians's take for what it is worth.  There are two methods which can be used to compute the energy (indeed, any of the four energy-type functions) from the equations of state. 
Solve the equations of state to get $T$ and $p$ as functions of $S$ and $V$ and then use the well-known methods for treating exact differential equations to solve $dE=TdS-pdV$.  In the case of the van der Waals
gas which we write as $T=(p+a/V^2)(V-b)$, $S=\frac 1{\gamma-1}\ln((p+a/V^2)(V-b)^\gamma$ (there seems to be a typo in the original formulation and we ignore the term $nR$ which, in this context, is just a scaling factor).  This leads to the expression $$\frac 1{\gamma-1}e^{(\gamma-1)S}-\frac a V$$
for the energy which simplifies to $\frac 1{\gamma-1}T - \frac a V$.
A second method uses the fact that if we consider the general equations of state $T=f(p,V)$ and $S=g(p,V)$ for functions $f$ and $g$ of two variables, then we can use the standard  methods of changing the independent variables in differential forms to rewrite the definition of $E$ in the form
$$ dE=fg_1 dp+(-p+fg_2)dV .$$  The subscripts denote partial differentiation with respect to $p$ and $V$ respectively.  This has the advantage that it works for any equations of state.  In our case $fg_1=\frac{V-b}{\gamma-1}$ and $$-p+fg_2=-p-\frac{2a(V-b)}{V^3(\gamma-1)}+\frac \gamma{\gamma-1}(p+a/V^2).$$  The final step is then slightly messy but still elementary since it only involves integrating simple  rational functions.  All the computations can be done by hand and take less time than would be required to put the solutions into TeX form.
We remark that, regardless of which of the two methods one employs, two of the energy functions can be computed by hand for the van der Waals gas.  For the other two, one can use the second method and then employ numerical procedures to compute the resulting integrals (they involve integrating logarithmic terms  in $p+\frac 1 {V^2}$ with respect to $V$).  
A: You and Lubos are integrating the expression $dU = -pdV$ for a constant composition system, but this expression is only valid for constant entropy $S$. During integration you maintain $T$ constant, but the latter is not equivalent to $S$ constant.
If you chose a representation $(T,V)$ then
$$dU = \left( \frac{\partial U}{\partial T}\right)_V dT + \left( \frac{\partial U}{\partial V}\right)_T dV$$
and you can integrate for the special case of constant $T$, but then $({\partial U}/{\partial V})_T$ is not $(-p)$, as you assumed above. The value of this partial derivative can be obtained from the Helmholtz equation $({\partial U}/{\partial V})_T = T^2 [{\partial}/{\partial T} (p/T)]_V$. Integration gives
$$U(T,V,N) = U_0(T,V_0,N) + \int_{V_0}^V T^2 \left( \frac{\partial}{\partial T} \frac{p}{T} \right)_V dV$$
Noting that when the volume tends to infinity the real gas approaches an ideal gas, which implies that $U\to U_\mathrm{ideal}$, we can chose $V_0\to\infty$ to fix the integratino constant $U_0$
$$U(T,V,N) = U_\mathrm{ideal}(T,N) + \int_{\infty}^V T^2 \left( \frac{\partial}{\partial T} \frac{p}{T} \right)_V dV$$
Substituting the van der Waals equation of state
$$\frac{p}{T} = \frac{NR}{V-Nb} - \frac{a}{T} \frac{N^2}{V^2}$$
and working out yields the internal energy of the van der Waals gas
$$U(T,V,N) = U_\mathrm{ideal}(T,N) -  \frac{aN^2}{V} $$
The energy of the ideal gas is given by the well-known form $U_\mathrm{ideal} = N C_V T$ with $C_V$ the heat capacity for ideal gas, e.g. $3R/2$ for monoatomic gas. Now you can understand why the appearance of the heat capacity for an ideal gas is not anything wrong, as you commented above.
Notice also that when $V\to\infty$ the internal energy of the van der Waals gas reduces to the internal energy of an ideal gas, which does not depend on volume. This is the correct result.
A: You can't just subtract infinities and write $\infty-\infty=0$. In fact, $\infty-\infty$ is a major example of an indeterminate form. The result may be anything and needs a precise analysis to be obtained. Moreover, as you realized later, there was really no $\infty-\infty$ over there, it was $\infty-f$ where $f$ is finite.
When you are calculating $\int p\,dV$ where $p$ is a combination of $1/(V-nb)$ and $1/V^2$ pieces, you should calculate the indefinite integral – effective the definite integral going from a lower limit at a finite point to the given upper limit – and it is
$$ - E(V) = \int_{V_0}^V p\, dV' = nRT\ln(V-nb)+\frac{an^2}{V}+C(V_0) $$
The integration constant $C$ is undetermined but one should think it's finite. You may see that both "main" terms are infinite for $V\to 0$ (which means an infinite amount of work would be needed to shrink the volume to zero) and the logarithm is infinite even for $V\to\infty$ (which means that the expansion of the gas to an infinite volume still produces infinite energy). For most purposes, the value of $C$ doesn't matter. But if one wants some "preferred" values of $C$ anyway, it's the value of $C$ that implies $E(V)=0$ or another reasonable value for some microscopic, tiny value of $V$ (so that the molecules are almost maximally squeezed).
A: In case you want to take it from the partition function,
$U = k_B T^2 \frac{\partial}{\partial T} \left( \ln Q \right)$
and
$Q(N, V, T) = \frac{1}{N!} \left( \frac{2 \pi m k_B T}{h^2} \right)^{\frac{3N}{2}} \left( V - Nb \right)^N e^{\frac{a N^2}{V k_B T}}$,
which gives the same result as the other answers.
