I want to solve a stochastic differential equation in different time windows under Wiener process, e.g., instead of solving the system for a time interval of (0, 2) seconds, I want to solve the system for a time duration of (0, 1) first, and then for a time duration of (1, 2). However, although I feed the problem in the second time window with the properly modified Wiener process (I update the initial time and initial value of the wiener process in the second time window with the last time and value of the wiener process in the first time window), the solutions of the system solved in two time windows and the that of the system solved at once do not coinside.
Below are the script I wrote for this problem and the plot of the solutions I obtained. Any ideas what I am doing wrong?
using DifferentialEquations
using Random
using Plots; plotly()
# 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
Random.seed!(0)
x0 = [1 / 2]
tspan = (0., 2.)
noise = WienerProcess(0., 0.)
prob = SDEProblem(f, g, x0, tspan, noise=noise)
sol_full = solve(prob, EM(), dt=dt)
# Solve for 0-1 and 1-2 seconds
Random.seed!(0)
x0 = [1 / 2]
tspan = (0., 1.)
noise = WienerProcess(0., 0.)
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])
prob = SDEProblem(f, g, x0, tspan, noise=noise)
sol_part2 = solve(prob, EM(), dt=dt)
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))
gui()