# Saving the value of parameterized functions in DifferentialEquations.jl

**URL:** <https://discourse.julialang.org/t/saving-the-value-of-parameterized-functions-in-differentialequations-jl/67071>\
**Category:** General Usage\
**Tags:** question, diffeq\
**Created:** [August 26, 2021, 11:14pm UTC](https://discourse.julialang.org/t/saving-the-value-of-parameterized-functions-in-differentialequations-jl/67071 "2021-08-26T23:14:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mys\_721tx](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mys_721tx/32/28238_2.png) [@mys\_721tx](https://discourse.julialang.org/u/mys_721tx)\
**Post date:** [August 26, 2021, 11:14pm UTC](https://discourse.julialang.org/t/saving-the-value-of-parameterized-functions-in-differentialequations-jl/67071/1 "2021-08-26T23:14:27Z")

</div>

Hello all,

I have the following ODE system in which p is a parameterized function:

```nohighlight
function fcd!(du, u, p, t)
    du[1] = p(t) - u[1]
    du[2] = p(t) / u[1] - u[2]
end

```

I wish to solve the ODE using DifferentialEquations.jl and also save the value of `p(t)` at all time points.

Right now I did so in a data frame, `conc` is `p(t)` in the ODE.

```nohighlight
DataFrame(sol) |>
@mutate(u = conc.(_.timestamp))

```

Is there a more elegant way to save `p(t)`?

---

<div class="post-metadata">

**Author:** ![Wen-Wei\_Tseng](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wen-wei_tseng/32/28839_2.png) [@Wen-Wei\_Tseng](https://discourse.julialang.org/u/Wen-Wei_Tseng)\
**Post date:** [August 27, 2021, 12:42am UTC](https://discourse.julialang.org/t/saving-the-value-of-parameterized-functions-in-differentialequations-jl/67071/2 "2021-08-27T00:42:33Z")

</div>

Hello, `ModelingToolkit.jl` (the symbolic part of `DifferentialEquations.jl`) provides tracing for non-state variables right in the solution interface and plot recipes. [Specifying a time-variable forcing function](https://mtk.sciml.ai/dev/tutorials/ode_modeling/#Specifying-a-time-variable-forcing-function) is possibly the closest to what you want.

---

<div class="post-metadata">

**Author:** ![mys\_721tx](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mys_721tx/32/28238_2.png) [@mys\_721tx](https://discourse.julialang.org/u/mys_721tx)\
**Post date:** [August 27, 2021, 2:18am UTC](https://discourse.julialang.org/t/saving-the-value-of-parameterized-functions-in-differentialequations-jl/67071/3 "2021-08-27T02:18:24Z")

</div>

Unfortunately I need to dynamically redefine the function to save time on Julia’s start-up overhead time. This does not work with `Symbolics.jl`.

---

<div class="post-metadata">

**Author:** ![Wen-Wei\_Tseng](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wen-wei_tseng/32/28839_2.png) [@Wen-Wei\_Tseng](https://discourse.julialang.org/u/Wen-Wei_Tseng)\
**Post date:** [August 27, 2021, 6:35am UTC](https://discourse.julialang.org/t/saving-the-value-of-parameterized-functions-in-differentialequations-jl/67071/4 "2021-08-27T06:35:41Z")

</div>

Perhaps [SavingCallback](https://diffeq.sciml.ai/dev/features/callback_library/#saving_callback) could meet your needs. It can save extra information in the simulation.
