#!/usr/bin/env python # coding: utf-8 # # Homework 12 # In[4]: import numpy as np import matplotlib.pyplot as plt get_ipython().run_line_magic('matplotlib', 'inline') # ## Problem 1 # # Read the posted notes for variables, dictionaries, and tuples. State if you did this. # # ## Problem 2 # # If a dictionary has a value that is an array, we can access elements of the array as follows. (First we make the dictionary, then we access an array element.) # # ```python # a = { # 'CO2':np.array([0.1, 2.2, 33.3]), # 'H2O':np.array([0.2, 3.8, 44.4]), # useful optional end comma # } # makes each line the same # a['CO2'][1] # --> 2.2 # ``` # # That is ```a['CO2']``` is the array, and the following ```[1]``` accesses the given element. # # The heat capacity of a species $i$ is given by # $$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)$$ # # The following species data are given: # # # | 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 | 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 | # # * Write a dictionary containing this data. # # In[ ]: # ## Problem 2 # # * Refer to Problem 1. Now write a function called ```cp``` that takes two arguments: a string that gives the name of the species, and the temperature. # * The function should return the heat capacity of the given species at the given temperature. # # In[ ]: # ## Problem 3 # * Refer to Problems 1 and 2 # * A mixture heat capacity can be found from # $$c_p(x,T) = \sum_i x_ic_{p,i}(T),$$ # where $x_i$ are species mole fractions. # # * Write a function called ```cp_mix``` that takes two arguments: a dictionary containing the names and mole fractions of species, and the temperature. # * This function should evaluate the mixture $c_p$ using a loop that calls the function you wrote Problem 2. # # In[ ]: # ## Problem 4 # * Refer to Problems 1, 2, and 3 # * Use the function ```cp_mix``` to evaluate the mixture heat capacity at T=900 K, for the following mixture (corresponding to a stoichiometric mixture of methane and air (CH4 + 2O2 + 7.52 N2): # * $x_{CH_4} = 0.095$, # * $x_{O2} = 0.19$, # * $x_{N2} = 0.715$. # In[ ]: # ## Problem 5 # * Refer to the above problems # * Create an array of temperatures from 300 to 1000 K with steps of 2 K. # * Use your cp_mix function to find an array of cp values at each temperature for the same mixture as in Problem 4. # * Plot $c_{p,mix}$ versus $T$. # In[ ]: