# Yet another question about solving an ODE with inputs using DifferentialEquations

**URL:** <https://discourse.julialang.org/t/yet-another-question-about-solving-an-ode-with-inputs-using-differentialequations/29960>\
**Category:** Modelling & Simulations\
**Tags:** question\
**Created:** [October 15, 2019, 11:10pm UTC](https://discourse.julialang.org/t/yet-another-question-about-solving-an-ode-with-inputs-using-differentialequations/29960 "2019-10-15T23:10:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![zdenek\_hurak](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zdenek_hurak/32/53118_2.png) [@zdenek\_hurak](https://discourse.julialang.org/u/zdenek_hurak)\
**Post date:** [October 15, 2019, 11:10pm UTC](https://discourse.julialang.org/t/yet-another-question-about-solving-an-ode-with-inputs-using-differentialequations/29960/1 "2019-10-15T23:10:47Z")

</div>

This is yet another question related to the obviously popular basic problem of solving an ODE (or a system of ODEs) with **inputs** in Julia (using `DifferentialEquations` package).

Let’s consider a single (scalar) ODE of the form

```nohighlight
dx/dt = f(x,u),

```

where `x(0)` and `u(t)` for `t` in `[0,tmax]` are specified. A simplest possible example is

```nohighlight
dx/dt = -x(t) + u(t),

```

where `x(0)=1` and `u(t) = 0` for `t` below (before) `t=1` and it equals 1 afterwards, that is, for `t>=1` (shifted/delayed Heavyside step function).

A MWE in Julia is (after changing the notation to the one favoured by the `DifferentialEquations`, namely, `x` is relabelled to `u` and the old `u` turns into a _parameter_ `p`):

```julia
using DifferentialEquations
using Plots
pyplot()

f(u,p,t) = -1.0*u + 1.0*p(t)

u0 = 1.0
p(t) = (1-t) <= 0 ? 1 : 0
tspan = (0.0,10.0)

prob = ODEProblem(f,u0,tspan,p)
sol = solve(prob)

plot(sol)

```

The example seems perfectly functional. However, looking at the definition of `f` above, that is, `f(u,p,t) = -1.0*u + 1.0*p(t)`, it cannot be unnoticed that `u` is called without the argument `t` whereas `p` needs to have it, that is, it appears as `p(t)`. Not a problem, it is just that while still learning basics of Julia, I was wondering if the code could be modified so that `p` is handled in the same way as the variable `u`, that is, without appending the `(t)`.

Perhaps this might be more related to the basics of Julia rather than DifferentialEquations (I still find myself rather clumsy with anonymous functions and stuff).

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [October 15, 2019, 11:43pm UTC](https://discourse.julialang.org/t/yet-another-question-about-solving-an-ode-with-inputs-using-differentialequations/29960/2 "2019-10-15T23:43:01Z")

</div>

You could put a DSL over it, but intrinsically at the bottom this is what it looks like in any modeling language after transformation.
