# Solving Stochastic Differential Equations in Different Time Windows

**URL:** <https://discourse.julialang.org/t/solving-stochastic-differential-equations-in-different-time-windows/14807>\
**Category:** Numerics\
**Tags:** diffeq, sde\
**Created:** [September 11, 2018, 11:58am UTC](https://discourse.julialang.org/t/solving-stochastic-differential-equations-in-different-time-windows/14807 "2018-09-11T11:58:33Z")\
**Posts on this page:** 1\
**Showing post:** 16

<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:** [September 30, 2018, 6:56am UTC](https://discourse.julialang.org/t/solving-stochastic-differential-equations-in-different-time-windows/14807/16 "2018-09-30T06:56:20Z")

</div>

I traced the issue back to being an upstream issue with RandomNumbers.jl on v1.0. If you use a seed of zero you always get zeros out of `randn`:

```julia
using RandomNumbers
rng = Xorshifts.Xoroshiro128Plus(0)
randn(rng,Float64) # 0.0

```

That issue was upstreamed: [zero seeds give zeros · Issue #48 · JuliaRandom/RandomNumbers.jl · GitHub](https://github.com/sunoru/RandomNumbers.jl/issues/48) . So if you don’t use a seed of zero and you set `reseed=false`, then the random process is not reseeded and you repeat the values:

```julia
using StochasticDiffEq, RandomNumbers, DiffEqNoiseProcess

# Define the problem
f(dx, x, u, t) = (dx .= x)
g(dx, x, u, t) = (dx .= x)
dt = 2^(-6)

# Solve for 0-2 seconds
rng = Xorshifts.Xoroshiro128Plus(1)
x0 = [1 / 2]
tspan = (0., 2.)
noise = WienerProcess(0., 0., rng=rng, reseed=false)
prob = SDEProblem(f, g, x0, tspan, noise=noise)
sol_full = solve(prob, EM(), dt=dt)

# Solve for 0-1 and 1-2 seconds
rng = Xorshifts.Xoroshiro128Plus(1)
x0 = [1 / 2]
tspan = (0., 1.)
noise = WienerProcess(0., 0., rng=rng, reseed=false)
prob = SDEProblem(f, g, x0, tspan, noise=noise)
sol_part1 = solve(prob, EM(), dt=dt)

x0 = sol_part1.u[end]
tspan = (sol_part1.t[end], 2.)
noise = WienerProcess(sol_part1.W.t[end], sol_part1.W.u[end], rng=rng, reseed=false)
prob = SDEProblem(f, g, x0, tspan, noise=noise)
sol_part2 = solve(prob, EM(), dt=dt)

using Plots
plt1 = plot(sol_full.t, vcat(sol_full.u...),
    linewidth=2, label="Full solution", linecolor=:red)
plot!(sol_part1.t, vcat(sol_part1.u...),
    linewidth=2, label="Solution part 1", linecolor=:green)
plot!(sol_part2.t, vcat(sol_part2.u...),
    linewidth=2, label="Solution part 2", linecolor=:blue)

plt2 = plot(sol_full.W.t, vcat(sol_full.W.u...),
    linewidth=2, label="Full solution Wiener", linecolor=:magenta)
plot!(sol_part1.W.t, vcat(sol_part1.W.u...),
    linewidth=2, label="Solution part 1 Wiener", linecolor=:cyan)
plot!(sol_part2.W.t, vcat(sol_part2.W.u...),
    linewidth=2, label="Solution part 2 Wiener", linecolor=:orange)

plot(plt1, plt2, layout=(2, 1))

```

![res](https://global.discourse-cdn.com/julialang/original/3X/2/e/2e374e8f47f0c949b22746ba712471831f981b6a.png)

Hope that helps. Sorry that took so long.

---

_[View the full topic](https://discourse.julialang.org/t/solving-stochastic-differential-equations-in-different-time-windows/14807)._
