Inverting integrals

Solving implicit integral problems of the following form is supported:

\[\begin{equation} \text{find $t$ such that } \int_{t_1}^t f(\tau)\text{d}\tau = V \ge 0, \end{equation}\]

where $t_1$ is given by first(A.t). This is supported for interpolations $f$ that are strictly positive and of one of these types:

  • ConstantInterpolation
  • LinearInterpolation

This is achieved by creating an 'integral inverse' interpolation object which can efficiently compute $t$ for a given value of $V$, see the example below.

using DataInterpolations
using Plots

# Create LinearInterpolation object from the
u = sqrt.(1:25) + (2.0 * rand(25) .- 1.0) / 3
t = cumsum(rand(25))
A = LinearInterpolation(u, t)

# Create LinearInterpolationIntInv object
# from the LinearInterpolation object
A_intinv = DataInterpolations.invert_integral(A)

# Get the t values up to and including the
# solution to the integral problem
V = 25.0
t_ = A_intinv(V)
ts = t[t .<= t_]
push!(ts, t_)

# Plot results
plot(A; label = "Linear Interpolation")
plot!(ts, A.(ts), fillrange = 0.0, fillalpha = 0.75,
    fc = :blues, lw = 0, label = "Area of $V")
Example block output

Docstrings

DataInterpolations.invert_integralFunction
invert_integral(A::AbstractInterpolation)::AbstractIntegralInverseInterpolation

Creates the inverted integral interpolation object from the given interpolation. Conditions:

  • The range of A must be strictly positive
  • A.u must be a number type (on which an ordering is defined)
  • This is currently only supported for ConstantInterpolation and LinearInterpolation

Arguments

  • A: interpolation object satisfying the above requirements
source
DataInterpolations.ConstantInterpolationIntInvType
ConstantInterpolationIntInv(u, t, A)

It is the interpolation of the inverse of the integral of a ConstantInterpolation. Can be easily constructed with invert_integral(A::ConstantInterpolation{<:AbstractVector{<:Number}})

Arguments

  • u : Given by A.t
  • t : Given by A.I (the cumulative integral of A)
  • A : The ConstantInterpolation object
source
DataInterpolations.LinearInterpolationIntInvType
LinearInterpolationIntInv(u, t, A)

It is the interpolation of the inverse of the integral of a LinearInterpolation. Can be easily constructed with invert_integral(A::LinearInterpolation{<:AbstractVector{<:Number}})

Arguments

  • u : Given by A.t
  • t : Given by A.I (the cumulative integral of A)
  • A : The LinearInterpolation object
source