.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/topology/surfaces/plot_04_morse_banchoff_critical_points.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 or to run this example in your browser via JupyterLite. .. rst-class:: sphx-glr-example-title .. _sphx_glr_api_gallery_topology_surfaces_plot_04_morse_banchoff_critical_points.py: Morse theory and Banchoff's critical points (1925-1967) ======================================================= Morse related the critical points of a function on a manifold to its topology: the alternating count of minima, saddles and maxima is the Euler characteristic. Banchoff found the polyhedral version. Charge each simplex to its highest vertex, and a vertex's index is the alternating count of what it receives. On an upright torus the height has one minimum, two saddles and one maximum (:math:`1 - 2 + 1 = 0`). A wobblier height function has more critical points, but the alternating sum stays at 0. .. GENERATED FROM PYTHON SOURCE LINES 16-43 .. image-sg:: /api/gallery/topology/surfaces/images/sphx_glr_plot_04_morse_banchoff_critical_points_001.png :alt: Critical points of any height function sum to χ(torus) = 0, height x: 1 - 2 + 1 = 0, wobbly height: 4 - 8 + 4 = 0 :srcset: /api/gallery/topology/surfaces/images/sphx_glr_plot_04_morse_banchoff_critical_points_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none height x: 1 minima, 2 saddles, 1 maxima; total index 0 wobbly height: 4 minima, 8 saddles, 4 maxima; total index 0 Text(0.5, 0.98, 'Critical points of any height function sum to χ(torus) = 0') | .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from mathematicskit.topology import critical_points, torus from mathematicskit.topology.visualizers import plot_complex T = torus(32, 16) x, y, z = T.coordinates.T heights = { "height x": x + 1e-3 * z, "wobbly height": x + 0.6 * np.sin(3 * y) + 0.3 * z, } fig = plt.figure(figsize=(12, 5)) for i, (name, h) in enumerate(heights.items()): result = critical_points(T, h) print(f"{name}: {len(result.minima)} minima, {len(result.saddles)} saddles, {len(result.maxima)} maxima; total index {result.euler_characteristic}") ax = fig.add_subplot(1, 2, i + 1, projection="3d", computed_zorder=False) plot_complex(T, ax=ax, face_values=[h[list(t)].mean() for t in T.simplices(2)], alpha=0.55, vertex_size=0) for vertices, color, label in ((result.minima, "tab:blue", "minimum"), (result.saddles, "tab:red", "saddle"), (result.maxima, "gold", "maximum")): ax.scatter(*T.coordinates[vertices].T, s=60, color=color, edgecolors="k", depthshade=False, label=label) ax.view_init(elev=40, azim=-90) ax.set_box_aspect((1, 1, 1), zoom=1.4) ax.set_axis_off() ax.set_title(f"{name}: {len(result.minima)} - {len(result.saddles)} + {len(result.maxima)} = {result.euler_characteristic}") ax.legend(loc="lower left", fontsize=8) fig.suptitle("Critical points of any height function sum to χ(torus) = 0") .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.080 seconds) .. _sphx_glr_download_api_gallery_topology_surfaces_plot_04_morse_banchoff_critical_points.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: lite-badge .. image:: images/jupyterlite_badge_logo.svg :target: ../../../../lite/lab/index.html?path=api/gallery/topology/surfaces/plot_04_morse_banchoff_critical_points.ipynb :alt: Launch JupyterLite :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_04_morse_banchoff_critical_points.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_04_morse_banchoff_critical_points.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_04_morse_banchoff_critical_points.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_