# Why does this really simple linear SDE diverge?

**URL:** <https://discourse.julialang.org/t/why-does-this-really-simple-linear-sde-diverge/107640>\
**Category:** General Usage\
**Created:** [December 15, 2023, 2:53am UTC](https://discourse.julialang.org/t/why-does-this-really-simple-linear-sde-diverge/107640 "2023-12-15T02:53:52Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![George\_Stepaniants](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/george_stepaniants/32/47230_2.png) [@George\_Stepaniants](https://discourse.julialang.org/u/George_Stepaniants)\
**Post date:** [December 15, 2023, 2:53am UTC](https://discourse.julialang.org/t/why-does-this-really-simple-linear-sde-diverge/107640/1 "2023-12-15T02:53:52Z")

</div>

```julia
using DifferentialEquations
using LinearAlgebra

N = 5
conn = -Matrix{Float64}(I, N, N)
sigma = Matrix{Float64}(I, N, N)
f(v, p, t) = conn * v
g(v, p, t) = sigma

Nt = 200
T = 100.0 # measured in seconds

prob = SDEProblem(f, g, zeros(N), (0.0, T), nothing)

function prob_func(prob, i, repeat)
    @. prob.u0 = randn()
    prob
end

ensembleprob = EnsembleProblem(prob; prob_func=prob_func)

sol = solve(ensembleprob, SOSRI(), EnsembleThreads(), trajectories = 10)

```

---

<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:** [December 15, 2023, 12:43pm UTC](https://discourse.julialang.org/t/why-does-this-really-simple-linear-sde-diverge/107640/2 "2023-12-15T12:43:27Z")

</div>

With additive noise, there’s no guarantee it stays positive. Once it goes negative it’s exponential growth with noise.

---

<div class="post-metadata">

**Author:** ![George\_Stepaniants](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/george_stepaniants/32/47230_2.png) [@George\_Stepaniants](https://discourse.julialang.org/u/George_Stepaniants)\
**Post date:** [December 15, 2023, 1:36pm UTC](https://discourse.julialang.org/t/why-does-this-really-simple-linear-sde-diverge/107640/3 "2023-12-15T13:36:26Z")

</div>

I don’t see how. This is just an Ornstein-Uhlenbeck SDE with noise, it should be stable.

---

<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:** [December 15, 2023, 1:45pm UTC](https://discourse.julialang.org/t/why-does-this-really-simple-linear-sde-diverge/107640/4 "2023-12-15T13:45:55Z")

</div>

Oh wait I was wrong. Did you try just decreasing the integration tolerances?

---

<div class="post-metadata">

**Author:** ![George\_Stepaniants](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/george_stepaniants/32/47230_2.png) [@George\_Stepaniants](https://discourse.julialang.org/u/George_Stepaniants)\
**Post date:** [December 15, 2023, 9:17pm UTC](https://discourse.julialang.org/t/why-does-this-really-simple-linear-sde-diverge/107640/5 "2023-12-15T21:17:19Z")

</div>

Same issue occurs, even if I set abstol = 1e-14, reltol = 1e-14 and the solve function. Not sure why this would fail for such a simple test case.

---

<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:** [December 16, 2023, 12:15am UTC](https://discourse.julialang.org/t/why-does-this-really-simple-linear-sde-diverge/107640/6 "2023-12-16T00:15:12Z")

</div>

Only with threading?
