#!/usr/bin/env python # coding: utf-8 # # Homework 15 # In[16]: import numpy as np import matplotlib.pyplot as plt get_ipython().run_line_magic('matplotlib', 'inline') from scipy.integrate import quad # ## Problem 1 # # * Use ```quad``` to solve the following integral: # $$ I = \int_0^{\pi/2}\cos(x)dx$$ # * See the [posted lecture notes](http://nbviewer.org/url/ignite.byu.edu/che263/lectures/quad.ipynb) for how to use ```quad```. # In[ ]: # ## Problem 2 # # Use ```quad``` to find the numerical integral of the following function: # # $$I = \int_0^{2\pi} e^{-x}\sin(3x)dx.$$ # In[ ]: # ## 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$. # * As described in the lecture notes, ```quad``` normally calls the function you pass as $f(x)$. # * To get ```quad``` to call your function as $f(x,a,b,c)$ instead, you need to tell quad about the extra $a$, $b$, $c$ arguments. # * ```quad``` has a parameter called ```args``` that we can set to a tuple containing our extra argments, like this: ```I,err = quad(f,x1,x2,args=(a,b,c))```. # * Then, when ```quad``` calls our function, it knows to call it as ```f(x,a,b,c)``` instead of ```f(x)``` like it usually does. # In[ ]: # ## 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)$$ # # # | Species | $a_0$ | $a_1$ | $a_2$ | $a_3$ | $a_4$ | # |---------|-----------------|-------------------|------------------|-------------------|-------------------| # | CO2 | 2.356773520E+00 | 8.984596770E-03 | -7.123562690E-06 | 2.459190220E-09 | -1.436995480E-13 | # | H2O(g) | 4.198640560E+00 | -2.036434100E-03 | 6.520402110E-06 | -5.487970620E-09 | 1.771978170E-12 | # | O2 | 3.782456360E+00 | -2.996734160E-03 | 9.847302010E-06 | -9.681295090E-09 | 3.243728370E-12 | # | N2 | 3.298677000E+00 | 1.408240400E-03 | -3.963222000E-06 | 5.641515000E-09 | -2.444854000E-12 | # | CH4 | 5.149876130E+00 | -1.367097880E-02 | 4.918005990E-05 | -4.847430260E-08 | 1.666939560E-11 | # # 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 # * Use ```quad``` to find the enthalpy of CO$_2$ at a temperature of 1000 K. # # ### Part b # * 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}$= 0.095, $x_{O2}$ = 0.19, $x_{N2}$=0.715 # * The enthalpy of the reactant mixture is $h_r = x_{CH4}h_{CH4}(T) + x_{O2}h_{O2}(T) + x_{N2}h_{N2}(T)$. # * Find the mixture enthalpy at T=1000 K. # # In[ ]: