-
-
Notifications
You must be signed in to change notification settings - Fork 47
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
Comments
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″") 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? |
You only plot the interpolation in the data points, which is misleading. Have a look at this: using DataInterpolations, Plots
t = 0.0:0.1:1.0
y = @. t^2 # -> y′ = 2*t, y″ = 2
yspl = CubicSpline(y, t)
t_eval = 0.0:0.001:1.0
plot(yspl; label = "yspl") # Uses plotting recipe
plot!(t_eval, DataInterpolations.derivative.(Ref(yspl), t_eval, 1), label = "yspl′")
plot!(t_eval, DataInterpolations.derivative.(Ref(yspl), t_eval, 2), label = "yspl″")
plot!(t_eval, t_eval.^2, label = "y", ls = :dash)
plot!(t_eval, 2*t_eval, label = "y′", ls = :dash)
plot!(t_eval, fill(2, length(t_eval)), label = "y″", ls = :dash) Because of how using DataInterpolations, Plots
t = 0.0:0.1:1.0
y = t.^2
y′ = 2*t
A = CubicHermiteSpline(y′, y, t)
t_eval = 0.0:0.001:1.0
plot(A; label = "CubicHermiteSpline") # Uses plotting recipe
plot!(t_eval, DataInterpolations.derivative.(Ref(A), t_eval, 1); label = "CubicHermiteSpline′")
plot!(t_eval, DataInterpolations.derivative.(Ref(A), t_eval, 2); label = "CubicHermiteSpline″")
plot!(t_eval, t_eval.^2; ls = :dash, label = "y")
plot!(t_eval, 2 * t_eval; ls = :dash, label = "y′")
plot!(t_eval, fill(2, length(t_eval)); ls = :dash, label = "y″") |
Thank you very much. I'm integrating ODEs, so I know the derivative, and will try to adapt to hermite splines. |
The second derivative is very noisy near the spline endpoints:
The first derivative looks much better, but also looks more kinky than it should near the ends (?) 🙂
The text was updated successfully, but these errors were encountered: