# Better way to solve jacobian dependent differential equation

**URL:** <https://discourse.julialang.org/t/better-way-to-solve-jacobian-dependent-differential-equation/60259>\
**Category:** Modelling & Simulations\
**Tags:** diffeq\
**Created:** [April 29, 2021, 3:22pm UTC](https://discourse.julialang.org/t/better-way-to-solve-jacobian-dependent-differential-equation/60259 "2021-04-29T15:22:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![willian](https://avatars.discourse-cdn.com/v4/letter/w/ecd19e/32.png) [@willian](https://discourse.julialang.org/u/willian)\
**Post date:** [April 29, 2021, 3:22pm UTC](https://discourse.julialang.org/t/better-way-to-solve-jacobian-dependent-differential-equation/60259/1 "2021-04-29T15:22:13Z")

</div>

What is the best way to solve the following differential equations ?

![image](https://global.discourse-cdn.com/julialang/original/3X/8/f/8f71aec62878eb3f1f48184173e34accf8fb28d2.png)

I mean, I could solve the first equation x(t) alone and use the solutions to run the solver again and find P(t). I would like to know if there is any better method (better in terms of performance and solution) in DifferentialEquations.jl that helps to solve these two equations in a better way.

---

<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 29, 2021, 3:26pm UTC](https://discourse.julialang.org/t/better-way-to-solve-jacobian-dependent-differential-equation/60259/2 "2021-04-29T15:26:04Z")

</div>

You can use ForwardDiff.jacobian in the RHS to put them together, and that will be faster if you aren’t using an implicit solver, slower if you are. Sequential solving here isn’t necessarily a bad idea.

---

<div class="post-metadata">

**Author:** ![jonniedie](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jonniedie/32/12842_2.png) [@jonniedie](https://discourse.julialang.org/u/jonniedie)\
**Post date:** [April 30, 2021, 1:53pm UTC](https://discourse.julialang.org/t/better-way-to-solve-jacobian-dependent-differential-equation/60259/3 "2021-04-30T13:53:35Z")

</div>

FWIW I’ve used `ForwardDiff.jacobian` when I was implementing the EKF in the past (which it looks like you’re doing here).

---

<div class="post-metadata">

**Author:** ![willian](https://avatars.discourse-cdn.com/v4/letter/w/ecd19e/32.png) [@willian](https://discourse.julialang.org/u/willian)\
**Post date:** [April 30, 2021, 11:42pm UTC](https://discourse.julialang.org/t/better-way-to-solve-jacobian-dependent-differential-equation/60259/4 "2021-04-30T23:42:56Z")

</div>

Yes, its exactly what Im trying to do ! Do you have any suggestion for the solver to use or any other part of the implementation ?

I’m checking the ForwardDiff.jacobian. Is this the same function as the one used internally by the DifferentialEquation.jl solvers or I’m ignoring something?

---

<div class="post-metadata">

**Author:** ![jonniedie](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jonniedie/32/12842_2.png) [@jonniedie](https://discourse.julialang.org/u/jonniedie)\
**Post date:** [May 2, 2021, 3:18pm UTC](https://discourse.julialang.org/t/better-way-to-solve-jacobian-dependent-differential-equation/60259/5 "2021-05-02T15:18:47Z")

</div>

> [@willian](#):
>
> Do you have any suggestion for the solver to use or any other part of the implementation ?

I had a `PeriodicCallback`, where I would add measurement noise and do the estimate and covariance update step (assuming you’re using a hybrid continuous/discrete filter). If you’ve got process noise as well, set the problem up as an SDE rather than trying to add noise in your ODE function.
