Worked Examples: Arithmetic#
These worked solutions correspond to the exercises on the Arithmetic page.
How to use this notebook:
Try each exercise yourself first before looking at the solution
The code cells show both the code and its output
Download this notebook if you want to run and experiment with the code yourself
Your solution might look different - that’s fine as long as it gives the correct answer!
Setup#
We’ll import the math
module here for use throughout the exercises.
import math
Exercise 1: Order of Operations (BODMAS)#
Problem: Without using a computer or calculator, calculate the following following the BODMAS order of operations:
\(24\,/\,(10 + 2)\)
\(5 + 16\,/\, 2 \times 3\)
\([32 \,/\, (6 + 2)]^2\)
Let’s verify the answers using Python.
Part (a): \(24\,/\,(10 + 2)\)#
24 / (10 + 2)
2.0
Working:
Brackets first: \((10 + 2) = 12\)
Division: \(24 / 12 = 2\)
Answer: \(2\) (Note that Python produces a float when we divide)
Part (b): \(5 + 16\,/\, 2 \times 3\)#
5 + 16 / 2 * 3
29.0
Working:
Following BODMAS (Brackets, Order, Division/Multiplication, Addition/Subtraction):
Division: \(16 / 2 = 8\)
Multiplication: \(8 \times 3 = 24\)
Addition: \(5 + 24 = 29\)
Important: Division and multiplication have equal priority and are evaluated left to right.
Answer: \(29.0\)
Part (c): \([32 \,/\, (6 + 2)]^2\)#
(32 / (6 + 2)) ** 2
16.0
Working:
Inner brackets first: \((6 + 2) = 8\)
Division: \(32 / 8 = 4\)
Order (exponent): \(4^2 = 16\)
Answer: \(16.0\)
Exercise 2: Chemical Calculations#
This exercise involves three separate chemical calculations using Python.
Part 1: Energy of Radiation#
Problem: Calculate the energy (in Joules) of radiation with wavenumber \(\bar{\nu} = 1700\) cm\(^{-1}\) using:
where:
\(h\) = Planck’s constant = \(6.626 \times 10^{-34}\) J s
\(c\) = speed of light = \(3 \times 10^{10}\) cm/s
\(\bar{\nu}\) = \(1700\) cm\(^{-1}\)
Solution:
# Define constants
h = 6.626e-34 # J s
c = 3e10 # cm/s
wavenumber = 1700 # /cm
# Calculate energy
energy = h * c * wavenumber
print(f"Energy = {energy} J")
print(f"Energy = {energy:.3e} J") # Scientific notation
Energy = 3.37926e-20 J
Energy = 3.379e-20 J
Explanation:
We use scientific notation:
3e10
means \(3 \times 10^{10}\)Be careful with units: here we’re using cm/s for \(c\) to match the wavenumber units (cm\(^{-1}\))
The energy is very small (about \(3.38 \times 10^{-20}\) J), which is typical for a single photon
We use f-strings with
:.3e
to format the output in scientific notation with 3 decimal places
Part 2: pH Calculation#
Problem: Calculate the pH when the hydronium ion concentration is \([\text{H}_3\text{O}^+] = 1.524 \times 10^{-5}\) M using:
$\(\text{pH} = -\log_{10}[\text{H}_3\text{O}^+]\)$’
Solution:
# Define concentration
concentration = 1.524e-5 # M
# Calculate pH
pH = -math.log10(concentration)
print(f"pH = {pH:.2f}")
pH = 4.82
Explanation:
We use
math.log10()
for the base-10 logarithmThe negative sign is important - we need \(-\log_{10}\), not \(\log_{10}\)
A pH of about 4.8 indicates a weakly acidic solution
Common mistake: Using math.log()
instead of math.log10()
. Remember:
math.log()
gives the natural logarithm (base \(\mathrm{e}\))math.log10()
gives the base-10 logarithm
Part 3: Lennard-Jones Potential#
Problem: Calculate the potential energy (in Joules) between two argon atoms at distance \(r = 2\) Å using the Lennard-Jones potential:
where:
\(A = 1.36 \times 10^{-134}\) J m\(^{12}\)
\(B = 9.27 \times 10^{-78}\) J m\(^6\)
\(r = 2\) Å \(= 2 \times 10^{-10}\) m
Solution:
# Define parameters
A = 1.36e-134 # J m^12
B = 9.27e-78 # J m^6
r = 2e-10 # m (2 Angstroms)
# Calculate energy
energy = A / (r ** 12) - B / (r ** 6)
print(f"Energy = {energy} J")
print(f"Energy = {energy:.3e} J")
Energy = 3.175468749999998e-18 J
Energy = 3.175e-18 J
Exercise 3: Gibbs Free Energy and Equilibrium#
Problem: The standard Gibbs free energy for a reaction at a particular temperature is related to the equilibrium constant at that temperature via,
For the reaction:
The standard free energies of formation, \(\Delta G_f^\circ\), for each reactant are given below:
PCl\(_3\): \(-267.8\)
PCl\(_5\): \(-305.0\)
Cl\(_2\): \(0\)
Part 1: Use Hess’s law to find the equilibrium constant \(K\) at 298 K.
Part 2: Given that \(\Delta G_r = -20.2\) kJ/mol at 350 K, and assuming \(\Delta H\) and \(\Delta S\) are temperature-independent, calculate \(\Delta H^\circ\) at 298 K.
Use the relation \(\Delta G = \Delta H - T\Delta S\)
Part 1: Calculate Equilibrium Constant at 298 K#
Step 1: Calculate \(\Delta G_r^\circ\) at 298 K using Hess’s law:
# Standard free energies of formation at 298 K (kJ/mol)
dg_f_PCl3 = -267.8
dg_f_PCl5 = -305.0
dg_f_Cl2 = 0
# Calculate reaction free energy
dg_rxn_298 = dg_f_PCl5 - (dg_f_PCl3 + dg_f_Cl2)
print(f"ΔG°(298 K) = {dg_rxn_298:.1f} kJ/mol")
ΔG°(298 K) = -37.2 kJ/mol
Step 2: Calculate the equilibrium constant using:
Rearranging:
# Constants
R = 8.314e-3 # kJ/(mol·K) - note the unit conversion!
T_298 = 298 # K
# Calculate equilibrium constant
K = math.exp(-dg_rxn_298 / (R * T_298))
print(f"K = {K:.2e}")
K = 3.32e+06
Part 2: Calculate \(\Delta H^\circ\) at 298 K#
Strategy: We have two equations and two unknowns (\(\Delta H\) and \(\Delta S\)):
At 298 K: \(\Delta G_{298} = \Delta H - 298\Delta S\)
At 350 K: \(\Delta G_{350} = \Delta H - 350\Delta S\)
We can solve for \(\Delta H\) by eliminating \(\Delta S\).
Derivation:
Subtracting the equations:
Therefore:
Substituting back into the first equation:
Simplifying:
# Given data
dg_298 = dg_rxn_298 # From part (a): -37.2 kJ/mol
dg_350 = -20.2 # kJ/mol
T_298 = 298 # K
T_350 = 350 # K
# Calculate ΔH using our derived formula
delta_H = (T_298 * (dg_298 - dg_350) / (T_350 - T_298)) + dg_298
print(f"ΔH° = {delta_H:.2f} kJ/mol")
ΔH° = -134.62 kJ/mol
# Verify by calculating ΔS
delta_S = (dg_298 - dg_350) / (T_350 - T_298)
print(f"ΔS° = {delta_S:.4f} kJ/(mol·K)")
print(f"ΔS° = {delta_S * 1000:.2f} J/(mol·K)")
# Check: does ΔG = ΔH - TΔS at both temperatures?
print(f"\nVerification:")
print(f"At 298 K: ΔG = {delta_H - T_298 * delta_S:.2f} kJ/mol (should be {dg_298:.2f})")
print(f"At 350 K: ΔG = {delta_H - T_350 * delta_S:.2f} kJ/mol (should be {dg_350:.2f})")
ΔS° = -0.3269 kJ/(mol·K)
ΔS° = -326.92 J/(mol·K)
Verification:
At 298 K: ΔG = -37.20 kJ/mol (should be -37.20)
At 350 K: ΔG = -20.20 kJ/mol (should be -20.20)
Exercise 4: Ideal Gas Law#
Problem: Using the ideal gas law \(PV = nRT\), calculate:
The pressure \(P\) in atm
Convert this pressure to kPa
Given:
\(R = 0.08206\) L atm K\(^{-1}\) mol\(^{-1}\)
\(n = 2.5\) mol
\(T = 300\) K
\(V = 10.0\) L
Also given: 1 atm = 101.325 kPa
Step 1: Calculate Pressure in atm#
Rearranging the ideal gas law:
# Given values
R = 0.08206 # L atm K^-1 mol^-1
n = 2.5 # mol
T = 300 # K
V = 10.0 # L
# Calculate pressure
P_atm = (n * R * T) / V
print(f"Pressure = {P_atm:.3f} atm")
Pressure = 6.155 atm
Step 2: Convert to kPa#
# Conversion factor
atm_to_kPa = 101.325 # kPa per atm
# Convert pressure
P_kPa = P_atm * atm_to_kPa
print(f"Pressure = {P_kPa:.2f} kPa")
Pressure = 623.60 kPa
Complete solution showing all steps:
# Given values
R = 0.08206 # L atm K^-1 mol^-1
n = 2.5 # mol
T = 300 # K
V = 10.0 # L
atm_to_kPa = 101.325 # Conversion factor
# Step 1: Calculate pressure in atm
P_atm = (n * R * T) / V
# Step 2: Convert to kPa
P_kPa = P_atm * atm_to_kPa
# Display results
print("Ideal Gas Law Calculation")
print("=" * 30)
print(f"Number of moles (n): {n} mol")
print(f"Temperature (T): {T} K")
print(f"Volume (V): {V} L")
print(f"Gas constant (R): {R} L atm K⁻¹ mol⁻¹")
print(f"\nPressure: {P_atm:.3f} atm")
print(f"Pressure: {P_kPa:.2f} kPa")
Ideal Gas Law Calculation
==============================
Number of moles (n): 2.5 mol
Temperature (T): 300 K
Volume (V): 10.0 L
Gas constant (R): 0.08206 L atm K⁻¹ mol⁻¹
Pressure: 6.155 atm
Pressure: 623.60 kPa
Note: Unit consistency is crucial: The value of \(R\) we use determines our pressure units
Using \(R = 0.08206\) L atm K\(^{-1}\) mol\(^{-1}\) gives pressure in atm
If we used \(R = 8.314\) J K\(^{-1}\) mol\(^{-1}\), we’d get pressure in Pa (with volume in m\(^3\))