# DifferentialEquations.jl look at the ODEsystem

**URL:** <https://discourse.julialang.org/t/differentialequations-jl-look-at-the-odesystem/95131>\
**Category:** General Usage\
**Created:** [February 24, 2023, 12:46pm UTC](https://discourse.julialang.org/t/differentialequations-jl-look-at-the-odesystem/95131 "2023-02-24T12:46:34Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![mm-crj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mm-crj/32/45906_2.png) [@mm-crj](https://discourse.julialang.org/u/mm-crj)\
**Post date:** [February 24, 2023, 12:46pm UTC](https://discourse.julialang.org/t/differentialequations-jl-look-at-the-odesystem/95131/1 "2023-02-24T12:46:34Z")

</div>

I am solving a large system of ODEs with the DifferentialEquation.jl package. Since I am using a number of for loops to set up the RHS to the du, so I would like to see the RHS matrix before solving. Is there a way I can do that?

* * *

Lets say I have the following

```julia
tspan=[0.0,1.0]
function flux!(du,u,p,t)
for i in 1:n
     dummy=0.0
     for j in 1:n
         dummy=dummy+u[j]
     end
   du[i]= max(0,dummy)*u[i]+min(0,dummy)*u[i+1]
end

prob = ODEProblem(flux!, u0, tspan)
sol = solve(prob)

```

So basically I am trying to put a convolution like function on the right hand side, and trying to see if the correct ODE system is generated or not.

---

<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:** [February 24, 2023, 1:13pm UTC](https://discourse.julialang.org/t/differentialequations-jl-look-at-the-odesystem/95131/2 "2023-02-24T13:13:12Z")

</div>

> [@mm-crj](#):
>
> I am solving a large system of ODEs with the DifferentialEquation.jl package. Since I am using a number of for loops to set up the RHS to the du, so I would like to see the RHS matrix before solving.

I’m a bit confused. Is this ModelingToolkit ODESystem or direct DifferentialEquations.jl?

---

<div class="post-metadata">

**Author:** ![mm-crj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mm-crj/32/45906_2.png) [@mm-crj](https://discourse.julialang.org/u/mm-crj)\
**Post date:** [February 24, 2023, 1:26pm UTC](https://discourse.julialang.org/t/differentialequations-jl-look-at-the-odesystem/95131/3 "2023-02-24T13:26:59Z")

</div>

This is DifferentialEquations.jl.

---

<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:** [February 24, 2023, 1:36pm UTC](https://discourse.julialang.org/t/differentialequations-jl-look-at-the-odesystem/95131/4 "2023-02-24T13:36:17Z")

</div>

Then it’s just Julia code so you instrument it with `@show`. What did you try?

```julia
function flux!(du,u,p,t)
for i in 1:n
     dummy=0.0
     for j in 1:n
         dummy=dummy+u[j]
     end
   du[i]= max(0,dummy)*u[i]+min(0,dummy)*u[i+1]
end
@show du
end

```

you were missing an end btw

---

<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:** [February 24, 2023, 1:37pm UTC](https://discourse.julialang.org/t/differentialequations-jl-look-at-the-odesystem/95131/5 "2023-02-24T13:37:02Z")

</div>

One debugging trick here is, because it’s linear, the matrix can be found by calculating the Jacobian. Just do `ForwardDiff.jacobian` on `f` and check the matrix.

---

<div class="post-metadata">

**Author:** ![mm-crj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mm-crj/32/45906_2.png) [@mm-crj](https://discourse.julialang.org/u/mm-crj)\
**Post date:** [February 24, 2023, 1:46pm UTC](https://discourse.julialang.org/t/differentialequations-jl-look-at-the-odesystem/95131/6 "2023-02-24T13:46:15Z")

</div>

Thanks for the answer. I now can print the du. Can I also, acces it as a variable(Matrix)?

---

<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:** [February 24, 2023, 1:48pm UTC](https://discourse.julialang.org/t/differentialequations-jl-look-at-the-odesystem/95131/7 "2023-02-24T13:48:54Z")

</div>

`du` isn’t a matrix. But if you’re looking for the operator, in this case it’s equivalent to the Jacobian, so just calculate the Jacobian.

---

<div class="post-metadata">

**Author:** ![mm-crj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mm-crj/32/45906_2.png) [@mm-crj](https://discourse.julialang.org/u/mm-crj)\
**Post date:** [February 24, 2023, 1:55pm UTC](https://discourse.julialang.org/t/differentialequations-jl-look-at-the-odesystem/95131/8 "2023-02-24T13:55:13Z")

</div>

May be I am not being clear. So in the system

d\_tu=A \cdot u

I want the matrix A, so that I can compute the coefficients by hand and see that they are indeed what they should be. I am really sorry, I am new to Julia and I don’t understand macros.

---

<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:** [February 24, 2023, 2:41pm UTC](https://discourse.julialang.org/t/differentialequations-jl-look-at-the-odesystem/95131/9 "2023-02-24T14:41:54Z")

</div>

Yes, have you tried calculating the Jacobian?

---

<div class="post-metadata">

**Author:** ![mm-crj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mm-crj/32/45906_2.png) [@mm-crj](https://discourse.julialang.org/u/mm-crj)\
**Post date:** [March 9, 2023, 3:25pm UTC](https://discourse.julialang.org/t/differentialequations-jl-look-at-the-odesystem/95131/10 "2023-03-09T15:25:49Z")

</div>

Thanks for all the help, the issue was when I was writing the flux as a sum on a new line for each component, only the 1st component was being added somehow. So when I changed the coefficient for the 1st component to zero to see how the others affected the solution, the RHS essentially became zero, as the rest of the components were not being added. That’s why I wanted to look at the RHS.

It took me a while to realize that whatever I sum to the flux after putting a newline is not being added to the RHS.
