Skip to content

Commit 66ae918

Browse files
committed
Fix extrapolation derivatives
1 parent 2262c6c commit 66ae918

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/derivatives.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,24 @@ function _extrapolate_derivative_right(A, t, order)
7474
end
7575
end
7676

77+
function _extrapolate_derivative_right(A::SmoothedConstantInterpolation, t, order)
78+
if A.extrapolation_right == ExtrapolationType.None
79+
throw(RightExtrapolationError())
80+
elseif A.extrapolation_right in (
81+
ExtrapolationType.Constant, ExtrapolationType.Extension)
82+
d = min(A.t[end] - A.t[end - 1], 2A.d_max) / 2
83+
if A.t[end] + d < t
84+
zero(eltype(A.u))
85+
else
86+
c = (A.u[end] - A.u[end - 1]) / 2
87+
c * (2((t - A.t[end]) / d) - 2)
88+
end
89+
90+
else
91+
_extrapolate_other(A, t, A.extrapolation_right)
92+
end
93+
end
94+
7795
function _derivative(A::LinearInterpolation, t::Number, iguess)
7896
idx = get_idx(A, t, iguess; idx_shift = -1, ub_shift = -1, side = :first)
7997
slope = get_parameters(A, idx)

src/interpolation_methods.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ function _extrapolate_right(A::SmoothedConstantInterpolation, t)
8484
A.u[end]
8585
else
8686
c = (A.u[end] - A.u[end - 1]) / 2
87-
A.u[end - 1] - c * (((t - A.t[end]) / d)^2 - 2 * ((t - A.t[end]) / d) - 1)
87+
-c * (((t - A.t[end]) / d)^2 - 2 * ((t - A.t[end]) / d) - 1)
8888
end
8989

9090
else

0 commit comments

Comments
 (0)