diff --git a/CH5210 Programming 1 - Functions.ipynb b/CH5210 Programming 1 Functions.ipynb similarity index 95% rename from CH5210 Programming 1 - Functions.ipynb rename to CH5210 Programming 1 Functions.ipynb index e01fdbd..5fbdaa0 100644 --- a/CH5210 Programming 1 - Functions.ipynb +++ b/CH5210 Programming 1 Functions.ipynb @@ -186,7 +186,8 @@ }, "outputs": [], "source": [ - "#Enter code for Task 1.1 here\n" + "#Enter code for Task 1.1 here\n", + "\n" ] }, { @@ -213,7 +214,8 @@ }, "outputs": [], "source": [ - "#Enter code for Task 1.2 here\n" + "#Enter code for Task 1.2 here\n", + "\n" ] }, { @@ -453,7 +455,8 @@ }, "outputs": [], "source": [ - "#Enter code for Task 2.1 here\n" + "#Enter code for Task 2.1 here\n", + "\n" ] }, { @@ -550,7 +553,8 @@ }, "outputs": [], "source": [ - "#Enter code for Task 3.1 here\n" + "#Enter code for Task 3.1 here\n", + "\n" ] }, { @@ -814,12 +818,7 @@ "outputs": [], "source": [ "#Enter code for Task 3.3 here\n", - "\n", - "log_data = np.log(data)\n", - "print(log_data)\n", - "\n", - "print(\"First two elements, \", log_data[0:2])\n", - "print(\"Last element: \", log_data[-1])\n" + "\n" ] }, { @@ -1020,9 +1019,9 @@ }, "source": [ "
\n", - "Task 4.1: Write a function to calculate the total number of moles of reactant and product in the reaction $A \\rightarrow 2B$, where the arguments should be initial moles of A and the extent of reaction $\\chi$. Use the function to calculate the total number of moles at $\\chi = 0.4$ when the reaction started with 3 mol of A.
\n", + "Task 4.1: Write a function to calculate the total number of moles, $n$, of reactant and product in the reaction $A \\rightarrow 2B$, where the arguments should be initial moles of A and the extent of reaction $\\xi$. Use the function to calculate the total number of moles at $\\xi = 0.4$ when the reaction started with 3 mol of A.
\n", "
\n", - "Hint: The number of moles of reactant equals 1 - $\\chi$. What are the number of moles of product with respect to $\\chi$?\n", + "Hint: The number of moles of reactant equals 1 - $\\xi$. What are the number of moles of product with respect to $\\xi$?\n", "
" ] }, @@ -1035,7 +1034,9 @@ }, "outputs": [], "source": [ - "#Enter code for Task 4.1 here\n" + "#Enter code for Task 4.1 here\n", + "\n", + "\n" ] }, { @@ -1101,7 +1102,7 @@ }, "source": [ "
\n", - "Task 5.1: Write a lambda function to compute the mole fraction of product in the reaction $A \\rightarrow 2B$, where the only required argument is the extent of reaction. Use the function to calculate the mole fraction of B at $\\chi = 0.5$.
\n", + "Task 5.1: Write a lambda function to compute the mole fraction of product in the reaction $A \\rightarrow 2B$, where the only required argument is the extent of reaction. Use the function to calculate the mole fraction of B at $\\xi = 0.5$.
\n", "
" ] }, @@ -1114,7 +1115,8 @@ }, "outputs": [], "source": [ - "#Enter code for Task 5.1 here\n" + "#Enter code for Task 5.1 here\n", + "\n" ] }, { @@ -1127,23 +1129,30 @@ "## End of Session Task\n", "\n", "\n", - "Write a function called `gibbs_energy` that calculates the Gibbs energy change at different extents of reaction ($\\chi$) for a reaction of the form:\n", + "Write a function called `gibbs_energy` that calculates the change in Gibbs energy at different extents of reaction ($\\xi$) for a reaction of the form:\n", + "\n", + "
$A(g) \\rightarrow 2B(g)$
\n", "\n", - "
$A(g) \\rightarrow 2B(g)$

\n", + "Assume 1 mol of A at $\\xi = 0$.\n", "\n", - "Assume 1 mol of A at $\\chi = 0$.\n", + "The total change in Gibbs energy is defined as the sum of contributions from the Gibbs energy change between reactant and product ($\\Delta G_{\\mathrm{reaction}}$) and the Gibbs energy change due to mixing ($\\Delta G_{\\mathrm{mix}}$):\n", "\n", - "The Gibbs energy change is the sum of contributions from the change in Gibbs energy between reactant and product and the Gibbs energy change due to mixing. The Gibbs energy change due to mixing is given by the equation:\n", + "
$\\Delta G_{\\mathrm{total}}(\\xi) = \\Delta G_{\\mathrm{reaction}}(\\xi) + \\Delta G_{\\mathrm{mix}}(\\xi)$
\n", + "\n", + "The Gibbs energy change due to mixing is given by the equation:\n", "\n", "
$\\Delta G_{\\text{mix}}(\\xi) = RT \\Big[ n_A\\ln(\\chi_A) + n_B\\ln(\\chi_B) \\Big]$
\n", "\n", - "The function should take as arguments:\n", + "where $\\chi$ is the mole fraction of a respective species.\n", + "\n", + "\n", + "The function `gibbs_energy` must take the following arguments:\n", "- The change in Gibbs energy between the reactant and product.\n", "- The temperature at which the reaction takes place.\n", "\n", - "The function should return:\n", + "and return:\n", "- A 1D NumPy array representing the extent of reaction.\n", - "- A 1D NumPy array representing the Gibbs energy change for each extent of reaction." + "- A 1D NumPy array representing the total Gibbs energy change for each extent of reaction." ] }, { @@ -1155,7 +1164,9 @@ }, "outputs": [], "source": [ - "#Enter code for End of Session Task here\n" + "#Enter code for End of Session Task here\n", + "\n", + "\n" ] }, { @@ -1196,7 +1207,7 @@ "# Interactive widget\n", "interact(\n", " plot_gibbs,\n", - " delta_G=FloatSlider(value=0, min=-2e4, max=2e4, step=1000, description=\"ΔG° (J/mol)\")\n", + " delta_G=FloatSlider(value=0, min=-2e4, max=2e4, step=10, description=\"ΔG° (J/mol)\")\n", ");" ] }