# DDE running result is different from the result in Matlab

I’m using DifferentialEquations.jl package to solve a delay differential equations problem. However, the result is different from what I got in Matlab. Can anybody tell me which part goes wrong? ><

This is my code in Julia:

``````using DifferentialEquations

function bc_model(du,u,h,p,t)
mu0, mu1, mu2, mu3, mu4, k0, k1, k2, k3, k4, k5, k6, n, P0, tau= p
hist5 = h(p, t-tau)[5]
hist2 = h(p, t-tau)[2]
du[1] = -mu0*u[1] - k1*u[1] + k0*(1/1+(hist5/P0)^n)
du[2] = -mu1*u[2] + k1*u[1]
du[3] = -mu2*u[3] + 2*k4*u[4] - 2*k3*u[3]^2 + k2*hist2
du[4] = -mu3*u[4] + k3*u[3]^2 - k4*u[4] - k5*u[4] + k6*u[5]
du[5] = -mu4*u[5] + k5*u[4] - k6*u[5]
end

h(p, t) = ones(5)

tau = 8
lags = [tau]
P0 = 1250; n = 5;
mu0 = 0.03; mu1 = 0.03; mu2 = 0.3; mu3 = 0.03; mu4 = 0.03;
k0 = 10; k1 = 1; k2 = 10; k3 = 0.01; k4 = 0.001; k5 = 10; k6 = 0;
p = (mu0, mu1, mu2, mu3, mu4, k0, k1, k2, k3, k4, k5, k6, n, P0, tau)
tspan = (0.0, 1000.0)
u0 = [1.0, 1.0, 1.0, 1.0, 1.0]

prob = DDEProblem(bc_model,u0,h,tspan,p, constant_lags=lags)

alg = MethodOfSteps(BS3())

sol = solve(prob,alg)

using Plots; plot(sol)
``````

This is my code in Matlab:

``````tau1 = 8; tau2 = 8; lags = [tau1 tau2];
tspan = [0 2000];
sol = dde23(@ddefun, lags, @history, tspan);

plot(sol.x, sol.y)
xlabel('Time t');
ylabel('Solution y');
legend('y_1','y_2','y_3','y_4','y_5')

function dydt = ddefun(t, y, Z)

p0 = 1250; n = 5;
mu0 = 0.03; mu1 = 0.03; mu2 = 0.3; mu3 = 0.03; mu4 = 0.03;
k0 = 10; k1 = 1; k2 = 10; k3 = 0.01; k4 = 0.001; k5 = 10; k6 = 0;

ylag1 = Z(:, 1);
ylag2 = Z(:, 2);

dydt = zeros(5, 1);
dydt(1) = -mu0*y(1) + k0*(1/(1 + (ylag1(5)/p0)^n)) - k1*y(1);
dydt(2) = -mu1*y(2) + k1*y(1);
dydt(3) = -mu2*y(3) + k2*ylag2(2) - 2*k3*y(3)^2 + 2*k4*y(4);
dydt(4) = -mu3*y(4) + k3*y(3)^2 - k4*y(4) - k5*y(4) + k6*y(5);
dydt(5) = -mu4*y(5) + k5*y(4) - k6*y(5);
end

function s = history(t)
s = ones(5, 1);
end
``````

Update:
Problem solved.
The issue is in function du[1]. I typed du[1] wrong. After changing du[1], the Julia code shows the same result as the Matlab code.

1 Like