CP213: Tutorial Notebook 1
CP213: Tutorial Notebook 1
awsharif syy fix to tutorial 1 Latest commit 124fab8 on 20 Sep 2021 History
2 contributors
Question 1
1
∫ dx x3 .
0
G. Use the trapezium rule with four equal intervals to estimate the value of the integral. Determine the percentage error between the exact value and the value
estimated by the trapezium rule.
N. Make a plot of the percentage error between the exact value and the value estimated by the trapezium rule and the number N of equal intervals used from
N = 1 to 100.
In [ ]:
Question 2
A projectile initially located at the origin has an initial speed v0 = 10 m s−1 directed at an angle of θ = 30∘ from the horizontal. It travels a gravitational field
g = 9.81 m s−2 which points in the negative y-direction.
B. Write an equation for how the x- and y-coordinates of the particle change depend on time t.
L. Plot the variation of the x- and y-coordinates of the projectile with time, from t = 0 until it hits the ground. Also, plot the trajectory (i.e. y(t) vs x(t)) of the
projectile.
N. Repeat parts 2 and 3 of the problem if the velocity of the projectile is at an angle of 60∘ from the horizontal. At what angle will the projectile travel the furthest
in the x-direction?
In [ ]:
Question 3
Plot the data set given in the code block below:
In [ ]:
x_dat = [1220, 1139, 1874, 1550, 1203, 1488, 2003, 1368, 1389, 1300, 1877, 1670, 1080, 1766, 1445, 1718, 1263, 1432, 1557, 1127]
y_dat = [42, 46.5, 28.5, 37.5, 43.5, 36, 21, 36, 37.5, 40.5, 27, 33, 49.5, 30, 39, 31.5, 48, 21, 34.5, 61.5]
The average value of x and y, denoted by x̄ and ȳ, respectively, are defined by
−
1 N 1
x̄ = ∑ xk
N k=0
−
1 N 1
ȳ = ∑ yk
N k=0
Compute x
¯ and y¯ for the data set provided.
In [ ]:
The variance of x (denoted by Sxx ), the variance of y (denoted by Syy ), and the covariance between x and y (denoted by Sxy ) are defined as:
N−1
1
Sxx = ∑(xk − x̄)2
N k=0
N−1
1
Sxy = ∑(xk − x̄)(yk − ȳ)
N k=0
1 N−1
Syy = ∑(yk − y¯)2
N k=0
In [ ]:
The general equation for the best fit line through a set of data is given by:
y = ax + b
Sxy
a=
Sxx
b = ȳ − ax̄.
Plot the equation of the best fit line along with the original data.
In [ ]:
Question 4
Consider the gas-water shift reaction
gas Mw Hf Gf
The data in the table have been summarized in the dictionary data . The stoichiometric coefficients (the stoichiometric coefficient for species k is typically
denoted by the symbol νk ) of the reaction are held in the dictionary nu . Note that product species have a positive stoichiometric coefficient, and reactant species
have a negative stoichiometric coefficient.
In [ ]:
R = 8.314e-3 # ideal gas constant / kJ mol^{-1} K^{-1}
T0 = 298.15 # reference temperature / K
p0 = 1.0e5 # reference pressure / Pa
# stoichiometric coefficients
nu = {}
nu['CO'] = -1.0
nu['CO2'] = 1.0
nu['H2'] = 1.0
nu['H2O'] = -1.0
ΔHrxn = ∑ νk Hf,k
k
where Hf,k is the standard enthalpy of formation of species k. The standard Gibbs energy of reaction ΔGrxn is given by
ΔGrxn = ∑ νk Gf,k
k
Task: Calculate the standard enthalpy of reaction and the standard Gibbs energy of reaction.
In [ ]:
Hrxn = 0.0 # Heat of reaction
Grxn = 0.0 # Gibbs free energy of reaction
for gas, coeff in nu.items():
# TODO sum up Hrxn and Grxn here <---------------------------------
Nk
xk =
N
where Nk is the number of moles of species k, and N = ∑j Nj is the total moles in the system.
Task: From the dictionary with the mole numbers as an input, create a dictionary of mole fractions.
In [ ]:
# some test data - mole numbers of some gases
mole = {}
mole['CO'] = 1.0
mole['CO2'] = 1.0
mole['H2'] = 1.0
mole['H2O'] = 1.0
total_moles = # ???
x_dict = {}
for name, N in mole.items():
Cp
= a0 + a1 T + a2 T 2 + a3 T 3 + a4 T 4
R
where T is the absolute temperature in kelvin, R = 8.314\,J−1 \,mol\,K−1 is the ideal gas constant, and the coefficients ak are given in the table below.
gas a 0 a 1 × 10 3 a 2 × 10 5 a 3 × 10 8 a 4 × 10 11
K −1 K −2 K −3 K −4
The coefficients of the heat capacity have been added to the dictionary data (see below). In what follows below, assume that the mixtures behave as an ideal gas.
In [ ]:
data['CO'] ['Cp_coeff'] = [3.912, -3.913e-3, 1.182e-5, -1.302e-8, 0.515e-11]
data['CO2']['Cp_coeff'] = [3.259, 1.356e-3, 1.502e-5, -2.374e-8, 1.056e-11]
data['H2'] ['Cp_coeff'] = [2.883, 3.681e-3, -0.772e-5, 0.692e-8, -0.213e-11]
data['H2O']['Cp_coeff'] = [4.395, -4.186e-3, 1.405e-5, -1.564e-8, 0.632e-11]
Task: Plot the molar heat capacity of the mixture and of each of the individual components as a function of temperature.
In [ ]:
moles = {'CO':1, 'CO2':2, 'H2':0, 'H2O':1}
T_data = np.arange(200.0, 600.0, 10.0)
plt.legend()
plt.xlabel('temperature / K')
plt.ylabel(r'molar heat capacity / J mol$^{-1}$ K$^{-1}$')
plt.show()
Task: Plot the heat capacity of reaction ΔCp,rxn (T ) of the gas-water shift reaction as a function of temperature.
ΔCp,rxn = ∑ νk Cp,k (T )
k
where T is the absolute temperature of the system, and Cp,k (T ) is the molar heat capacity of species k at temperature T .
In [ ]:
T_data = np.arange(200.0, 600.0, 10.0)
plt.xlabel('temperature / K')
plt.ylabel(r'$\Delta C_{p,{\rm rxn}}$ / J mol$^{-1}$ K$^{-1}$')
plt.show()
In [ ]:
© 2022 GitHub, Inc. Terms Privacy Security Status Docs Contact GitHub Pricing API Training Blog About