Can someone help me implement my Kuramoto Model with time delay please?
8 次查看(过去 30 天)
显示 更早的评论
Hi there,
I want to solve numerically a system of DDEs with two coupled oscillators based on the Kuramoto Model with a time delay. These are my DDEs:
where K is my coupling matrix. This is the code I am using but I keep getting that not enough inputs and it does not work:
N=2; % two oscillators: melatonin and cortisol
omega=2*pi; % intrinsic frequency of both oscillators: 24 hours
tau=[5*pi/9]; % time delay: 3 hours and 20 minutes
h=0.1; % step size
iter=500; % number of iterations
tspan=0:h:h*iter; % time
K=[0 0.5;0.5 0]; % initialising the coupling matrix
sol=dde23(@ddefun,tau,@history,tspan)
% Subfunctions
function dthetadt=ddefun(t,theta,Z,omega,K)
thetalag1=Z(:,1);
dthetadt=[omega+K(1,2)*sin(theta(2)-theta(1));
omega+K(2,1)*sin(thetalag1(1)-theta(2))];
end
function s=history(t)
s=ones(2,1);
end
Please can someone help me and see where I am going wrong?
Thank you.
0 个评论
采纳的回答
Fabio Freschi
2021-9-2
编辑:Fabio Freschi
2021-9-2
Your function requires additional parameters. One way to pass them is to use an anonymous function as extra layer
% params
N = 2; % two oscillators: melatonin and cortisol
omega = 2*pi; % intrinsic frequency of both oscillators: 24 hours
tau = 5*pi/9; % time delay: 3 hours and 20 minutes
h = 0.1; % step size
iter = 500; % number of iterations
tspan = 0:h:h*iter; % time
K = [0 0.5; 0.5 0]; % initialising the coupling matrix
% extra layer function so that omega and K are available to ddefun
myfun = @(t,theta,Z)ddefun(t,theta,Z,omega,K);
% call to solver
sol = dde23(myfun,tau,@history,tspan);
% Subfunctions
function dthetadt = ddefun(t,theta,Z,omega,K)
thetalag1 = Z(:,1);
dthetadt = [omega+K(1,2)*sin(theta(2)-theta(1));
omega+K(2,1)*sin(thetalag1(1)-theta(2))];
end
function s = history(t)
s = ones(2,1);
end
You can find other strategies to pass extra parameters here
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Delay Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!