import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
from scipy.integrate import quad
quad
to solve the following integral:* See the [posted lecture notes](http://nbviewer.org/url/ignite.byu.edu/che263/lectures/quad.ipynb) for how to use ```quad```.
Use quad
to find the numerical integral of the following function:
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)$.
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))
.quad
calls our function, it knows to call it as f(x,a,b,c)
instead of f(x)
like it usually does.
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.$$Species | $h_{f,i}$ (J/mol) |
---|---|
CO2 | -393509 |
H2O(g) | -241818 |
O2 | 0 |
N2 | 0 |
CH4 | -74520 |
quad
to find the enthalpy of CO$_2$ at a temperature of 1000 K.