# Does DifferentialEquations.jl support matrix-shaped noise

**URL:** <https://discourse.julialang.org/t/does-differentialequations-jl-support-matrix-shaped-noise/110958>\
**Category:** General Usage\
**Tags:** sde, differentialequation\
**Created:** [February 29, 2024, 3:15pm UTC](https://discourse.julialang.org/t/does-differentialequations-jl-support-matrix-shaped-noise/110958 "2024-02-29T15:15:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![matt1](https://avatars.discourse-cdn.com/v4/letter/m/b782af/32.png) [@matt1](https://discourse.julialang.org/u/matt1)\
**Post date:** [February 29, 2024, 3:15pm UTC](https://discourse.julialang.org/t/does-differentialequations-jl-support-matrix-shaped-noise/110958/1 "2024-02-29T15:15:51Z")

</div>

let’s say I want to solve the following system of SDEs:  
\begin{align\*} du\_{1} &= f\_{1}(u,du,p,t) dt+c\_{11}dW\_{1}+c\_{12}dW\_{2} \\ du\_{2} &= f\_{2}(u,du,p,t) dt+c\_{23}dW\_{3}+c\_{24}dW\_{4} \\ du\_{3} &= f\_{3}(u,du,p,t) dt+c\_{35}dW\_{5}+c\_{36}dW\_{6} \\ du\_{4} &=f\_{4}(u,du,p,t) dt+ c\_{47}dW\_{7}+c\_{48}dW\_{8} \end{align\*}  
In Julia, the implementation of the g function (which gives the change of u due to the noise) looks like this:  
function g!(u,du,t,p)  
du[1,1] = c\_{11}  
du[1,2] = c\_{12}  
du[1,3] = 0  
du[1,4] = 0  
du[1,5] = 0  
du[1,6] = 0  
du[1,7] = 0  
du[1,8] = 0  
du[2,1] = 0  
du[2,2] = 0  
du[2,3] = c\_{23}  
du[2,4] = c\_{24}  
du[2,5] = 0  
du[2,6] = 0  
du[2,7] = 0  
du[2,8] = 0  
du[3,1] = 0  
du[3,2] = 0  
du[3,3] = 0  
du[3,4] = 0  
du[3,5] = c\_{35}  
du[3,6] = c\_{36}  
du[3,7] = 0  
du[3,8] = 0  
du[4,1] = 0  
du[4,2] = 0  
du[4,3] = 0  
du[4,4] = 0  
du[4,5] = 0  
du[4,6] = 0  
du[4,7] = c\_{47}  
du[4,8] = c\_{48}  
end

and then I define the problem and solve it as:  
prob=SDEProblem(f!,g!,ones(4),(0.0,1.0),noise\_rate\_prototype = zeros(4,8))  
where I assumed the initial condition u\_0=[1 1 1 1], and I let the system evolve form 0.0 to time 1.0. In this example, inside g, I define a matrix 4x8 (containing the noise rates), such that g\*dw gives the change du due to the stochastic part of the equation. since du is a 1d vector of length 4, dW is a vector of independent noises of length 8.  
This is fine.

But I am wondering if there exist the possibility in julia to have instead of a 1d vector dW, a matrix. This would be useful in the case where the object u that I’m solving for is a matrix and the different components get independent noises.

For example let’s say u and du are 2x2 matrices. Then, is there a way to have a g function given by a 2x4 matrix and the dW by a 4x2 matrix so that g\*dW is 2x2 and it correctly gives independent noises for the different comonents of du?

---

<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 29, 2024, 3:19pm UTC](https://discourse.julialang.org/t/does-differentialequations-jl-support-matrix-shaped-noise/110958/2 "2024-02-29T15:19:24Z")

</div>

At this time it’s not supported. You’d have to `reshape` in the `g` function, but that reshape is free

---

<div class="post-metadata">

**Author:** ![matt1](https://avatars.discourse-cdn.com/v4/letter/m/b782af/32.png) [@matt1](https://discourse.julialang.org/u/matt1)\
**Post date:** [March 14, 2024, 2:08pm UTC](https://discourse.julialang.org/t/does-differentialequations-jl-support-matrix-shaped-noise/110958/3 "2024-03-14T14:08:27Z")

</div>

But how can I do the reshape inside the G? If G returns a vector then I think every component will just get a single noise, hence I obtain a diagonal noise.
