Is it correct as I defined my delays?

I have been getting into Julia for a while now, however, sometimes I am left with some doubts. This time I am not 100% sure if this is the way to declare and use two different delays with DDE.

I have a Metzler system which features the \tau and \sigma delay. I understand how it is handled when there is only one delay, but not when you have two different delays. This is the implementation I made, I hope someone can help me.

\dot{x}(t)=\left[\begin{array}{cc}-2 & 1 \\ 1 & -1\end{array}\right] x(t-\tau)+\left[\begin{array}{c}\sin x_2(t-\sigma) \\ \sin x_1(t-\sigma)\end{array}\right] u(t)


function metzler(u,h,p,t)
    tau, sigma = p
    theta_a = 0.01
    theta_c = 0.01
    R = 1
    Q = 1

    x1t = h(p, t-tau)[1]
    x2t = h(p, t-tau)[2]
    x1s = h(p, t-sigma)[1]
    x2s = h(p, t-sigma)[2]

    x1 = u[1]
    x2 = u[2]

    Wc = [u[3];u[4];u[5]]
    Wa = [u[6];u[7];u[8]]

    phix = [x1^2;x1*x2;x2^2]
    dphix = [2*x1 0;x2 x1;0 2*x2]

    f = [-2*x1t + x2t;
            x1t - x2t]
    g = [sin(x2s);
            sin(x1s)]

    ua = -0.5*inv(R)*g'*dphix'*Wa
    s = dphix*(f+g*ua)

    Wch = -theta_c*(s/(s'*s+1)^2)*(s'*Wc+[x1;x2]'*Q*[x1;x2]+ua*R*ua')

    Wah = -theta_a*phix*(Wa'*phix+0.5*inv(R)*g'*dphix'*Wc)

    [f+g*ua;Wch;Wah]
end



function adp()
    h(p,t) = ones(2)
    tau = 0.5
    sigma = 1.0
    lags = [tau,sigma]
    p = (tau, sigma)
    tspan = (0.0, 20.0)
    dt = 0.01
    u0 = [2.0;1.0;
            0.1;0.1;0.1;
            0.0;0.0;0.0]
    prob = DDEProblem(metzler,u0,h,tspan,p;constant_lags = lags)
    alg = MethodOfSteps(BS3())
    sol = solve(prob,alg,saveat=dt)
end

Yes it looks fine.

1 Like

Perfect, thanks.