# using Pkg
# Pkg.add("DifferentialEquations")
# Pkg.add("StochasticDelayDiffEq")
using DifferentialEquations, StochasticDelayDiffEq, Plots, Statistics
function f(du, u, h, p, t)
M_A, M_B = u;
tau, mu, n, P0, b, sigma_A, sigma_B = p;
hist_A = h(p, t-tau)[1];
hist_B = h(p, t-tau)[2];
du[1] = -mu*M_A + (1+b)*(1/(1+(hist_B/P0)^n));
du[2] = -mu*M_B + (1/(1+(hist_A/P0)^n));
end
function g(du, u, h, p, t)
tau, mu, n, P0, b, sigma_A, sigma_B = p;
du[1] = sigma_A;
du[2] = sigma_B;
end
h(p, t) = zeros(2);
tau = 100; lag = [tau];
P0 = 0.1; n = 5;
mu = 0.03; b = 0.01;
sigma_A = 0.003; sigma_B = 0.003; # only sigma < 0.07 show realiable staeady states
p = (tau, mu, n, P0, b, sigma_A, sigma_B);
tspan = (0, 50000);
u0 = [0, 0];
prob = SDDEProblem(f, g, u0, h, tspan, p; constant_lags = lag);
# single trajectory
# sol = solve(prob, RKMil());
# plot(sol)
# small multiple trajectories
# multiple trajectories
ensembleprob = EnsembleProblem(prob);
sol = solve(ensembleprob, RKMil(), EnsembleThreads(), trajectories = 1000);
# summ = EnsembleSummary(sol, 0:1:50000);
# plot(summ)
m_sol = mean(sol ,dims = 3)
# plot(sol[1, :, 1], sol[2, :, 1], xlabel = "mRNA in cell A", ylabel = "mRNA in cell B")
Sorry for posting screen shot.
This is the code
And also the “sol” is not a matrix. It’s an EnsembleSolution.
Is it because its a EnsembleSolution so I can’t use “mean”?
Thank you