.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/thermo/equilibrium/plot_01_law_of_mass_action.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_api_gallery_thermo_equilibrium_plot_01_law_of_mass_action.py: Guldberg and Waage's law of mass action: Q = K at equilibrium ============================================================= For :math:`N_2O_4 \rightleftharpoons 2NO_2` the reaction quotient :math:`Q = x_{NO_2}^2/x_{N_2O_4}` (at :math:`P = P^\circ`), computed by :func:`~chemistrykit.thermo.systems.equilibrium.reaction_quotient`, rises monotonically with the extent of reaction. The law of mass action says the mixture stops changing where :math:`Q` reaches the equilibrium constant :math:`K`. Starting from different mixtures of reactant and product, the equilibrium compositions found by :func:`~chemistrykit.thermo.systems.equilibrium.solve_equilibrium_composition` all give the same :math:`Q = K`. .. GENERATED FROM PYTHON SOURCE LINES 17-40 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from chemistrykit.constants import R from chemistrykit.thermo.systems.equilibrium import reaction_quotient, solve_equilibrium_composition T = 298.15 K = 4.0 gibbs_formation = [0.0, -R * T * np.log(K) / 2.0] # [N2O4, NO2] nu = np.array([-1.0, 2.0]) xi = np.linspace(0.01, 0.99, 300) Q = [reaction_quotient([(1 - x) / (1 + x), 2 * x / (1 + x)], nu) for x in xi] fig, ax = plt.subplots(figsize=(7, 5)) ax.semilogy(xi, Q, color="steelblue", label=r"$Q(\xi)$ starting from pure $N_2O_4$") ax.axhline(K, color="crimson", linestyle="--", label=f"K = {K}") ax.set_xlabel(r"extent of reaction $\xi$ (mol)") ax.set_ylabel("reaction quotient Q") ax.set_title(r"$N_2O_4 \rightleftharpoons 2NO_2$: the reaction stops where Q = K") ax.legend() fig.tight_layout() .. image-sg:: /api/gallery/thermo/equilibrium/images/sphx_glr_plot_01_law_of_mass_action_001.png :alt: $N_2O_4 \rightleftharpoons 2NO_2$: the reaction stops where Q = K :srcset: /api/gallery/thermo/equilibrium/images/sphx_glr_plot_01_law_of_mass_action_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 41-44 Different starting mixtures end with different amounts of each gas, but always with the same value of the mass-action ratio (at fixed total pressure, that also pins the mole fractions): .. GENERATED FROM PYTHON SOURCE LINES 44-51 .. code-block:: Python for n0 in ([1.0, 0.0], [0.05, 1.9], [1.0, 1.0], [0.2, 3.0]): res = solve_equilibrium_composition(("N2O4", "NO2"), [[-1.0], [2.0]], n0, gibbs_formation, T) Q_eq = reaction_quotient(res.x, nu) print(f"start n = {n0}: equilibrium n = {np.round(res.n, 4)} mol, Q = {Q_eq:.4f}") plt.show() .. rst-class:: sphx-glr-script-out .. code-block:: none start n = [1.0, 0.0]: equilibrium n = [0.2929 1.4142] mol, Q = 3.9999 start n = [0.05, 1.9]: equilibrium n = [0.2929 1.4142] mol, Q = 4.0000 start n = [1.0, 1.0]: equilibrium n = [0.4393 2.1213] mol, Q = 4.0000 start n = [0.2, 3.0]: equilibrium n = [0.4979 2.4042] mol, Q = 4.0000 .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.076 seconds) .. _sphx_glr_download_api_gallery_thermo_equilibrium_plot_01_law_of_mass_action.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_01_law_of_mass_action.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_01_law_of_mass_action.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_01_law_of_mass_action.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_