# Saving extra values during DifferentialEquations solution only at specific times

**URL:** <https://discourse.julialang.org/t/saving-extra-values-during-differentialequations-solution-only-at-specific-times/89586>\
**Category:** General Usage\
**Tags:** differentialequation\
**Created:** [November 1, 2022, 1:33am UTC](https://discourse.julialang.org/t/saving-extra-values-during-differentialequations-solution-only-at-specific-times/89586 "2022-11-01T01:33:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![DanielVandH](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danielvandh/32/31134_2.png) [@DanielVandH](https://discourse.julialang.org/u/DanielVandH)\
**Post date:** [November 1, 2022, 1:33am UTC](https://discourse.julialang.org/t/saving-extra-values-during-differentialequations-solution-only-at-specific-times/89586/1 "2022-11-01T01:33:32Z")

</div>

I have a problem where I want to solve some extra parameters produced while solving a differential equation. For example, the following saves some random number everytime the ODE is evaluated:

```julia
f = (u, p, t) -> (a = rand(); push!(p, a); a * u)
u0 = 1 / 2
p = Float64[]
prob = ODEProblem(f, u0, (0.0, 1.0), p)
solve(prob, Tsit5(); saveat = 0.1)

```

This obviously fails since the ODE is evaluated many more times than simply every `0.1` units of time. How can I change this so that I only push into `p` when the solution is saved? Is it possible to get the exact time, or at least a closest time?

---

<div class="post-metadata">

**Author:** ![cmarcotte](https://avatars.discourse-cdn.com/v4/letter/c/a3d4f5/32.png) [@cmarcotte](https://discourse.julialang.org/u/cmarcotte)\
**Post date:** [November 1, 2022, 9:11am UTC](https://discourse.julialang.org/t/saving-extra-values-during-differentialequations-solution-only-at-specific-times/89586/2 "2022-11-01T09:11:29Z")

</div>

I think what you are looking for is a [callback](https://diffeq.sciml.ai/stable/features/callback_functions/). If you look at the [callback library](https://diffeqcallbacks.sciml.ai/stable/) there is a [saving callback](https://diffeqcallbacks.sciml.ai/stable/output_saving/) which should work for you.
