.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_basis_sets.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_auto_examples_plot_basis_sets.py: Basis Sets Visualization ======================== This example demonstrates how different basis sets look for polynomial orders. We compare Lagrange, Legendre, and Bernstein-type bases using different node distributions (uniform, Gauss, Gauss-Lobatto, Chebyshev-Gauss). The basis values are sampled at the integration points (nodes), and the functions are visualized on the reference interval [-1, 1]. .. GENERATED FROM PYTHON SOURCE LINES 12-19 .. code-block:: Python # Assume classes are defined in fdg import numpy as np from fdg import BasisSpecs, BasisType from matplotlib import pyplot as plt from matplotlib.axes import Axes .. GENERATED FROM PYTHON SOURCE LINES 20-22 Helper function to plot a basis set ----------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 22-56 .. code-block:: Python def plot_basis_set(basis_type: BasisType, order: int, ax: Axes) -> None: """Plot basis in the set.""" basis_specs = BasisSpecs(basis_type, order) x = np.linspace(-1, +1, 200) v = basis_specs.values(x) for i in range(v.shape[-1]): ax.plot(x, v[..., i], label=f"ϕ_{i}") ax.set_title(f"{basis_type.value}, order={order}") ax.set_xlim(-1, +1) ax.set_ylim(-1.2, +1.2) ax.legend() ax.grid(True) def plot_basis_set_derivatives(basis_type: BasisType, order: int, ax: Axes) -> None: """Plot basis derivatives in the set.""" basis_specs = BasisSpecs(basis_type, order) x = np.linspace(-1, +1, 200) v = basis_specs.derivatives(x) for i in range(v.shape[-1]): ax.plot(x, v[..., i], label=f"ϕ_{i}") ax.set_title(f"{basis_type.value}, order={order}") ax.set_xlim(-1, +1) ax.set_ylim(-2, +2) ax.legend() ax.grid(True) .. GENERATED FROM PYTHON SOURCE LINES 57-59 Specify Config -------------- .. GENERATED FROM PYTHON SOURCE LINES 59-62 .. code-block:: Python ORDER = 5 .. GENERATED FROM PYTHON SOURCE LINES 63-65 Compare different basis types ----------------------------- .. GENERATED FROM PYTHON SOURCE LINES 65-79 .. code-block:: Python fig, axes = plt.subplots(2, 3, figsize=(12, 8), sharey=True) for ax, btype in zip(axes.flat, BasisType): plot_basis_set(BasisType(btype), order=ORDER, ax=ax) fig.suptitle(f"Comparison of Basis Sets for {ORDER=}", fontsize=14) fig.tight_layout(rect=(0, 0.05, 1, 0.95)) # plt.show() .. image-sg:: /auto_examples/images/sphx_glr_plot_basis_sets_001.png :alt: Comparison of Basis Sets for ORDER=5, legendre, order=5, bernstein, order=5, lagrange-uniform, order=5, lagrange-gauss, order=5, lagrange-gauss-lobatto, order=5, lagrange-chebyshev-gauss, order=5 :srcset: /auto_examples/images/sphx_glr_plot_basis_sets_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 80-82 Compare derivatives of different basis types -------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 82-93 .. code-block:: Python fig, axes = plt.subplots(2, 3, figsize=(12, 8), sharey=True) for ax, btype in zip(axes.flat, BasisType): plot_basis_set_derivatives(BasisType(btype), order=ORDER, ax=ax) fig.suptitle(f"Comparison of Basis Set derivatives for {ORDER=}", fontsize=14) fig.tight_layout(rect=(0, 0.05, 1, 0.95)) plt.show() .. image-sg:: /auto_examples/images/sphx_glr_plot_basis_sets_002.png :alt: Comparison of Basis Set derivatives for ORDER=5, legendre, order=5, bernstein, order=5, lagrange-uniform, order=5, lagrange-gauss, order=5, lagrange-gauss-lobatto, order=5, lagrange-chebyshev-gauss, order=5 :srcset: /auto_examples/images/sphx_glr_plot_basis_sets_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.526 seconds) .. _sphx_glr_download_auto_examples_plot_basis_sets.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_basis_sets.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_basis_sets.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_basis_sets.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_