import numpy as np
import matplotlib.pyplot as plt
from cherab.inversion import Derivative

# Create a sample 1-D sine profile
x = np.linspace(0, 2 * np.pi, 100, endpoint=False)
y = np.sin(x)

# Calculate the derivative matrix
derivative = Derivative(x)
dmat = derivative.matrix_along_axis(0, boundary="dirichlet")

# Compare gradient values
plt.plot(x, y, label="y = sin(x)")
plt.plot(x, dmat @ y, label="y' = D @ y")
plt.plot(x, np.gradient(y, x), label="y' = np.gradient(y, x)", linestyle="--")
plt.legend()
plt.show()