.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/statmech/ising/plot_01_ising_chain_transfer_matrix.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_statmech_ising_plot_01_ising_chain_transfer_matrix.py: Ising's one-dimensional chain: no phase transition ===================================================== Ernst Ising (1925) solved the chain of spins :math:`s_i=\pm1` with nearest-neighbor coupling `J` and found no spontaneous magnetization at any temperature above zero. :class:`~chemistrykit.statmech.Ising1D` solves it with the 2x2 transfer matrix, whose eigenvalues :math:`\lambda_\pm` give :math:`Z_N=\lambda_+^N+\lambda_-^N` exactly. The plots show a checked partition function, a magnetization that is a smooth function of field at every temperature (it only becomes a step at :math:`T=0`), a correlation length that grows as :math:`e^{2J/k_BT}` but stays finite, and a smooth heat-capacity maximum instead of a singularity. .. GENERATED FROM PYTHON SOURCE LINES 17-27 .. code-block:: Python import itertools import matplotlib.pyplot as plt import numpy as np from chemistrykit.constants import K_B from chemistrykit.statmech import Ising1D J = 100.0 * K_B # coupling, J/k_B = 100 K .. GENERATED FROM PYTHON SOURCE LINES 28-29 The transfer-matrix result equals brute-force enumeration of all 2^N states: .. GENERATED FROM PYTHON SOURCE LINES 29-38 .. code-block:: Python N, T_check, h_check = 10, 150.0, 20.0 * K_B Z_exact = 0.0 for spins in itertools.product((-1, 1), repeat=N): s = np.array(spins) E = -J * np.sum(s * np.roll(s, 1)) - h_check * np.sum(s) Z_exact += np.exp(-E / (K_B * T_check)) print(f"brute force Z_10 = {Z_exact:.6e}, transfer matrix Z_10 = {Ising1D(J, h_check).partition_function(T_check, N):.6e}") .. rst-class:: sphx-glr-script-out .. code-block:: none brute force Z_10 = 1.123856e+04, transfer matrix Z_10 = 1.123856e+04 .. GENERATED FROM PYTHON SOURCE LINES 39-65 .. code-block:: Python fig, axes = plt.subplots(1, 3, figsize=(14, 4.2)) h = np.linspace(-50.0, 50.0, 400) * K_B for T, color in [(25.0, "crimson"), (50.0, "darkorange"), (100.0, "seagreen"), (300.0, "steelblue")]: m = np.array([Ising1D(J, hi).magnetization(T) for hi in h]) axes[0].plot(h / K_B, m, color=color, label=f"T = {T:.0f} K") axes[0].set_xlabel(r"field $h/k_B$ (K)") axes[0].set_ylabel("magnetization per spin") axes[0].set_title("m(h) is smooth for every T > 0") axes[0].legend() T = np.linspace(20.0, 400.0, 300) chain = Ising1D(J) axes[1].semilogy(T, chain.correlation_length(T), color="steelblue", label=r"exact $\xi = -1/\ln\tanh K$") axes[1].semilogy(T, 0.5 * np.exp(2 * J / (K_B * T)), color="gray", linestyle="--", label=r"$\frac{1}{2}e^{2J/k_BT}$") axes[1].set_xlabel("T (K)") axes[1].set_ylabel("correlation length (sites)") axes[1].set_title("Finite correlation length") axes[1].legend() axes[2].plot(T, chain.heat_capacity_per_spin(T) / K_B, color="crimson") axes[2].set_xlabel("T (K)") axes[2].set_ylabel(r"$c / k_B$ per spin") axes[2].set_title("Smooth heat capacity: no transition") fig.tight_layout() plt.show() .. image-sg:: /api/gallery/statmech/ising/images/sphx_glr_plot_01_ising_chain_transfer_matrix_001.png :alt: m(h) is smooth for every T > 0, Finite correlation length, Smooth heat capacity: no transition :srcset: /api/gallery/statmech/ising/images/sphx_glr_plot_01_ising_chain_transfer_matrix_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.141 seconds) .. _sphx_glr_download_api_gallery_statmech_ising_plot_01_ising_chain_transfer_matrix.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_ising_chain_transfer_matrix.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_01_ising_chain_transfer_matrix.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_01_ising_chain_transfer_matrix.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_