Can someone help me implement my Kuramoto Model with time delay please?

17 Ansichten (letzte 30 Tage)
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.

Akzeptierte Antwort

Fabio Freschi
Fabio Freschi am 2 Sep. 2021
Bearbeitet: Fabio Freschi am 2 Sep. 2021
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

Weitere Antworten (0)

Kategorien

Mehr zu Performance and Memory finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by