-
-
Save mfalt/d6ac31b192a8ccd96acb0057915dffc2 to your computer and use it in GitHub Desktop.
Test of DADE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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