Best way to take derivatives of unevenly spaced data (with interpolations? discrete derivatives?)

You could use Roots.jl to find zeros of the first derivative of the spline.

Here is a quick example using Newton’s method:

using BSplineKit
using Roots

f(x) = cos(4π * x) * exp(-4x)

xs = 0:0.05:1
S = spline(interpolate(xs, f.(xs), BSplineOrder(6)))

S′ = diff(S, Derivative(1))
S″ = diff(S, Derivative(2))

x₀ = 0.5  # initial guess for Newton method
x = find_zero((S′, S″), x₀, Roots.Newton())  # 0.47547599925831957
S(x)   # 0.1422509042378483
S′(x)  # -1.5265566588595902e-16
2 Likes