# Simulating SDEs with shared noise in \`DifferentialEquations.jl\`

**URL:** https://discourse.julialang.org/t/simulating-sdes-with-shared-noise-in-differentialequations-jl/126139
**Category:** Modelling & Simulations
**Created:** [February 21, 2025, 9:14am UTC](https://discourse.julialang.org/t/simulating-sdes-with-shared-noise-in-differentialequations-jl/126139 "2025-02-21T09:14:58Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![NoFishLikeIan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nofishlikeian/32/20917_2.png) [@NoFishLikeIan](https://discourse.julialang.org/u/NoFishLikeIan)
#### Post date: [February 21, 2025, 9:14am UTC](https://discourse.julialang.org/t/simulating-sdes-with-shared-noise-in-differentialequations-jl/126139/1 "2025-02-21T09:14:58Z")

</div>

I have a problem with two processes X\_{1, t}, X\_{2, t} \in \mathbb{R} which satisfy the SDEs

\begin{align} dX\_{1, t} = f\_1(t, X\_{1, t}) \; dt + \sigma \; dW\_t, \\ dX\_{2, t} = f\_2(t, X\_{1, t}) \; dt + \sigma \; dW\_t. \end{align}

The functions f\_i are nonlinear. The two processes share the noise \sigma \; dW\_t. I would like to simulate paths of X\_{1, t} and X\_{2, t} with the same noise realisations. I tried to do this with `DifferentialEquations.jl` and `DiffEqNoiseProcess.jl`, by defining `W = WienerProcess(0., 0.)`, passing it as `noise` to `SDEProblem` and solving with the same `seed`. But when I check the noise realisation, I get different values.

See this MWE for f\_1(t, x) = \sqrt{x} and f\_2(t, x) = x, and \sigma = 1.

```julia
using DifferentialEquations

f₁(x, p, t) = sqrt(x)
f₂(x, p, t) = x

g(x, p, t) = 1.

W = WienerProcess(0., 0.)
x₀ = 10.
tspan = (0., 1.)

prob₁ = SDEProblem(f₁, g, x₀, tspan, noise = W)
prob₂ = SDEProblem(f₂, g, x₀, tspan, noise = W)

seed = 42

sol₁ = solve(prob₁; seed = seed, save_noise = true)
sol₂ = solve(prob₂; seed = seed, save_noise = true)

error = [sol₁.W(t)[1] - sol₂.W(t)[1] for t in 0:0.01:1]

```

Am I misunderstanding how the seed works? Is there a better way to achieve this?

---

<div class="post-metadata">

### Author: ![NoFishLikeIan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nofishlikeian/32/20917_2.png) [@NoFishLikeIan](https://discourse.julialang.org/u/NoFishLikeIan)
#### Post date: [February 23, 2025, 3:53pm UTC](https://discourse.julialang.org/t/simulating-sdes-with-shared-noise-in-differentialequations-jl/126139/2 "2025-02-23T15:53:06Z")

</div>

I have thought of an inefficient way of doing this. I can simulate the two variables X\_1 and X\_2 as a vector SDE with noise matrix \Sigma = \begin{pmatrix} 1 & 0 \\ 1 & 0\\\end{pmatrix}. This leads to

```julia
using DifferentialEquations
using SparseArrays

f₁(x, p, t) = sqrt(x)
f₂(x, p, t) = x

function fjoint!(dx, x, p, t)
    dx[1] = f₁(x[1], p, t)
    dx[2] = f₂(x[2], p, t)

    return 
end

function g!(Σ, x, p, t)
    Σ[1, 1] = 1.
    Σ[2, 1] = 1.

    return
end

x₀ = 2ones(2);
tspan = (0.0, 1.0);

A = spzeros(2, 2)
A[1, 1] = 1.0
A[2, 1] = 1.0

prob = SDEProblem(fjoint!, g!, x₀, tspan; noise_rate_prototype = A);

```

If somebody can think of a simpler way, please let me know.

---

<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 23, 2025, 5:17pm UTC](https://discourse.julialang.org/t/simulating-sdes-with-shared-noise-in-differentialequations-jl/126139/3 "2025-02-23T17:17:01Z")

</div>

This is scalar noise and is discussed here:

> **[Stochastic Differential Equations · DifferentialEquations.jl](https://docs.sciml.ai/DiffEqDocs/stable/tutorials/sde_example/#Example-3:-Systems-of-SDEs-with-Scalar-Noise)**
>
> Documentation for DifferentialEquations.jl.
