Skip to content

Instantly share code, notes, and snippets.

@mfalt

mfalt/DADE.jl Secret

Created October 16, 2020 16:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mfalt/d6ac31b192a8ccd96acb0057915dffc2 to your computer and use it in GitHub Desktop.
Save mfalt/d6ac31b192a8ccd96acb0057915dffc2 to your computer and use it in GitHub Desktop.
Test of DADE
using DelayDiffEq
using DifferentialEquations
using Plots
A = -1.0
B = 1.0
C = 0.5
D = 0.0
function f(du, u, h!, p, t)
(A,B,C,D,tmp,Tau) = p
h!(tmp, p, t-Tau[1]) # Get delayed signal
du[1] = A*u[1] + B*tmp[2] # x'(t) = A*x(t) + B*d(t-tau)
du[2] = -u[2] + C*u[1] + D*tmp[2] # d(t) = C*x(t) + D*d(t-tau)
end
f2 = DDEFunction(f, mass_matrix = [1.0 0; 0 0])
Tau = [1.0,]
tmp = fill(0.0, 2)
p = (A,B,C,D,tmp,Tau)
# Second state zero before time starts
x0 = [1.0, 0.0]
h!(out, p, t) = (out .= x0)
prob = DDEProblem{true}(f2, x0, h!, (0.0, 2), p, constant_lags=Tau)
sol = solve(prob, MethodOfSteps(Tsit5()))
plot(sol)
plot!(0:0.1:1, x->exp(-x), lab="Ref u1")
plot!(0:0.1:1, x->0.5*exp(-x), lab="Ref u2")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment