DDE23 - specifying which variables are delayed
Show older comments
I am using dde23 and am unclear on how you specify which variables are lagged. Is this something you can specify? Does it go y1, y2, y3, y4? Can you set the order you want the des to appear in (I'm updating an existing set of code and am trying to avoid re-writing where unnecessary).
ETA: I found another example that gives me a hint - but I'm not sure I am right. Z is a n x m matrix, n = number of parameters, m = number of lag times specified.
So Z(2,1) is y2 lagged by 0.3 (the first lag option). Updating the code ...
% ExampleDDE - Matlab time dependent delay de
lags = [0.3 3]; % [y2 delay y4 delay]
tspan = [0 10];
param = [1 5 2 0.1 0.5 0.7]; % example parameters for DE
sol = dde23(@(t,y,z) ddefun(t,y,z,param), lags, @history, tspan);
plot(sol.x,sol.y,'-o')
xlabel('Time t');
ylabel('Solution y');
legend('y_1','y_2','y_3', 'y_4','Location','NorthWest');
function dydt = ddefun(t,y, Z, p)
y1 = y(1);
y2 = y(2);
y3 = y(3);
y4 = y(4);
ylag2 = Z(2,1); % this should be a delay on y2, first time lag
ylag4 = Z(4,2); % this should be a delay on y4, second time lag
lagged = ylag2/ylag4;
A = p(1);
B = p(2);
C = p(3);
a = p(4);
b = p(5);
d = p(6);
d1 = A* y1 + b * y3 - C * y4;
d2 = C * y4 + lagged * y3 - a * B * y4 - A * y1;
d3 = a * y4 - b * y3;
d4 = d * y4;
dydt = [d1;d2;d3;d4];
end
function s = history(t) % history function for t<= 0
s = [1 5 10 7];
end
Accepted Answer
More Answers (0)
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!