From 4e4d32478fa6d95dcfe71d6592e29ca2543fa015 Mon Sep 17 00:00:00 2001 From: Sathvik Bhagavan Date: Sat, 18 Nov 2023 14:51:44 +0000 Subject: [PATCH] feat: add integral for AkimaInterpolation --- src/integrals.jl | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/integrals.jl b/src/integrals.jl index e1f663bd..1b91349f 100644 --- a/src/integrals.jl +++ b/src/integrals.jl @@ -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)) @@ -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())