.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/thermo/equilibrium/plot_03_van_t_hoff_plot.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_03_van_t_hoff_plot.py: The van't Hoff plot: ln K against 1/T ===================================== van't Hoff's equation :math:`d\ln K/dT = \Delta H^\circ/(RT^2)` makes :math:`\ln K` a straight line in :math:`1/T` with slope :math:`-\Delta H^\circ/R` and intercept :math:`\Delta S^\circ/R`. This example generates noisy equilibrium constants for :math:`N_2O_4 \rightleftharpoons 2NO_2` from :func:`~chemistrykit.thermo.systems.equilibrium.van_t_hoff_equilibrium_constant` and recovers the reaction enthalpy and entropy with :func:`~chemistrykit.thermo.systems.equilibrium.fit_van_t_hoff`. .. GENERATED FROM PYTHON SOURCE LINES 16-43 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from chemistrykit.constants import R from chemistrykit.thermo.systems.equilibrium import fit_van_t_hoff, van_t_hoff_equilibrium_constant dH_true, dS_true = 57_200.0, 175.8 T_ref = 298.15 K_ref = np.exp(-(dH_true - T_ref * dS_true) / (R * T_ref)) rng = np.random.default_rng(1) T_data = np.linspace(280.0, 360.0, 9) K_data = van_t_hoff_equilibrium_constant(T_data, T_ref=T_ref, K_ref=K_ref, delta_h=dH_true) K_data = K_data * np.exp(rng.normal(scale=0.05, size=T_data.size)) # 5% multiplicative noise fit = fit_van_t_hoff(T_data, K_data) fig, ax = plt.subplots(figsize=(7, 5)) ax.scatter(1000.0 / T_data, np.log(K_data), label="noisy data") T_line = np.linspace(T_data.min(), T_data.max(), 100) ax.plot(1000.0 / T_line, np.log(fit.predict(T_line)), color="crimson", label=rf"fit: $\Delta H^\circ$ = {fit.delta_h / 1000:.1f} kJ/mol") ax.set_xlabel("1000 / T (1/K)") ax.set_ylabel("ln K") ax.set_title(r"van't Hoff plot for $N_2O_4 \rightleftharpoons 2NO_2$") ax.legend() fig.tight_layout() .. image-sg:: /api/gallery/thermo/equilibrium/images/sphx_glr_plot_03_van_t_hoff_plot_001.png :alt: van't Hoff plot for $N_2O_4 \rightleftharpoons 2NO_2$ :srcset: /api/gallery/thermo/equilibrium/images/sphx_glr_plot_03_van_t_hoff_plot_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 44-48 .. code-block:: Python print(f"fitted dH = {fit.delta_h / 1000:.2f} kJ/mol (true {dH_true / 1000:.2f})") print(f"fitted dS = {fit.delta_s:.1f} J/(mol K) (true {dS_true:.1f}); R^2 = {fit.r_squared:.4f}") plt.show() .. rst-class:: sphx-glr-script-out .. code-block:: none fitted dH = 57.14 kJ/mol (true 57.20) fitted dS = 175.7 J/(mol K) (true 175.8); R^2 = 0.9996 .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.039 seconds) .. _sphx_glr_download_api_gallery_thermo_equilibrium_plot_03_van_t_hoff_plot.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_03_van_t_hoff_plot.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_03_van_t_hoff_plot.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_03_van_t_hoff_plot.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_