Tutorial 2 - 2010
Due date(s): | 22 September 2010 |
(PDF) | Tutorial questions |
Other instructions | Hand-in at class. |
<rst> <rst-options = {'toc': False, 'reset-figures': False} />
.. |m3| replace:: m\ :sup:`3` .. highlight:: python
.. rubric:: Tutorial objectives
- Some questions to help you feel comfortable deriving model equations for actual chemical engineering systems. - Brute force solving of equation systems. The rest of the course will focus on better ways to solve these equations. - Interpreting source code written on paper.
.. rubric:: Recap of tutorial rules
- Tutorials can be done in groups of two - please take advantage of this to learn with each other.
- Tutorials must be handed in at the start of class on Wednesday. No electronic submissions - thanks!
Question 1 [2]
===
.. note::
Parts 1 and 2 of this question were from the 2006 final exam (slightly modified). It was worth 10% of the 3 hour exam
Consider a mixing tank with fluid volume :math:`V` where fluids A and B with densities :math:`\rho_A` and :math:`\rho_b`, specific heat capacities :math:`C_{p,A}`, :math:`C_{p,B}` and temperatures :math:`T_A` and :math:`T_B` are the inlet streams at volumetric flow rates :math:`F_A` and :math:`F_B`. The outlet stream is at a flow rate :math:`F_A+F_B`. The specific heat capacity and density of the outlet streams is given by :math:`C_p=(C_{p,A}F_A+C_{p,B}F_B)/F` and :math:`\rho=(\rho_AF_A+\rho_BF_B)/F`. The fluid also looses heat from the tank at a rate :math:`q=k_T(T-T_\text{wall})` where :math:`T_\text{wall}` is the constant tank wall temperature, :math:`k_T` is a constant and :math:`T` denotes the current fluid temperature.
- . Using 3-step modelling approach shown in class, derive a dynamical balance describing the time-dependent exit stream temperature.
- . Can the steady state exit stream temperature be higher than both :math:`T_A` and :math:`T_B`? Explain.
- . Calculate, *by-hand*, the steady-state exit temperature, using that
* :math:`V` = 10 |m3| * :math:`\rho_A` = 1200 kg/\ |m3| and :math:`\rho_b` = 950 kg/\ |m3| * :math:`C_{p,A}` = 2440 J/(kg.K) and :math:`C_{p,B}` = 3950 J/(kg.K) * :math:`T_A` = 320 K and :math:`T_B` = 350 K and :math:`T_\text{wall}` = 300K * :math:`F_A = F_B` = 0.05 |m3|/s * :math:`k_T` = 200 W/(m\ :sup:`2`.K) :math:`\times` 24 m\ :sup:`2` = 4800 W/K
Question 2 [2]
=====
.. note:: You don't need to write any code for this question.
Consider the reaction
.. math:: {\sf P_2I_4} + n\,{\sf P_4} + p\,{\sf H_2O} \longrightarrow 4\,{\sf PH_4I} + q\,{\sf H_3PO_4} where :math:`n`, :math:`p` and :math:`q` denote the stoichiometric coefficients for :math:`\sf P_4`, :math:`\sf H_2O` and :math:`\sf H_3PO_4` respectively.
- . Derive the equations necessary to solve for :math:`n, p`, and :math:`q` by equating atoms of :math:`{\sf P}`, :math:`{\sf H}`, and :math:`{\sf O}` on the reactant and product sides.
- . In the next section of the course we will use Guass Elimination to solve these equations. For now though, let's describe a brute force approach. First, complete the two lines of this MATLAB function:
.. code-block:: matlab
function total_error = equation_error( n, p, q )
% Given the values of n, p, and q, calculate the error of each balance equation. % Returns the sum of squares of the errors.
error_1 = _______________ % from the P-balance error_2 = 2*p - 3*q - 16; % from the H-balance error_3 = _______________ % from the O-balance
total_error = (error_1)^2 + (error_2)^2 + (error_3)^2;
end % end of function
or complete this Python function:
.. code-block:: python
def equation_error(n, p, q ): """ Given the values of n, p, and q, calculate the error of each of the 3 equations. Returns the sum of squares of the errors. """ error_1 = _______________ error_2 = 2*p - 3*q - 16 error_3 = _______________
return error_1**2 + error_2**2 + error_3**2
- . Since we known that :math:`n, p`, and :math:`q` must be positive, we can construct a set of 3 nested for-loops, as shown below in MATLAB and Python. Describe in plain English what the code does.
**In MATLAB:**
.. code-block:: matlab
smallest = 0.0; largest = 14.9; step_size = 0.1; vector = smallest : step_size : largest;
% How many elements in each vector? num = length(vector);
errors = zeros(num, num, num);
index_n = 0; index_p = 0; index_q = 0; for n = smallest : step_size : largest index_n = index_n + 1; for p = smallest : step_size : largest index_p = index_p + 1; for q = smallest : step_size : largest index_q = index_q + 1;
% Calculate the error at this value of n, p and q: errors(index_n, index_p, index_q) = equation_error(n, p, q);
end index_q = 0; end index_p = 0; end [min_error, min_index] = min(errors(:)) [index_n, index_p, index_q] = ind2sub([num, num, num], min_index); disp(['Solution at ', num2str([vector(index_n), vector(index_p), vector(index_q)])])
**In Python:**
.. code-block:: python
import numpy as np
smallest = 0.0 largest = 15.0 step_size = 0.1 vector = np.arange(smallest, largest, step_size)
# How many elements in each vector? num = len(vector)
errors = np.zeros( (num, num, num) )
for index_n, n in enumerate(vector): for index_p, p in enumerate(vector): for index_q, q in enumerate(vector):
# Calculate the error at this value of n, p and q: errors[index_n, index_p, index_q] = equation_error(n, p, q)
# Which combination had the smallest error? min_index = np.argmin(errors) index_n, index_p, index_q = np.unravel_index(min_index, (num, num, num)) n, p, q = vector[index_n], vector[index_p], vector[index_q] print(n, p, q)
4. How many times will the function ``equation_error`` be called? 5. What will this function output be if :math:`(n, p, q) = (1.0, 9.2, 2.5)`?
Bonus question [0.5]
=========
Using the code given in question 2, report what the ``min_index`` variable is and what are the values of :math:`n, p`, and :math:`q` which give minimum error to the set of equations. How long did it take to find the solution of this simple linear equation system?
.. raw:: latex
\vspace{0.25cm} \hrule %\begin{center}END\end{center}
</rst>