Skip to content

Commit

Permalink
feat: add integral for AkimaInterpolation
Browse files Browse the repository at this point in the history
  • Loading branch information
sathvikbhagavan committed Nov 18, 2023
1 parent ba31e21 commit 4e4d324
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/integrals.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
function integral(A::AbstractInterpolation, t::Number)
bw, fw = samples(A)
idx = max(1 + bw, min(searchsortedlast(A.t, t), length(A.t) - fw))
_integral(A, idx, t)
((t < A.t[1] || t > A.t[end]) && !A.extrapolate) && throw(ExtrapolationError())
integral(A, A.t[1], t)
end

function integral(A::AbstractInterpolation, t1::Number, t2::Number)
((t1 < A.t[1] || t1 > A.t[end]) && !A.extrapolate) && throw(ExtrapolationError())
((t2 < A.t[1] || t2 > A.t[end]) && !A.extrapolate) && throw(ExtrapolationError())
bw, fw = samples(A)
# the index less than or equal to t1
idx1 = max(1 + bw, min(searchsortedlast(A.t, t1), length(A.t) - fw))
Expand Down Expand Up @@ -97,5 +98,11 @@ function _integral(A::CubicSpline{<:AbstractVector{<:Number}}, idx::Number, t::N
(6 * h2))
end

samples(A::AkimaInterpolation{<:AbstractVector{<:Number}}) = (0, 1)
function _integral(A::AkimaInterpolation{<:AbstractVector{<:Number}}, idx::Number, t::Number)
t1 = A.t[idx]
A.u[idx]*(t - t1) + A.b[idx]*((t - t1)^2/2) + A.c[idx]*((t - t1)^3/3) + A.d[idx]*((t - t1)^4/4)
end

integral(A::LagrangeInterpolation, t1::Number, t2::Number) = throw(IntegralNotFoundError())
integral(A::LagrangeInterpolation, t::Number) = throw(IntegralNotFoundError())

0 comments on commit 4e4d324

Please sign in to comment.