Delay Differential Equation problem

DifferentialEquation.jl DDE running problem:

using DifferentialEquations, Plots

function dde(du,u,h,p,t)
    M_A, M_B = u;
    tau, mu, n, P0, 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

h(p, t) = ones(2)

tau = 100;
P0 = 0.1; n = 5;
mu = 0.03; b = 0.01;
p = (tau, mu, n, P0, b)
tspan = (0, 5000)
u0 = [0, 0]

prob = DDEProblem(dde, u0, h, tspan, p; constant_lags = (p[1], ))

sol = solve(prob, MethodOfSteps(BS3()))

plot(sol)

image


The corresponding Matlab code:

function osc_switch

%%parameters
mu=0.03;  %degradation rate
n=5; %Hill coefficient
p0=0.1; %Hill threshold
tau=100; %time delay
b=0.01; %bias

%%simulation details
t0=0; %start time
tend=5000; %end time
npts=10000; %number of reporting points
tout=linspace(t0,tend,npts); %reporting times
history=[0;0]; %initial history

%%solver call
sol=dde23(@ddes,tau,history,tout); 
x=deval(sol,tout); %solution

%%plot solution
figure(22)
plot(tout,x,'LineWidth',2) %time course
xlabel('time')
ylabel('amount')

figure(23)
plot(x(1,:),x(2,:),'LineWidth',2) %phase plane
grid on
axis equal
xlabel('x')
ylabel('y')

%%DDE function
    function dydt=ddes(t,y,z)
        dydt=[-mu*y(1)+(1+b)*f(z(2));-mu*y(2)+f(z(1))];
    end

%%Regulation function
    function out=f(x)
        out=1./(1+(x/p0).^n);
    end

end

What’s your test case to show the RHS is exactly the same?

These are the delayed differential equations I’m using:

\frac{dM_A}{dt} = -\mu M_A + (1+b) \frac{1}{1+(\frac{M_B(t-\tau)}{P_0})^n}
\frac{dM_B}{dt} = -\mu M_B + \frac{1}{1+(\frac{M_A(t-\tau)}{P_0})^n}


The code in Matlab is running fine.
image


I’m very confused.
I wondered if I made some mistakes on function part in Julia code?
Thank you.

Shouldn’t this be:

1/(1 + (hist_B/P0)^n)

and similar for the next line?

2 Likes

Oh It works fine now!
Thank you.
Sorry for making such a stupid mistake. I’m feel embarrassed now ahaha…

1 Like

I’ve made sillier mistakes in my life…

1 Like