Before you turn this problem in, make sure everything runs as expected. First, restart the kernel (in the menubar, select Kernel\(\rightarrow\)Restart) and then run all cells (in the menubar, select Cell\(\rightarrow\)Run All).
Make sure you fill in any place that says YOUR CODE HERE or “YOUR ANSWER HERE”, as well as your name and collaborators below:
The goal of this problem is to compute the work required to isothermally compress a carbon dioxide gas at 50 degrees Celsius at 1 atm to 1/100th of its initial volume. The work is defined by:
\(\frac{dW}{dV} = -P(V)\).
We can model \(P(V)\) with the Redlich-Kwong equation of state:
\(P(V) = \frac{RT}{(V - b)} - \frac{a}{V (V + b) \sqrt{T}}\)
where
\(a = 0.42747 \left(\frac{R^2 T_c^{5/2}}{P_c}\right)\)
and
\(b = 0.08664 \left (\frac{R T_c}{P_c}\right)\)
The critical constants and Gas constant are provided with the relevant units in the code cell below.
The initial volume of gas under these conditions is 26.4134 liters/mol.
R = 0.08206 # atm * L / gmol / K
# Critical properties for CO2
Tc = 304.2 # K
Pc = 72.9 # atm
Part 1#
Setup a function that defines the Redlich-Kwong equation of state \(P(V)\).
Part 2#
Setup a function that defines the ODE: \(dW/dV = -P(V)\).
Part 3#
Use scipy.integrate.solve_ivp to integrate your ODE from \(V_0\) to \(V_f = 0.01 V_0\). Show the final work required to do the compression to the final volume.
Part 4#
For an ideal gas, the product of \(PV = RT\) where \(RT\) is a constant, which means that a plot of \(ln(P)\) vs \(\ln(V)\) would be a straight line with a slope of -1. Note that \(\ln\) is numpy.log in colab.
Compute the pressure using the volumes from your ODE solution, and make a plot of \(\ln(P)\) vs \(\ln(V)\). This should be as easy as \(P(sol.t)\) if you named your solution as sol.
The ideal pressure is \(P = R T / V\). Compute this and add it to the plot also as \(ln(P)\) vs \(\ln(V)\). Comment on the similarity and differences between the real gas and the ideal gas results.
%run ~/f23-06623/f23.py
%pdf