Note
Go to the end to download the full example code.
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.
boundaries: {left: 0, right: 0, top: 0, bottom: 0} |
---|
derivative: 2 |
accuracy: 4 |
Importing required packages#
Here we import the necessary libraries for numerical computations and finite difference operations.
from PyFinitDiff.finite_difference_2D import FiniteDifference, Boundaries
import matplotlib.pyplot as plt
Setting up the finite difference instance and boundaries#
We define the grid size and set up the finite difference instance with specified boundary conditions.
sparse_instance = FiniteDifference(
n_x=20,
n_y=20,
dx=1,
dy=1,
derivative=2,
accuracy=2,
boundaries=Boundaries()
)
Visualizing the triplets with matplotlib#
We plot the triplets using matplotlib to visualize the finite difference operator.
sparse_instance.triplet.plot()
plt.show()
# -

Total running time of the script: (0 minutes 0.645 seconds)