# First-order linear system with time delay as DDEProblem?

**URL:** <https://discourse.julialang.org/t/first-order-linear-system-with-time-delay-as-ddeproblem/27014>\
**Category:** Numerics\
**Tags:** diffeq\
**Created:** [July 31, 2019, 2:43am UTC](https://discourse.julialang.org/t/first-order-linear-system-with-time-delay-as-ddeproblem/27014 "2019-07-31T02:43:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![joshualeond](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joshualeond/32/230_2.png) [@joshualeond](https://discourse.julialang.org/u/joshualeond)\
**Post date:** [July 31, 2019, 2:43am UTC](https://discourse.julialang.org/t/first-order-linear-system-with-time-delay-as-ddeproblem/27014/1 "2019-07-31T02:43:07Z")

</div>

I’m new to the diffeq landscape and am working on solving a _First Order Plus Dead Time (FOPDT)_ model:

\tau\_p \frac{dy(t)}{dt} = -y(t) + K\_p u\left(t-\theta\_p\right)

I have data for y(t) and data for u(t) and am having trouble figuring out how to translate this to the `DifferentialEquations` package. Here’s my translation from what I see in the beginner docs for `ODE`s:

- y(t) \rightarrow variable `u`
- \tau\_p, K\_p, \theta\_p \rightarrow parameters `p`
- start and end time of data as a tuple \rightarrow `t`
- u(t) \rightarrow ??

I’m unsure of what to do with u(t) from the FOPDT definition here. I wouldn’t think of it as a parameter since it’s actually just raw data. I did see a python implementation for solving an FOPDT and they ended up taking the data and making an interpolation function via `scipy.interpolate.interp1d` and passing that as a parameter to the `odeint` method of `scipy`.

Given that the FOPDT model has a time delay (u(t-\theta\_p)) I thought this may be a good use case for a Delay Differential Equation (`DDEProblem`). However, I’m unsure if this is the proper use of a `DDEProblem` since u(t) is what I want historical values of and not past values of the diffeq’s solution.

This may seem a bit vague but I’m hoping someone could lead me in the right direction. Thanks for the help.

---

<div class="post-metadata">

**Author:** ![sgjanssens](https://avatars.discourse-cdn.com/v4/letter/s/9f8e36/32.png) [@sgjanssens](https://discourse.julialang.org/u/sgjanssens)\
**Post date:** [July 31, 2019, 8:59am UTC](https://discourse.julialang.org/t/first-order-linear-system-with-time-delay-as-ddeproblem/27014/2 "2019-07-31T08:59:47Z")

</div>

Your way of thinking looks fine to me. This is a first order, linear, inhomogeneous ODE of the form \dot{y}(t) = Ay(t) + f(t) with

A:=-\tau\_p^{-1}, \qquad f(t) := \tau\_p^{-1}K\_p u(t - \theta\_p)

and not a DDE. If you want to solve the associated initial-value problem on an interval [t\_0,t\_1] then it is necessary to know u on the translated interval [t\_0 - \theta\_p, t\_1 - \theta\_p]. This can be done by variation-of-constants, i.e.

u(t) = e^{(t - t\_0)A}u(t\_0) + \int\_{t\_0}^te^{(t- \tau)A}f(\tau)\,d\tau, \qquad t\_0 \le t \le t\_1.

You can calculate the integral using numerical quadrature and knowledge of the u. For comparison and as a test, you can also feed the ODE to your preferred ODE solver and compare the results.

---

<div class="post-metadata">

**Author:** ![sgjanssens](https://avatars.discourse-cdn.com/v4/letter/s/9f8e36/32.png) [@sgjanssens](https://discourse.julialang.org/u/sgjanssens)\
**Post date:** [July 31, 2019, 9:17am UTC](https://discourse.julialang.org/t/first-order-linear-system-with-time-delay-as-ddeproblem/27014/3 "2019-07-31T09:17:05Z")

</div>

Incidentally, what exactly constitutes a parameter may depend on context. We are used to thinking of parameters as points in \mathbb{R} or perhaps \mathbb{R}^n, but sometimes it can be very useful to think of functions such as f (defined via u) as parameters as well, especially if you are interested in how the behavior of the solution y changed when we perturb f.

---

<div class="post-metadata">

**Author:** ![joshualeond](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joshualeond/32/230_2.png) [@joshualeond](https://discourse.julialang.org/u/joshualeond)\
**Post date:** [July 31, 2019, 5:19pm UTC](https://discourse.julialang.org/t/first-order-linear-system-with-time-delay-as-ddeproblem/27014/5 "2019-07-31T17:19:45Z")

</div>

Thanks @sgjanssens! That clears things up a bit. I’ll go ahead and use `DifferentialEquations` `ODEProblem` with f (defined via u) as an additional parameter and look into cross-checking it with calculating the integral as well.
