Delay differential equations where every variable can take on multiple delays
Show older comments
Hello,
I'm trying to code the Kuramoto model as a delay differential equation. I have a connectivity matrix and a delay matrix. So the equation looks like this:
The problem is the delay matrix D has 0s on the diagonal and when formulating the DDE all the time delays has to be positive or I get the error message "The lags must all be positive". One way to circumvent this is to do an if / else loop:
if i ~= j
theta_j = Z(:, ???)
else
theta_j = theta(j);
end
Then the problem is how to formulate lags and Z. One can do the following:
lags = D(find(triu(D, 1)));
Which would only give the non-diagonal upper triangle of D. Then one would need to find a mapping between ij and lags to put in as a Z index. I am inclined to use sub2ind but they would assume that the matrix is symmetrical and square, not only the upper triangle. Is there a way to make this work?
For context, here is the full code for the Kuramoto equation:
function dtheta = krm_dde(t, theta, Z, p)
for i = 1:length(p.omega)
sum_coupling = 0;
% Do the sigma term
for j = 1:length(p.omega)
if i ~= j
theta_j = Z(:, ???);
else
theta_j = theta(j);
end
sum_coupling = sum_coupling + p.C(i, j) * sin(theta_j - theta(i));
end
% Do the RHS
dtheta(i) = p.omega(i) + K * sum_coupling;
end
end
Tangentially related: I would also appreciate any tips to make this code vectorized. It is horribly slow in this state.
Thanks,
Yasir
Accepted Answer
More Answers (0)
Categories
Find more on Assembly 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!