.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/triplets/plot_triplets_0.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_gallery_triplets_plot_triplets_0.py: Example: triplets 0 =================== In this example, we generate a finite difference instance and visualize the resulting triplets. The boundary conditions, derivative, and accuracy settings are specified for demonstration purposes. .. GENERATED FROM PYTHON SOURCE LINES 10-17 .. list-table:: Finite-difference parameters :widths: 25 :header-rows: 1 * - boundaries: {left: 0, right: 0, top: 0, bottom: 0} * - derivative: 2 * - accuracy: 4 .. GENERATED FROM PYTHON SOURCE LINES 19-22 Importing required packages --------------------------- Here we import the necessary libraries for numerical computations and finite difference operations. .. GENERATED FROM PYTHON SOURCE LINES 22-26 .. code-block:: Python from PyFinitDiff.finite_difference_2D import FiniteDifference, Boundaries import matplotlib.pyplot as plt .. GENERATED FROM PYTHON SOURCE LINES 27-30 Setting up the finite difference instance and boundaries --------------------------------------------------------- We define the grid size and set up the finite difference instance with specified boundary conditions. .. GENERATED FROM PYTHON SOURCE LINES 30-41 .. code-block:: Python sparse_instance = FiniteDifference( n_x=20, n_y=20, dx=1, dy=1, derivative=2, accuracy=2, boundaries=Boundaries() ) .. GENERATED FROM PYTHON SOURCE LINES 42-45 Visualizing the triplets with matplotlib ----------------------------------------- We plot the triplets using matplotlib to visualize the finite difference operator. .. GENERATED FROM PYTHON SOURCE LINES 45-51 .. code-block:: Python sparse_instance.triplet.plot() plt.show() # - .. image-sg:: /gallery/triplets/images/sphx_glr_plot_triplets_0_001.png :alt: Finite-difference coefficients structure :srcset: /gallery/triplets/images/sphx_glr_plot_triplets_0_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.645 seconds) .. _sphx_glr_download_gallery_triplets_plot_triplets_0.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_triplets_0.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_triplets_0.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_triplets_0.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_