Skip to content

Instantly share code, notes, and snippets.

View VictorSeven's full-sized avatar

Victor Buendía VictorSeven

View GitHub Profile
@VictorSeven
VictorSeven / gist:996e0745e820dde0610ada9e9e025844
Created March 7, 2024 18:47
Julia's numerical derivative following Numpy gradient
function numerical_derivative(y, x)
"""
Compute the derivative of the function y(x) which has been sampled in discrete steps. The implementation here has
been adapted from Numpy's gradient function (centered finite differences). Boundaries have just forward differences.
It works only for 1D functions, but should be possible to easily extend to other things.
"""
#Create target vector
n = length(x)
derivs = Vector{Float64}(undef, n)