Skip to content
This repository was archived by the owner on May 12, 2026. It is now read-only.
This repository was archived by the owner on May 12, 2026. It is now read-only.

Interpolation on algebraic relations #37

Closed

Description

@aytekinar

When simulating systems, one often needs to keep track of the input and onput signals. Assume we have the following representation:

xdot = A*x + B*u(t,x)
y = C*x + D*u(t,x)

Then, a solution similar to

type TimeResponse{T} <: DEDataArray{T}
  x::Array{T,1}
  u::Array{T,1}
  y::Array{T,1}
end

function f(t::Real,x::TimeResponse,dx::AbstractVector,u)
  ucalc = u(t, x.x) # callable object on (::Real,::AbstractVector)
  isa(ucalc, AbstractVector) || DomainError()
  x.u = ucalc
  dx[:] = A*x.x + B*x.u # for some A, B
  x.y = C*x.x + D*x.u
end

would handle everything. However, in this way, interpolation on u and y are note available in the current design.

Moreover, u object above can be a discrete-time system object on its own, with some samplingtime(u) defined. Then, this object will calculate the new values at each samplingtime(u) and hold the previous value at all times. See, e.g.,

function (u::System)(t::Real, x::AbstractVector)
  if t >= u.tprev + samplingtime(u)
    u.tprev = t
    u.uprev = ... # calculate new value
  end
  u.uprev
end

this approach can also run easily using tstops keyword.

However, if there is gonna be some change in DEDataArray type to support the algebraic equations as those above, one needs to think about this issue. Should it be DEDataArrays responsibility to take this discrete behaviour in mind (interpolation would yield the stairs), or should it be the object's job to cache some values and not do any interpolation when asked by the DifferentialEquations ecosystem packages? Would there exist some common interface between the two?

Cc: @neveritt

Activity

  1. ChrisRackauckas commented on May 10, 2017

    @ChrisRackauckas
    Member

    However, if there is gonna be some change in DEDataArray type to support the algebraic equations as those above, one needs to think about this issue. Should it be DEDataArrays responsibility to take this discrete behaviour in mind (interpolation would yield the stairs), or should it be the object's job to cache some values and not do any interpolation when asked by the DifferentialEquations ecosystem packages?

    DEDataArray does its job which, while it can handle parts of this, is separate from this issue. So I think this should be a new type which is more specific to this problem.

    I think the solution is to register u and C*x.x + D*x.u so that way x.u and x.y are calculated on-demand for interpolations.

    should it be the object's job to cache some values

    I'm not sure I know of another way to handle this if it's a function call. Maybe you can "register" variables as discrete, and it will do "discrete interpolation" (take the left endpoint of any known interval).

  2. aytekinar commented on May 10, 2017

    @aytekinar
    Author

    I'm not sure I know of another way to handle this if it's a function call. Maybe you can "register" variables as discrete, and it will do "discrete interpolation" (take the left endpoint of any known interval).

    is this already supported? then it's great!

  3. ChrisRackauckas commented on May 10, 2017

    @ChrisRackauckas
    Member

    is this already supported? then it's great!

    No, this is the proposed new type. Either compute values on demand using a function, or default to "discrete" and interpolate by taking the value from the left.

    Actually, this is compatible with the current DEDataArray. That would follow directly if similar was changed. Computing values from a function can be another type, but making the interpolation include the discrete variables is an easy update.

  4. aytekinar commented on May 10, 2017

    @aytekinar
    Author

    I don't know what I can say --- that's just impressive! Would be cool to see that. Thanks!

  5. ChrisRackauckas commented on May 10, 2017

    @ChrisRackauckas
    Member

    The discrete change is implemented on DiffEqBase master. Some tags are needed.

  6. ChrisRackauckas-Claude commented on Mar 24, 2026

    @ChrisRackauckas-Claude
    Member

    Triage: DEDataArray/DEDataVector has been completely removed from DiffEqBase. MTK's observables system is the recommended replacement. This issue is no longer relevant. Recommend closing.

  7. ChrisRackauckas commented on Mar 24, 2026

    @ChrisRackauckas
    Member

    Closing: DEDataArray has been deprecated and removed. Algebraic relation interpolation is now handled by ModelingToolkit.jl. DiffEqBase.jl has been merged into OrdinaryDiffEq.jl.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions