# Passing along data from one time step to the next using DifferentialEquations.jl

**URL:** <https://discourse.julialang.org/t/passing-along-data-from-one-time-step-to-the-next-using-differentialequations-jl/38335>\
**Category:** Modelling & Simulations\
**Created:** [April 27, 2020, 8:41pm UTC](https://discourse.julialang.org/t/passing-along-data-from-one-time-step-to-the-next-using-differentialequations-jl/38335 "2020-04-27T20:41:17Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![bielim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bielim/32/13963_2.png) [@bielim](https://discourse.julialang.org/u/bielim)\
**Post date:** [April 27, 2020, 8:41pm UTC](https://discourse.julialang.org/t/passing-along-data-from-one-time-step-to-the-next-using-differentialequations-jl/38335/1 "2020-04-27T20:41:17Z")

</div>

I am using `DifferentialEquations.jl` to solve an ODE of the form \frac{d\boldsymbol{M}}{dt} = \boldsymbol{f}(\boldsymbol{M}), where \boldsymbol{M} = [M\_1, ..., M\_k]^T, and \boldsymbol{f} = [f\_1(\boldsymbol{M}), ..., f\_k(\boldsymbol{M})]^T  
Without going into the weeds of how exactly the right-hand side, \boldsymbol{f}(\boldsymbol{M}), is computed, let me just say that it involves solving a nonlinear system of equations. At each time step t, that system of equations uses the current state of the solution \boldsymbol{M} to determine a vector of unknowns \boldsymbol{x}, which in turn is needed to compute \boldsymbol{f}(\boldsymbol{M}).

To solve that system of equations it would be very useful to have access to the unknowns \boldsymbol{x} that were computed in the previous time step - they would be a good initial guess for solving the system of equations at the current time step.

Is there a way to achieve what I want, i.e., to pass \boldsymbol{x} to the next time step for use in the evaluation of \boldsymbol{f}?

---

<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:** [April 27, 2020, 9:11pm UTC](https://discourse.julialang.org/t/passing-along-data-from-one-time-step-to-the-next-using-differentialequations-jl/38335/2 "2020-04-27T21:11:58Z")

</div>

> [@bielim](#):
>
> Is there a way to achieve what I want, i.e., to pass x\boldsymbol{x} to the next time step for use in the evaluation of f\boldsymbol{f} ?

If your problem is like Mu’=f(u), then you might want to use a mass matrix instead since that doesn’t require an extra nonlinear solve. Otherwise, you can use the parameters to hold a cache of the values, and then use those the values from in the parameters as the guess.

---

<div class="post-metadata">

**Author:** ![bielim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bielim/32/13963_2.png) [@bielim](https://discourse.julialang.org/u/bielim)\
**Post date:** [April 27, 2020, 11:09pm UTC](https://discourse.julialang.org/t/passing-along-data-from-one-time-step-to-the-next-using-differentialequations-jl/38335/3 "2020-04-27T23:09:30Z")

</div>

Thanks for your reply, @ChrisRackauckas!  
Using the parameters to hold a cache of the value of \boldsymbol{x} and then access it in the next time step sounds like it would solve my problem. Can you elaborate a little on how to implement that?

---

<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:** [April 27, 2020, 11:11pm UTC](https://discourse.julialang.org/t/passing-along-data-from-one-time-step-to-the-next-using-differentialequations-jl/38335/4 "2020-04-27T23:11:11Z")

</div>

This tutorial has an example of a compute cache. It always rewrites first though: passing to the next timestep is done by just using the value before writing.

[https://tutorials.sciml.ai/html/introduction/03-optimizing\_diffeq\_code.html](https://tutorials.sciml.ai/html/introduction/03-optimizing_diffeq_code.html)

---

<div class="post-metadata">

**Author:** ![bielim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bielim/32/13963_2.png) [@bielim](https://discourse.julialang.org/u/bielim)\
**Post date:** [April 27, 2020, 11:21pm UTC](https://discourse.julialang.org/t/passing-along-data-from-one-time-step-to-the-next-using-differentialequations-jl/38335/5 "2020-04-27T23:21:42Z")

</div>

Thank you very much, I will work through that example and report on whether I was able to solve my problem using that approach.

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [April 28, 2020, 2:28am UTC](https://discourse.julialang.org/t/passing-along-data-from-one-time-step-to-the-next-using-differentialequations-jl/38335/6 "2020-04-28T02:28:20Z")

</div>

That sounds like it might be some kind of continuation method? If so there are specialized packages for that, like

> **[GitHub - bifurcationkit/BifurcationKit.jl: A Julia package to perform...](https://github.com/bifurcationkit/BifurcationKit.jl)**
>
> A Julia package to perform Bifurcation Analysis. Contribute to bifurcationkit/BifurcationKit.jl development by creating an account on GitHub.
