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:
NAME = ""
COLLABORATORS = ""
We can model the profit from a continously stirred tank reactor (CSTR) by computing the value produced from it and subtracting the cost of operating it. Let’s assume that the value a CSTR produces is given by the conversions \(X\) as \(F_{A0} X M\) where \(F_{A0}\) is the inlet molar flow, \(X\) is the conversion in the reactor, and \(M\) is the value of the products formed. The cost of operating our reactor is just proportional to the volume \(V\) of the reactor: \(cost = V C\) where \(C\) is the cost per unit volume.
That leads to this equation
\(profit = F_{A0} X M - V C\)
The volume required to get a particular conversion is defined as
\(V = \frac{F_{A0} X}{k F_{A0}/\nu (1 - X)}\)
You can see the value increases with \(X\), but so does the cost. This leads to a maximum in profit because eventually the volume gets large and the operating costs exceed the value of the products.
The values for the constants in this problem are provided in the next code cell.
Fa0 = 1 # molar flow in, mol / hr
M = 2.5 # value of product $ / mol
C = 0.3 # cost in $ / m^3 / hr
nu = 0.1 # flow rate in m^3 / hr
k = 0.23 # rate constant 1 / hr
Make a plot of the profit for 𝑋=0..1 and show there is a maximum in the profit. Use your graph to visually estimate the conversion where the profit is maximized and the maximum profit. Note, the profit goes to −∞ at 𝑋=1 , so you should use plt.ylim to show only the positive part of the graph. You do not need to solve anything for this, just evaluate the right things.
Use solve_ivp to find the maximum#
We can use an event with scipy.integrate.solve_ivp to find the maximum profit. The first step is to derive a differential equation:
\(\frac{dprofit}{dX} = F_{A0} M - \frac{dV}{dX} C\)
Derive an analytical expression for \(\frac{dV}{dX}\) from the equation above. Then, use solve_ivp to integrate \(\frac{dprofit}{dX}\) with an event function that defines when \(\frac{dprofit}{dX} = 0\), which corresponds in this example to the location of the maximum. The initial condition for the ODE is \(P(X=0)=0\).
Plot your solution to make sure it is the same as the graph you made above, and show a quantitative answer to the conversion where the profit is maximized.
When you are done, download a PDF and turn it in on Canvas. Make sure to save your notebook, then run this cell and click on the download link.
%run ~/f23-06623/f23.py
%pdf