# DifferentialEquations and derivatives of solutions?

**URL:** <https://discourse.julialang.org/t/differentialequations-and-derivatives-of-solutions/49995>\
**Category:** General Usage\
**Created:** [November 11, 2020, 5:43pm UTC](https://discourse.julialang.org/t/differentialequations-and-derivatives-of-solutions/49995 "2020-11-11T17:43:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)\
**Post date:** [November 11, 2020, 5:43pm UTC](https://discourse.julialang.org/t/differentialequations-and-derivatives-of-solutions/49995/1 "2020-11-11T17:43:11Z")

</div>

Suppose I use the `DifferentialEquations.jl` package and find a solution structure `sol`.

Is there a simple way to find the derivative of the various variables in `sol`? In other words: suppose I have 6 states in an ODE model, and want to plot the time derivative of state nr. 4?

---

<div class="post-metadata">

**Author:** ![lbenet](https://avatars.discourse-cdn.com/v4/letter/l/35a633/32.png) [@lbenet](https://discourse.julialang.org/u/lbenet)\
**Post date:** [November 11, 2020, 10:11pm UTC](https://discourse.julialang.org/t/differentialequations-and-derivatives-of-solutions/49995/2 "2020-11-11T22:11:38Z")

</div>

I guess your differential equations are of the form dx\_i/dt = f\_i(x,t). Therefore, you can obtain the time derivative directly by evaluating the differential equations.

---

<div class="post-metadata">

**Author:** ![Mason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mason/32/2423_2.png) [@Mason](https://discourse.julialang.org/u/Mason)\
**Post date:** [November 11, 2020, 10:23pm UTC](https://discourse.julialang.org/t/differentialequations-and-derivatives-of-solutions/49995/3 "2020-11-11T22:23:44Z")

</div>

You just add a second argument with the order of derivative you want:

```julia
julia> begin
           using DifferentialEquations
           f(u,p,t) = 1.1*u
           u0 = 1/2
           tspan = (0.0,1.0)
           prob = ODEProblem(f,u0,tspan)
           sol = solve(prob, Tsit5(), reltol=1e-10, abstol=1e-10)
       end;

julia> sol(1.0) # solution at t = 1.0
1.50208301197696

julia> sol(1.0, Val{1}) ) # First derivative of the solution at t = 1.0 
1.6522913131746269

julia> 1.1 * sol(1.0) ≈ sol(1.0, Val{1}) # We know for this differential equation, that this should match the derivative for any t
true

```
