I try to understand how to solve stochastic differential equations (SDEs) numerically (I have no experience in any language, but for some reasons I chose Julia). As a starting model, I decided to use Lotka-Volterra equations. I read manual and tutorial for DifferentialEquations.jl. While my model is a simple system of ODE:
everything works fine:
using DifferentialEquations
using Plots
function lotka(du,u,p,t);
????, ????, ????, ???? = p;
du[1] = ????*u[1]-????*u[1]*u[2];
du[2] = ????*u[1]*u[2]-????*u[2];
end
u0 = [15.0,1.0,0.0,0.0];
p = (0.3,0.05,0.7,0.1);
tspan = (0.0,50.0);
prob = ODEProblem(lotka,u0,tspan,p);
sol = solve(prob);
plot(sol,vars = (1,2))
Now I want to add Ornstein-Uhlenbeck noise:
The stupid straightforward solution is:
using DifferentialEquations
using Plots
function lotka(du,u,p,t);
????, ????, ????, ????, ????, ???? = p;
du[1] = ????*u[1]-????*u[1]*u[2]+u[3];
du[2] = ????*u[1]*u[2]-????*u[2]+u[4];
du[3] = -u[3]/????+sqrt((2.0*????^2.0/????))*randn();
du[4] = -u[4]/????+sqrt((2.0*????^2.0/????))*randn();
end
u0 = [15.0,1.0,0.0,0.0];
p = (0.3,0.05,0.7,0.1,0.1,0.1);
tspan = (0.0,50.0);
prob = ODEProblem(lotka,u0,tspan,p);
sol = solve(prob);
But, as expected, it did not work, as solver is not for such SDE problem.
┌ Warning: Interrupted. Larger maxiters is needed.
└ @ DiffEqBase /home/jrun/.julia/packages/DiffEqBase/ujEgN/src/integrator_interface.jl:116
I tried to read SDE Julia documentation, but without good example I could not understand how to deal with it. Moreover, my math background is poor, and it seems I did not understand notation correctly. How can I make this work for SDEs?
UPDATE:
Finally, I have the following code:
using DifferentialEquations,Plots;
function lotka(du,u,p,t);
????, ????, ????, ????, ????, ???? = p;
du[1] = ????*u[1]-????*u[1]*u[2];
du[2] = ????*u[1]*u[2]-????*u[2];
end
function stoch(du,u,p,t)
????, ????, ????, ????, ????, ???? = p;
du[1] = 1
du[2] = 1
end
u0 = [15.0,1.0];
p = (0.3,0.05,0.7,0.1,0.9,0.1);
????, ????, ????, ????, ????, ???? = p;
OU = OrnsteinUhlenbeckProcess(1/????, 0.0, ????, 0.0, 0.0);
tspan = (0.0,100.0);
prob = SDEProblem(lotka,stoch,u0,tspan,p,noise = OU);
sol = solve(prob,EM(),dt = 1e-3, adaptive=false);
To close this topic I have two last questions:
Is it correct code? (I am afraid, that my noise is not diagonal in this case)
May I have different initial noise (W0) for each of two equations?
tspan = [0 t_max]
, wheret_max > 50
. – Sven Krüger