Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Second derivatives are very noisy near endpoints #370

Open
hersle opened this issue Dec 5, 2024 · 1 comment
Open

Second derivatives are very noisy near endpoints #370

hersle opened this issue Dec 5, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@hersle
Copy link

hersle commented Dec 5, 2024

The second derivative is very noisy near the spline endpoints:

using DataInterpolations, Plots
t = 0.0:0.01:1.0
y = @. t^2 # -> y′ = 2*t, y″ = 2
yspl = CubicSpline(y, t)
plot(t, yspl(t); label = "y")
plot!(t, t -> DataInterpolations.derivative(yspl, t, 1); label = "y′")
plot!(t, t -> DataInterpolations.derivative(yspl, t, 2); label = "y″")

image

The first derivative looks much better, but also looks more kinky than it should near the ends (?) 🙂

@hersle hersle added the bug Something isn't working label Dec 5, 2024
@hersle
Copy link
Author

hersle commented Dec 5, 2024

For comparison, it does not happen with cubic splines from e.g. Dierckx:

using Dierckx, Plots
t = 0.0:0.01:1.0
y = @. t^2 # -> y′ = 2*t, y″ = 2
yspl = Spline1D(t, y; k=3)
plot(t, yspl(t); label = "y")
plot!(t, t -> Dierckx.derivative(yspl, t; nu=1); label = "y′")
plot!(t, t -> Dierckx.derivative(yspl, t, nu=2); label = "y″")

bilde

Now that I have thought more about this: is this just an effect of the choice of boundary conditions on the splines, as in this thread? ?DataInterpolations.CubicSpline does say it is using natural boundary conditions, which means the second derivative is forced to 0 at the ends. I chose a function whose derivative is exactly 2 everywhere, so that must create some "tension" at the ends?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant