Skip to content

Commit

Permalink
derivatives
Browse files Browse the repository at this point in the history
  • Loading branch information
SouthEndMusic committed Nov 25, 2024
1 parent ec4c113 commit 97de11c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
13 changes: 13 additions & 0 deletions src/derivatives.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@ function _derivative(A::LinearInterpolation, t::Number, iguess)
slope
end

function _derivative(A::SmoothedConstantInterpolation{<:AbstractVector}, t::Number, iguess)
idx = get_idx(A, t, iguess)
d_lower, d_upper, c_lower, c_upper = get_parameters(A, idx)

if (t - A.t[idx]) < d_lower
-2c_lower * ((t - A.t[idx]) / d_lower - 1) / d_lower
elseif (A.t[idx + 1] - t) < d_upper
2c_upper * (1 - (A.t[idx + 1] - t) / d_upper) / d_upper
else
zero(c_upper / oneunit(t))
end
end

function _derivative(A::QuadraticInterpolation, t::Number, iguess)
idx = get_idx(A, t, iguess)
Δt = t - A.t[idx]
Expand Down
6 changes: 3 additions & 3 deletions src/interpolation_caches.jl
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ end
cache_parameters = false, assume_linear_t = 1e-2)
It is a method for interpolating constantly with forward fill, with smoothing around the
value transitions to make the curve C1 smooth while the integral never drifts far from
value transitions to make the curve C1 smooth while the integral never drifts far from
the integral of constant interpolation.
## Arguments
Expand All @@ -300,10 +300,10 @@ the integral of constant interpolation.
## Keyword Arguments
- `d_max`: the maximum distance in `t` from the data points the smoothing is allowed to reach.
- `d_max`: the maximum distance in `t` from the data points the smoothing is allowed to reach.
- `extrapolate`: boolean value to allow extrapolation. Defaults to `false`.
- `cache_parameters`: precompute parameters at initialization for faster interpolation computations. Note: if activated, `u` and `t` should not be modified. Defaults to `false`.
- `assume_linear_t`: boolean value to specify a faster index lookup behaviour for
- `assume_linear_t`: boolean value to specify a faster index lookup behavior for
evenly-distributed abscissae. Alternatively, a numerical threshold may be specified
for a test based on the normalized standard deviation of the difference with respect
to the straight line (see [`looks_linear`](@ref)). Defaults to 1e-2.
Expand Down
4 changes: 2 additions & 2 deletions src/interpolation_methods.jl
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ function _interpolate(A::SmoothedConstantInterpolation{<:AbstractVector}, t::Num
out = A.u[idx]

if (t - A.t[idx]) < d_lower
out -= c_lower * (((t - A.t[idx]) / d_lower - 1))^2
out -= c_lower * ((t - A.t[idx]) / d_lower - 1)^2
elseif (A.t[idx + 1] - t) < d_upper
out += c_upper * ((1 - (A.t[idx + 1] - t) / d_upper))^2
out += c_upper * (1 - (A.t[idx + 1] - t) / d_upper)^2
end

out
Expand Down

0 comments on commit 97de11c

Please sign in to comment.