# Can I integrate 2 functions simultaneously in DifferentialEquations.jl?

**URL:** <https://discourse.julialang.org/t/can-i-integrate-2-functions-simultaneously-in-differentialequations-jl/93801>\
**Category:** Numerics\
**Tags:** diffeq, modelingtoolkit, differentialequation\
**Created:** [January 31, 2023, 1:28am UTC](https://discourse.julialang.org/t/can-i-integrate-2-functions-simultaneously-in-differentialequations-jl/93801 "2023-01-31T01:28:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![shaurya](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/shaurya/32/30468_2.png) [@shaurya](https://discourse.julialang.org/u/shaurya)\
**Post date:** [January 31, 2023, 1:28am UTC](https://discourse.julialang.org/t/can-i-integrate-2-functions-simultaneously-in-differentialequations-jl/93801/1 "2023-01-31T01:28:34Z")

</div>

I have 2 coupled systems of differential equations, used for spacecraft simulation, which are to be integrated simultaneously:

![image](https://global.discourse-cdn.com/julialang/original/3X/d/b/dbf43e7d00462237a0eed06b2e26a05edd659f9f.png)

 ![image](https://global.discourse-cdn.com/julialang/original/3X/a/0/a083be7ffe4c12d154c3d5f202026c43f8d92bc2.png)

In this system, omega\_i and epsilon\_j are the variables. (i belongs to {1,2,3} and j belongs to {1,2,3,4}). All other symbols are constants.

In MATLAB, I typically make a new vector as [w;e], which has both the w and e terms, and use it in a single function.

```julia
function dwdt = KDE_dwdt(t,w,I)
    dwdt = zeros(7,1);
    dwdt(1) = -w(3)*w(2)*(I(3)-I(2))/I(1);
    dwdt(2) = -w(3)*w(1)*(I(1)-I(3))/I(2);
    dwdt(3) = -w(1)*w(2)*(I(2)-I(1))/I(3);

    e = w(4:7);

    de = [e(4) -e(3) e(2) e(1);...
          e(3) e(4) -e(1) e(2);...
          -e(2) e(1) e(4) e(3);...
          -e(1) -e(2) -e(3) e(4); ];
    dwdt(4:7) = 1/2 * de * [w(1:3);0];
end

```

Should I follow a similar way in Julia. I don’t know if Julia allows for 2 separate functions to be integrated simultaneously, or if there are more efficient ways to solve this system. This is because I already have the individual system of equations written for omega, and epsilon, but I’m not sure if those can be solved with individually written functions.

For instance, in Julia, I have the following function written for epsilon and omegas:

```julia
function omega_propagator(dω,ω,t,I,L)
    dω[1] = (-ω[3]*ω[2]*(I[3]-I[2]))/I[1];
    dω[2] = (-ω[3]*ω[1]*(I[1]-I[3]))/I[2];
    dω[3] = (-ω[1]*ω[2]*(I[2]-I[1]))/I[3];
end

function KDE_EP!(de,e,wf,t)
    ω = wf(de,e,t); #here wf was a function which gave values of omega, but not integrated numerically
    de.= 0.5*[e[4] -e[3] e[2] e[1];e[3] e[4] -e[1] e[2]; -e[2] e[1] e[4] e[3];-e[1] -e[2] -e[3] e[4]]*[ω;0];
end

```

Is there a way that I can integrate omega values in `KDE_EP!` and use omega values in `omega_propagator` for the next step?

Thanks!

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [January 31, 2023, 2:08am UTC](https://discourse.julialang.org/t/can-i-integrate-2-functions-simultaneously-in-differentialequations-jl/93801/2 "2023-01-31T02:08:53Z")

</div>

> [@shaurya](#):
>
> Should I follow a similar way in Julia.

Yes.

---

<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:** [January 31, 2023, 7:45am UTC](https://discourse.julialang.org/t/can-i-integrate-2-functions-simultaneously-in-differentialequations-jl/93801/3 "2023-01-31T07:45:22Z")

</div>

Please read the getting started tutorial:

[https://docs.sciml.ai/DiffEqDocs/stable/getting\_started/#Example-2:-Solving-Systems-of-Equations](https://docs.sciml.ai/DiffEqDocs/stable/getting_started/#Example-2:-Solving-Systems-of-Equations)

---

<div class="post-metadata">

**Author:** ![shaurya](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/shaurya/32/30468_2.png) [@shaurya](https://discourse.julialang.org/u/shaurya)\
**Post date:** [January 31, 2023, 3:53pm UTC](https://discourse.julialang.org/t/can-i-integrate-2-functions-simultaneously-in-differentialequations-jl/93801/4 "2023-01-31T15:53:21Z")

</div>

Thanks I’ll do that then!
