Homework 15¶
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
from scipy.integrate import quad
from scipy.optimize import root
Problem 1¶
- Use
quadto solve the following integral: $$ I = \int_0^{\pi/2}\cos(x)dx$$
Problem 2¶
Use quad to find the numerical integral of the following function:
$$I = \int_0^{2\pi} e^{-x}\sin(3x)dx.$$
Problem 3¶
Use quad to find the numerical integral of the following function:
$$I = \int_{x_1}^{x_2}f(x,a,b,c)dx,$$
where,
$$f(x,a,b,c) = ax^2 + bx + c.$$
That is, $f(x,a,b,c)$ is a polynomial function of $x$ with coefficients $a$, $b$, and $c$.
Solve this for $x_1=1$, $x_2=5$, and for coefficients $a=2$, $b=3$, $c=4$. Use
args.
Problem 4¶
The following equation describes species heat capacities, with data following.
$$c_{p,i}(T) = R_g(a_{0,i} + a_{1,i}T + a_{2,i}T^2 + a_{3,i}T^3 + a_{4,i}T^4 a_{5,i}T^5)$$
| Species | $a_0$ | $a_1$ | $a_2$ | $a_3$ | $a_4$ | $a_5$ |
|---|---|---|---|---|---|---|
| CO2 | 2.43285367e+00 | 8.73482125e-03 | -7.23410929e-06 | 3.31988589e-09 | -7.96674425e-13 | 7.75882050e-17 |
| H2O | 3.99372572e+00 | -5.71111971e-04 | 2.86341142e-06 | -1.70578598e-09 | 4.30471370e-13 | -4.13058207e-17 |
| O2 | 3.03505333e+00 | 1.75425833e-03 | -5.83241162e-07 | -1.20878070e-10 | 1.19576187e-13 | -1.92204612e-17 |
| N2 | 3.60896122e+00 | -1.09689742e-03 | 2.91988900e-06 | -2.05903734e-09 | 6.18649909e-13 | -6.86285024e-17 |
| CH4 | 2.22727446e+00 | 5.71428010e-03 | 4.32080053e-06 | -4.90604232e-09 | 1.65822643e-12 | -1.92319706e-16 |
The enthalpy of the species is given by
$$h_i(T) = h_{f,i} + \int_{T_{ref}}^{T}c_{p,i}(T)dT.$$
- Here, $h_{f,i}$ is the heat of formation of the species at temperature $T_{ref}=298$.
| Species | $h_{f,i}$ (J/mol) |
|---|---|
| CO2 | -393509 |
| H2O(g) | -241818 |
| O2 | 0 |
| N2 | 0 |
| CH4 | -74520 |
Part a¶
Store the $a$ and $h_{f}$ arrays in dictionaries with the species names as keys.
Part b¶
Write a function to compute $c_p$ that takes the species name and temperature as arguments. It will use your dictionary for the $a$.
Part c¶
Write a function to compute the enthalpy of a species given the species name and temperature as arguments. It should use quad and call your $c_p$ function from Part b, and also use your dictionary for $h_{f,i}$.
Use your function to find the enthalpy of CO2 at T=1000 K.
Part e¶
Write a function to compute a mixture enthalpy given a dictionary that maps species names to mole fractions, and temperature, where $h_{mix}(x,T)$ is defined as
$h_{mix}(x,T) = \sum_i x_ih_i(T)$.
This function will use the $x$ dictionary, and your enthalpy function from Part c.
Part d¶
- Methane combustion follows the reaction $$CH_4 + 2O_2 + 7.52 N_2 \rightarrow CO_2 + 2H_2O + 7.52N_2$$
- The reactant mole fractions are: $x_{CH4}$= 1/(1+2+7.52)=0.095, $x_{O2}$ = 2/(1+2+7.52)=0.19, $x_{N2}$=7.52/(1+2+7.52)=0.715
- Similarly, for the products.
- The adiabatic flame temperature (product temperature) is found by equating the reactant mixture enthalpy at the reactant temperature of 300 K with the product mixture enthalpy at the unknown temperature $T_{ad}$. Use
rootto solve this equation: $h_r(300) = h_p(T_{ad})$. You'll need to make use of the mixture function from Part $d$.
Note¶
The whole point of this problem is to find the adiabatic flame temperature for stoichiometric methane combustion given the combustion reaction, and the $c_p$ polynomial coefficients (the a's), and the heats of formation of the species. Parts a-d are just well-considered organizational steps along the path to solution.
#--------- Part a
#--------- Part b
#--------- Part c
#--------- Part d
#--------- Part e