-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathkuramNetwork.asv
64 lines (50 loc) · 1.83 KB
/
kuramNetwork.asv
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
%% Run Kuramoto oscillator through network
function [theta,r, psi] = kuramNetwork (testNet,Edges,N,Lam,omega,theta,numNodes)
% This script runs a kuramoto oscillator through a pre-generated network
% conditioned on local connections
% Numerical integration through fourth-order Runge-Kutta Method
% BC/ML/SWoNS/2018
% Code adapted from appmath.wordpress.com, courtesy
% Jeongho Kim, Mathematical Sciences, Seoul National University.
% Someone please clean
%% Generate network
iter = 250;
h = 0.1;
r = zeros(length(iter-1),1);
figure;
movegui('center');
for k = 1:iter-1
thetaConnect = theta(:,k)*ones(1,N)-(ones(N,1)*theta(:,k)'); %Generates phase matrix\
indEdgeConnect = adjacency(testNet);
thetaConnect(~indEdgeConnect) = 0; %no connection == 0
f1 = kuramoto (thetaConnect,Lam,N,omega);
f2=kuramoto(thetaConnect+0.5*h*f1(:,1),Lam,N,omega);
f3=kuramoto(thetaConnect+0.5*h*f2(:,1),Lam,N,omega); %4-th order Runge-Kutta method.
f4=kuramoto(thetaConnect+h*f3(:,1),Lam,N,omega);
theta(:,k+1) = theta(:,k)+(h/6)*(f1(:,1))+2*f2(:,1)+2*f3(:,1)+f4(:,1);
indOver = find (theta(:,k+1) > 2*pi);
indUnder = find (theta(:,k+1) < 0);
theta(indOver,k+1) = theta(indOver,k+1) - 2*pi;
theta(indUnder,k+1) = theta(indUnder,k+1) + 2*pi;
z = sum(exp(1i*theta(:,k+1)))/N;
r(k+1) = abs (z);
psi(k+1) = angle(z);
if k == iter/2
theta (:,k+1) = theta(:,k) .* randn(1,size(theta,1))'+50;
pause(1)
end
x=cos(theta(:,k));
y=sin(theta(:,k));
s=linspace(0,2*pi,100);
cx=cos(s);
cy=sin(s);
s = plot(x,y,'o',cx,cy);
set(s,'MarkerSize',20);
axis([-1 1 -1 1])
axis square
drawnow
end
function f=kuramoto(x,Lam,N,omega)
f=omega+(Lam/N)*sum(sin(x))'; %Take out rand for noise
end
end