.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/surface/freundlich/plot_01_freundlich_isotherm.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_surface_freundlich_plot_01_freundlich_isotherm.py: The Freundlich adsorption isotherm ===================================== :class:`~chemistrykit.surface.systems.freundlich.FreundlichIsotherm` models the empirical power law :math:`q=K_fP^{1/n}`, useful for a heterogeneous surface where Langmuir's single-site-energy assumption breaks down. Unlike Langmuir, it has no saturation limit, so extrapolating it far beyond the fitted pressure range is unphysical. :func:`~chemistrykit.surface.systems.freundlich.fit_freundlich` recovers `(Kf, n)` via the standard log q vs. log P linearization. .. GENERATED FROM PYTHON SOURCE LINES 15-26 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from chemistrykit.surface.systems.freundlich import FreundlichIsotherm, fit_freundlich from chemistrykit.surface.visualizers.surface_plots import plot_isotherm, plot_linearization Kf_true, n_true = 4.0, 2.5 iso = FreundlichIsotherm(Kf=Kf_true, n=n_true) print(f"Loading at P=1 (should equal Kf exactly): {iso.loading(1.0):.6f}") .. rst-class:: sphx-glr-script-out .. code-block:: none Loading at P=1 (should equal Kf exactly): 4.000000 .. GENERATED FROM PYTHON SOURCE LINES 27-36 .. code-block:: Python rng = np.random.default_rng(1) P_data = np.array([0.1, 0.25, 0.5, 1.0, 2.0, 4.0, 8.0]) q_data = iso.loading(P_data) * (1.0 + rng.normal(scale=0.01, size=P_data.shape)) fit = fit_freundlich(P_data, q_data) print(f"\nTrue (Kf, n) = ({Kf_true}, {n_true})") print(f"Fitted (Kf, n) = ({fit.Kf:.4f}, {fit.n:.4f})") print(f"R^2 of linearized fit: {fit.r_squared:.6f}") .. rst-class:: sphx-glr-script-out .. code-block:: none True (Kf, n) = (4.0, 2.5) Fitted (Kf, n) = (4.0055, 2.5087) R^2 of linearized fit: 0.999847 .. GENERATED FROM PYTHON SOURCE LINES 37-45 .. code-block:: Python fig, axes = plt.subplots(1, 2, figsize=(10, 4)) plot_isotherm(iso, P_max=10.0, P_data=P_data, q_data=q_data, ax=axes[0]) x_lin = np.log(P_data) y_lin = np.log(q_data) plot_linearization(x_lin, y_lin, fit=(1.0 / fit.n, np.log(fit.Kf)), ax=axes[1], xlabel="ln P", ylabel="ln q") plt.tight_layout() plt.show() .. image-sg:: /api/gallery/surface/freundlich/images/sphx_glr_plot_01_freundlich_isotherm_001.png :alt: FreundlichIsotherm isotherm, Isotherm linearization :srcset: /api/gallery/surface/freundlich/images/sphx_glr_plot_01_freundlich_isotherm_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.061 seconds) .. _sphx_glr_download_api_gallery_surface_freundlich_plot_01_freundlich_isotherm.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_freundlich_isotherm.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_01_freundlich_isotherm.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_01_freundlich_isotherm.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_