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

조회 수: 14 (최근 30일)
Newbie
Newbie . 2021년 9월 1일
댓글: Newbie . 2021년 9월 2일
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.

채택된 답변

Fabio Freschi
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 CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by