{"id":5417,"date":"2019-10-30T17:27:36","date_gmt":"2019-10-30T22:27:36","guid":{"rendered":"https:\/\/blogs.mathworks.com\/cleve\/?p=5417"},"modified":"2019-10-30T17:32:00","modified_gmt":"2019-10-30T22:32:00","slug":"stability-of-kuramoto-oscillators","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/cleve\/2019\/10\/30\/stability-of-kuramoto-oscillators\/","title":{"rendered":"Stability of Kuramoto Oscillators"},"content":{"rendered":"<div class=\"content\"><!--introduction--><p>I am working with Indika Rajapakse and Steve Smale to investigate the stability of the dynamic system describing Kuramoto oscillators. Indika and Steve are interested in Kuramoto oscillators for two reasons; the self synchronization provides a model of the cells in a beating heart and the dynamic system is an example for Morse-Smale theory.  I am personally interested in the Kuramoto model as it relates to deep brain stimulation (DBS) for open-loop control of human movement disorders. My <tt>kuramoto<\/tt> program demonstrates both stable and unstable critical points.  Roundoff error may destabilize an unstable critical point.<\/p><!--\/introduction--><h3>Contents<\/h3><div><ul><li><a href=\"#932fe65d-a845-4012-ac24-fb21f626ec63\">The Potential<\/a><\/li><li><a href=\"#adfe36d6-2444-46db-835e-215c44822e31\">The Kuramoto Model<\/a><\/li><li><a href=\"#84e4bf7e-3d02-4440-a213-980e6878b010\">The Order Parameter<\/a><\/li><li><a href=\"#c0d1153b-174c-4cd4-a2bf-873cdf12b170\"><tt>kuramoto.m<\/tt><\/a><\/li><li><a href=\"#8cb26a33-f63c-45be-aa82-f0046a7f955e\">kappa = 0, beta = 0<\/a><\/li><li><a href=\"#b0cdbf2e-e6d1-441a-8aea-c8c1d01e71aa\">kappa = .75, beta = 0<\/a><\/li><li><a href=\"#39889500-1f63-4df3-8b3a-1bf5115aee7c\">kappa = .36, beta = .24<\/a><\/li><li><a href=\"#5a8f77c6-9f05-40ed-812d-acdb4c6d469a\">kappa = .36, beta = .23<\/a><\/li><li><a href=\"#3912872b-25ae-4d44-a396-445c26034027\">n = 100, kappa = .10, beta = .05<\/a><\/li><li><a href=\"#a9790c82-aadf-4230-b622-a72cb8cfd2f0\">Software<\/a><\/li><li><a href=\"#44ff65bd-89c2-49be-b168-ddb075d4183b\">Links<\/a><\/li><\/ul><\/div><h4>The Potential<a name=\"932fe65d-a845-4012-ac24-fb21f626ec63\"><\/a><\/h4><p>The Kuramoto model is a system of $n$ ordinary differential equations describing the time evolution, $\\theta_k(t)$ , of oscillating components.  The key to our analysis is expressing the equations in terms of the gradient of a potential function,<\/p><p>$$v(t) = \\frac{4}{n^2}\\sum_k{ \\sum_{j&gt;k}\r\n{\\sin^2{\\frac{\\theta_j(t)-\\theta_k(t)}{2}}}}$$<\/p><p>The $4\/n^2$ normalizes the potential so that<\/p><p>$$0 \\le v \\le 1$$<\/p><p>When all the $\\theta_k(t)$ are equal, the oscillators are perfectly synchronized and $v(t) = 0$.  On the other hand, if the $\\theta_k(t)$ are equally spaced throughout the interval $[0, 2\\pi]$, the oscillators are not synchronized and $v(1) = 1$.<\/p><p>The gradient of $v$, written $\\nabla v$, is the vector whose components are the partial derivatives,<\/p><p>$$\\frac{\\partial v}{\\partial\\theta_k}\r\n= -\\frac{2}{n^2} \\sum_j {\\sin{(\\theta_j-\\theta_k)}}$$<\/p><p>A <i>critical point<\/i> is any point where the gradient of the potential is zero.<\/p><h4>The Kuramoto Model<a name=\"adfe36d6-2444-46db-835e-215c44822e31\"><\/a><\/h4><p>The traditional form of Kuramoto's equation is<\/p><p>$$\\frac{d\\theta_k}{dt}\r\n= \\omega_k + \\frac{\\kappa}{n} \\sum_j {\\sin{(\\theta_j-\\theta_k)}}, \\\r\nk = 1,...,n$$<\/p><p>Here $\\omega_k$ is a constant, the natural frequency of the $k$-th oscillator, and $\\kappa$ is the coupling coefficient of the nonlinear synchronizing term.  Written in terms of the potential, the vector form of Kuramoto's equation becomes<\/p><p>$$\\frac{d\\theta}{dt}\r\n= \\omega - \\frac{\\kappa n}{2} \\nabla v(\\theta)$$<\/p><h4>The Order Parameter<a name=\"84e4bf7e-3d02-4440-a213-980e6878b010\"><\/a><\/h4><p>An oscillator $\\theta_k$ is often identified with the point on the unit circle $e^{i \\theta_k}$.  Think of this as the oscillator's <i>alter ego<\/i>.<\/p><p>The <i>average oscillator<\/i>, $\\psi$, is defined by<\/p><p>$$|z|e^{i \\psi} = \\frac{1}{n} \\sum_k e^{i \\theta_k}$$<\/p><p>The magnitude $|z|$ provides another measure of synchronization, the <i>order parameter<\/i>.  A reference frame rotating with frequency $\\psi$ is frequently convenient.<\/p><p>When the $\\theta_k$ are initialized to be equally spaced on $[0,2\\pi]$, their average should be zero, so $|z|$ should be zero and $\\psi$ is not uniquely defined.  But in practice with finite precision arithmetic, <tt>pi<\/tt> is not exactly equal to $\\pi$ and the initial $\\theta_k$ are not exactly equally spaced.  Even if they were, there would be roundoff error in the computation of their average.  As a result, the computed $|z|$ is not exactly zero, the computed <tt>psi<\/tt> can take on almost any value and the rotating reference frame may behave erratically.<\/p><p>The potential and the order parameter provide complementary measures of synchronicity; when one of them is equal to zero the other is equal to one.  We would like to know a more quantitative relation between the two.<\/p><h4><tt>kuramoto.m<\/tt><a name=\"c0d1153b-174c-4cd4-a2bf-873cdf12b170\"><\/a><\/h4><p>My program <tt>kuramoto<\/tt> allows you to experiment with Kuramoto's model. The crucial parameters are the strength of the synchronizing term <tt>kappa<\/tt> and the spread of the intrinsic frequencies <tt>beta<\/tt>. Five radio buttons labeled <tt>preset<\/tt> correspond to the five situations described in the remainder of this blog post.<\/p><h4>kappa = 0, beta = 0<a name=\"8cb26a33-f63c-45be-aa82-f0046a7f955e\"><\/a><\/h4><p>This example illustrates the effect of roundoff error on the simulation. With <tt>beta<\/tt> equal to zero, all the intrinsic frequencies are equal to one.  And with <tt>kappa<\/tt> equal to zero, there is no synchronizing term.  So the dynamical system is simply<\/p><p>$$\\frac{d\\theta_k(t)}{dt} = 1,\\ k = 1,...,n$$<\/p><p>For the initial conditions, distribute $\\theta_k(0)$ evenly over the interval $[0, 2\\pi]$,<\/p><p>$$\\theta_k(0) = \\frac{2k\\pi}{n}$$<\/p><p>The exact solution, then, is<\/p><p>$$\\theta_k(t) = t + \\frac{2k\\pi}{n},\\ k = 1,...,n$$<\/p><p>This is an unstable critical point.  The $\\theta_k(t)$ will remain equally spaced over $[0,2\\pi]$ and their alter egos $e^{i \\theta_k(t)}$ will be distributed evenly around the unit circle, <i>unless<\/i> something disturbs them.<\/p><p>But, since we are anticipating systems which don't have such neat solutions, we use the venerable MATLAB ode solver <tt>ode45<\/tt>, to compute numerical solutions.  This potentially introduces perturbations from both the discretion error of the numerical method and the roundoff error of the finite precision arithmetic.  Let's see the result with this animated gif.  Watch carefully.<\/p><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/k3_gif1.gif\" alt=\"\"> <\/p><p>Did you notice the little jiggles?  Gremlins at work?  They are harmless, but interesting. I haven't dug into the details of <tt>ode45<\/tt>.  It is integrating a constant, so there shouldn't be any discretization error.  But there is still roundoff error.<\/p><p>Consider a simpler stand-in -- Euler's method. There is a fixed step step size <tt>h<\/tt>.  There is the constant vector<\/p><p><tt>omega = ones(n,1)<\/tt><\/p><p>The differential equation is incredibly simple; the derivative does not depend upon either <tt>t<\/tt> or <tt>theta<\/tt>.<\/p><p><tt>f(t,theta) = omega<\/tt><\/p><p>The initial values are<\/p><p><tt>theta0 = (1:n)\/n*2*pi<\/tt><\/p><p><tt>t = 0<\/tt><\/p><p><tt>theta = theta0<\/tt><\/p><p>Euler would simply accumulate the scalar time<\/p><p><tt>t = t + h<\/tt><\/p><p>And the vector solution<\/p><p><tt>theta = theta + h*omega<\/tt><\/p><p>There would be roundoff error, provided <tt>h<\/tt> is not an inverse power of two, but is like our old friend <tt>0.1<\/tt>.<\/p><p>Here is the actual error observed with <tt>kuramoto<\/tt> using <tt>ode45<\/tt>. The exact solution should be<\/p><p><tt>theta == t + theta0<\/tt><\/p><p>I have plotted the <i>relative error<\/i> in units of <tt>eps(theta)<\/tt>, a single rounding error in the computed solution.<\/p><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/k3_fig1a.png\" alt=\"\"> <\/p><p>There is action whenever <tt>t<\/tt> passes a power of two -- 8, 16, 32, 64, 128. It would go on like this forever.  Temporary pulses of a couple of dozen rounding errors.  Look back at the animated gif.  It jiggles whenever <tt>t<\/tt> passes a power of two.<\/p><p>Roundoff error is rarely important in the numerical solution of ordinary differential equations.  It shows up here only because nothing else is happening.<\/p><h4>kappa = .75, beta = 0<a name=\"b0cdbf2e-e6d1-441a-8aea-c8c1d01e71aa\"><\/a><\/h4><p>This is a clean example of synchronization.  All the omegas are the same and there is a strong coupling coefficient.  The oscillators fall into lock step and the potential rapidly drops to zero.<\/p><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/k3_gif2.gif\" alt=\"\"> <\/p><p>A plot of <tt>theta-t<\/tt> versus <tt>t<\/tt> shows the oscillators agreeing to meet at their average value.<\/p><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/k3_fig2a.png\" alt=\"\"> <\/p><p>Here is the strength of the nonlinear synchronizing term, the gradient of the potential.<\/p><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/k3_fig2b.png\" alt=\"\"> <\/p><p>Here is a closer look at <tt>grad(v)<\/tt>.  It's a signed logarithmic plot. Two of the components of <tt>grad(v)<\/tt> are positive, two are negative and one, colored blue-green, changes sign.  I've plotted the logarithms of the absolute values with a split y-axis reflecting the sign of the component.  Most of the time, the graphs of the logarithms are straight lines, indicating the corresponding components are growing or decaying exponentially, starting or ending at tiny values.  When these components reach a critical size, the oscillators synchronize.<\/p><p>I haven't yet analyzed the slopes of these logarithms, so I don't know the rates of exponential growth or decay.  I'll leave that as homework.  Please let me know if you come up with anything.<\/p><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/k3_fig2c.png\" alt=\"\"> <\/p><h4>kappa = .36, beta = .24<a name=\"39889500-1f63-4df3-8b3a-1bf5115aee7c\"><\/a><\/h4><p>The remaining cases in this post all have nonzero values of <tt>beta<\/tt>, so the intrinsic frequencies, in the vector <tt>omega<\/tt>, are not all equal to one, but are evenly spaced in the interval <tt>[1-beta,1+beta]<\/tt>. In this particular case, the spacing <tt>beta<\/tt> is large enough that the nonlinear coupling strength, <tt>kappa<\/tt>, cannot force synchronization.  The oscillators just barely fail to agree on a common frequency.<\/p><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/k3_gif3.gif\" alt=\"\"> <\/p><p>When the $e^{i \\theta_k}$ are plotted around the unit circle the oscillators appear to periodically approach a common value. But a plot of $\\theta_k(t)-t$ versus $t$ reveals that they are diverging from each other.  The unit circle motion is based on $\\theta_k(t) \\ \\mbox{mod} \\ 2\\pi$.<\/p><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/k3_fig3a.png\" alt=\"\"> <\/p><p><tt>grad(v)<\/tt> is very busy.<\/p><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/k3_fig3b.png\" alt=\"\"> <\/p><h4>kappa = .36, beta = .23<a name=\"5a8f77c6-9f05-40ed-812d-acdb4c6d469a\"><\/a><\/h4><p>Decreasing the spread of the intrinsic frequencies a little bit from <tt>beta = .24<\/tt> to <tt>beta = .23<\/tt> causes the oscillators to approach, but not reach, synchronicity.  Their differences remain constant, so the potential is constant, but not zero.  The system is stable. They are <i>phase locked<\/i>.<\/p><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/k3_gif4.gif\" alt=\"\"> <\/p><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/k3_fig4a.png\" alt=\"\"> <\/p><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/k3_fig4b.png\" alt=\"\"> <\/p><h4>n = 100, kappa = .10, beta = .05<a name=\"3912872b-25ae-4d44-a396-445c26034027\"><\/a><\/h4><p>Finally, let's increase the size of the population to <tt>n = 100<\/tt>. And, for the first case in this post, introduce some randomness. <tt>omega<\/tt> is sampled from a normal distribution, centered around one, with standard deviation <tt>beta<\/tt>. The random number generator has been set with <tt>rng<\/tt> so that I get the same sample on each run. Watch the single oscillator, colored blue-green, catch up to the others. The oscillators approach a stable, phase locked configuration. The potential approaches a constant, nonzero value.<\/p><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/k3_gif5.gif\" alt=\"\"> <\/p><p>The plot of <tt>theta-t<\/tt> shows the evolution of the oscillators into three stable clumps, separated by multiples of $2\\pi$. Many of the fast oscillators, colored shades of blue, form one clump. Some of the slow oscillators, colored shades of yellow, form a slow pack.  The majority are in a central group.  The blue-green guy is slower than the others deciding which clump to join.  The animation views the world mod $2\\pi$ and consequently sees only one clump.  (If I were still using our <tt>jet<\/tt> color map, the fast and slow groups would be red and blue, evokinging a political analogy. I'm not going there.)<\/p><p>This picture depends strongly on the random sampling.  Running the simulation again may produce a different number of clumps.<\/p><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/k3_fig5a.png\" alt=\"\"> <\/p><p>A plot of the gradient of the potential shows it settling down to a constant vector.  It also hints at structure yet to be explored.<\/p><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/k3_fig5b.png\" alt=\"\"> <\/p><h4>Software<a name=\"a9790c82-aadf-4230-b622-a72cb8cfd2f0\"><\/a><\/h4><p>I have updated <tt>kuramoto<\/tt> on the MATLAB Central File Exchange. <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/72534\">Here is the link<\/a>. I have also included it in <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/59085-cleve_s-laboratory\">version 4.80 of Cleve's Laboratory<\/a>.<\/p><h4>Links<a name=\"44ff65bd-89c2-49be-b168-ddb075d4183b\"><\/a><\/h4><p>Wikipedia, Kuramoto model, <a href=\"https:\/\/en.wikipedia.org\/wiki\/Kuramoto_model\">https:\/\/en.wikipedia.org\/wiki\/Kuramoto_model<\/a>.<\/p><p>Dirk Brockman and Steven Strogatz, \"Ride my Kuramotocycle\", <a href=\"https:\/\/www.complexity-explorables.org\/explorables\/ride-my-kuramotocycle\">https:\/\/www.complexity-explorables.org\/explorables\/ride-my-kuramotocycle<\/a>.<\/p><p>Cleve Moler, \"Kuramoto Model of Synchronized Oscillators\", <a href=\"https:\/\/blogs.mathworks.com\/cleve\/2019\/08\/26\/kuramoto-model-of-synchronized-oscillators\">https:\/\/blogs.mathworks.com\/cleve\/2019\/08\/26\/kuramoto-model-of-synchronized-oscillators<\/a>.<\/p><p>Cleve Moler, \"Experiments with Kuramoto Oscillators\", <a href=\"https:\/\/blogs.mathworks.com\/cleve\/2019\/09\/16\/experiments-with-kuramoto-oscillators\">https:\/\/blogs.mathworks.com\/cleve\/2019\/09\/16\/experiments-with-kuramoto-oscillators<\/a>.<\/p><script language=\"JavaScript\"> <!-- \r\n    function grabCode_846f2140c1a745528bdde6092d9545b3() {\r\n        \/\/ Remember the title so we can use it in the new page\r\n        title = document.title;\r\n\r\n        \/\/ Break up these strings so that their presence\r\n        \/\/ in the Javascript doesn't mess up the search for\r\n        \/\/ the MATLAB code.\r\n        t1='846f2140c1a745528bdde6092d9545b3 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 846f2140c1a745528bdde6092d9545b3';\r\n    \r\n        b=document.getElementsByTagName('body')[0];\r\n        i1=b.innerHTML.indexOf(t1)+t1.length;\r\n        i2=b.innerHTML.indexOf(t2);\r\n \r\n        code_string = b.innerHTML.substring(i1, i2);\r\n        code_string = code_string.replace(\/REPLACE_WITH_DASH_DASH\/g,'--');\r\n\r\n        \/\/ Use \/x3C\/g instead of the less-than character to avoid errors \r\n        \/\/ in the XML parser.\r\n        \/\/ Use '\\x26#60;' instead of '<' so that the XML parser\r\n        \/\/ doesn't go ahead and substitute the less-than character. \r\n        code_string = code_string.replace(\/\\x3C\/g, '\\x26#60;');\r\n\r\n        copyright = 'Copyright 2019 The MathWorks, Inc.';\r\n\r\n        w = window.open();\r\n        d = w.document;\r\n        d.write('<pre>\\n');\r\n        d.write(code_string);\r\n\r\n        \/\/ Add copyright line at the bottom if specified.\r\n        if (copyright.length > 0) {\r\n            d.writeln('');\r\n            d.writeln('%%');\r\n            if (copyright.length > 0) {\r\n                d.writeln('% _' + copyright + '_');\r\n            }\r\n        }\r\n\r\n        d.write('<\/pre>\\n');\r\n\r\n        d.title = title + ' (MATLAB code)';\r\n        d.close();\r\n    }   \r\n     --> <\/script><p style=\"text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray\"><br><a href=\"javascript:grabCode_846f2140c1a745528bdde6092d9545b3()\"><span style=\"font-size: x-small;        font-style: italic;\">Get \r\n      the MATLAB code <noscript>(requires JavaScript)<\/noscript><\/span><\/a><br><br>\r\n      Published with MATLAB&reg; R2018b<br><\/p><\/div><!--\r\n846f2140c1a745528bdde6092d9545b3 ##### SOURCE BEGIN #####\r\n%% Stability of Kuramoto Oscillators\r\n% I am working with Indika Rajapakse and Steve Smale to investigate the\r\n% stability of the dynamic system describing Kuramoto oscillators.\r\n% Indika and Steve are interested in Kuramoto oscillators for two reasons;\r\n% the self synchronization provides a model of the cells in a beating\r\n% heart and the dynamic system is an example for Morse-Smale theory.  I am\r\n% personally interested in the Kuramoto model as it relates to deep brain\r\n% stimulation (DBS) for open-loop control of human movement disorders.\r\n% My |kuramoto| program demonstrates both stable and unstable critical\r\n% points.  Roundoff error may destabilize an unstable critical point.\r\n\r\n%% The Potential\r\n% The Kuramoto model is a system of $n$ ordinary differential equations\r\n% describing the time evolution, $\\theta_k(t)$ , of\r\n% oscillating components.  The key to our analysis is expressing the\r\n% equations in terms of the gradient of a potential function,\r\n%\r\n% $$v(t) = \\frac{4}{n^2}\\sum_k{ \\sum_{j>k}\r\n% {\\sin^2{\\frac{\\theta_j(t)-\\theta_k(t)}{2}}}}$$\r\n%\r\n% The $4\/n^2$ normalizes the potential so that\r\n%\r\n% $$0 \\le v \\le 1$$\r\n\r\n%%\r\n% When all the $\\theta_k(t)$ are equal, the oscillators are perfectly\r\n% synchronized and $v(t) = 0$.  On the other hand, if the $\\theta_k(t)$\r\n% are equally spaced throughout the interval $[0, 2\\pi]$,\r\n% the oscillators are not synchronized and $v(1) = 1$.\r\n\r\n%%\r\n% The gradient of $v$, written $\\nabla v$, is the vector whose components\r\n% are the partial derivatives,\r\n%\r\n% $$\\frac{\\partial v}{\\partial\\theta_k}\r\n% = -\\frac{2}{n^2} \\sum_j {\\sin{(\\theta_j-\\theta_k)}}$$\r\n%\r\n% A _critical point_ is any point where the gradient of the potential\r\n% is zero.\r\n\r\n%% The Kuramoto Model\r\n% The traditional form of Kuramoto's equation is\r\n%\r\n% $$\\frac{d\\theta_k}{dt}\r\n% = \\omega_k + \\frac{\\kappa}{n} \\sum_j {\\sin{(\\theta_j-\\theta_k)}}, \\\r\n% k = 1,...,n$$\r\n%\r\n% Here $\\omega_k$ is a constant, the natural frequency of the $k$-th\r\n% oscillator, and $\\kappa$ is the coupling coefficient of the nonlinear\r\n% synchronizing term.  Written in terms of the potential, the vector\r\n% form of Kuramoto's equation becomes\r\n%\r\n% $$\\frac{d\\theta}{dt}\r\n% = \\omega - \\frac{\\kappa n}{2} \\nabla v(\\theta)$$\r\n%\r\n\r\n%% The Order Parameter\r\n% An oscillator $\\theta_k$ is often identified with the point on the unit\r\n% circle $e^{i \\theta_k}$.  Think of this as the oscillator's _alter ego_.\r\n%\r\n% The _average oscillator_, $\\psi$, is defined by\r\n%\r\n% $$|z|e^{i \\psi} = \\frac{1}{n} \\sum_k e^{i \\theta_k}$$\r\n%\r\n% The magnitude $|z|$ provides another measure of synchronization,\r\n% the _order parameter_.  A reference frame rotating with frequency\r\n% $\\psi$ is frequently convenient.\r\n\r\n%%\r\n% When the $\\theta_k$ are initialized to be equally spaced on $[0,2\\pi]$,\r\n% their average should be zero, so $|z|$ should be zero and $\\psi$ is not\r\n% uniquely defined.  But in practice with finite precision arithmetic,\r\n% |pi| is not exactly equal to $\\pi$ and the initial $\\theta_k$ are not\r\n% exactly equally spaced.  Even if they were, there would be roundoff\r\n% error in the computation of their average.  As a result, the computed\r\n% $|z|$ is not exactly zero, the computed |psi| can take on almost any\r\n% value and the rotating reference frame may behave erratically.\r\n\r\n%%\r\n% The potential and the order parameter provide complementary measures of\r\n% synchronicity; when one of them is equal to zero the other is equal to\r\n% one.  We would like to know a more quantitative relation between the two.\r\n\r\n%% |kuramoto.m|\r\n% My program |kuramoto| allows you to experiment with Kuramoto's model.\r\n% The crucial parameters are the strength of the synchronizing term\r\n% |kappa| and the spread of the intrinsic frequencies |beta|.\r\n% Five radio buttons labeled |preset| correspond to the five situations\r\n% described in the remainder of this blog post.\r\n\r\n%% kappa = 0, beta = 0\r\n% This example illustrates the effect of roundoff error on the simulation.\r\n% With |beta| equal to zero, all the intrinsic frequencies\r\n% are equal to one.  And with |kappa| equal to zero, there is no\r\n% synchronizing term.  So the dynamical system is simply\r\n%\r\n% $$\\frac{d\\theta_k(t)}{dt} = 1,\\ k = 1,...,n$$\r\n% \r\n% For the initial conditions, distribute $\\theta_k(0)$ evenly over the\r\n% interval $[0, 2\\pi]$,\r\n%\r\n% $$\\theta_k(0) = \\frac{2k\\pi}{n}$$\r\n%\r\n% The exact solution, then, is\r\n%\r\n% $$\\theta_k(t) = t + \\frac{2k\\pi}{n},\\ k = 1,...,n$$\r\n%\r\n% This is an unstable critical point.  The $\\theta_k(t)$ will remain\r\n% equally spaced over $[0,2\\pi]$ and their alter egos $e^{i \\theta_k(t)}$\r\n% will be distributed evenly around the unit circle, _unless_ something\r\n% disturbs them.\r\n\r\n%%\r\n% But, since we are anticipating systems which don't have such neat\r\n% solutions, we use the venerable MATLAB ode solver |ode45|, to compute\r\n% numerical solutions.  This potentially introduces perturbations from\r\n% both the discretion error of the numerical method and the roundoff error\r\n% of the finite precision arithmetic.  Let's see the result with this\r\n% animated gif.  Watch carefully.\r\n%\r\n% <<k3_gif1.gif>>\r\n%\r\n% Did you notice the little jiggles?  Gremlins at work?  They are\r\n% harmless, but interesting. I haven't dug into the details\r\n% of |ode45|.  It is integrating a constant, so there shouldn't be any\r\n% discretization error.  But there is still roundoff error.\r\n\r\n%%\r\n% Consider a simpler stand-in REPLACE_WITH_DASH_DASH Euler's method.\r\n% There is a fixed step step size |h|.  There is the constant vector\r\n%\r\n% |omega = ones(n,1)|\r\n%\r\n% The differential equation is incredibly simple; the derivative does\r\n% not depend upon either |t| or |theta|.\r\n%\r\n% |f(t,theta) = omega|\r\n%\r\n% The initial values are\r\n%\r\n% |theta0 = (1:n)\/n*2*pi| \r\n%\r\n% |t = 0|\r\n%\r\n% |theta = theta0|\r\n\r\n%%\r\n% Euler would simply accumulate the scalar time\r\n%\r\n% |t = t + h|\r\n%\r\n% And the vector solution\r\n%\r\n% |theta = theta + h*omega|\r\n%\r\n% There would be roundoff error, provided |h| is not an inverse power\r\n% of two, but is like our old friend |0.1|.\r\n\r\n%%\r\n% Here is the actual error observed with |kuramoto| using |ode45|.\r\n% The exact solution should be\r\n%\r\n% |theta == t + theta0|\r\n%\r\n% I have plotted the _relative error_ in units of |eps(theta)|,\r\n% a single rounding error in the computed solution.\r\n%\r\n% <<k3_fig1a.png>>\r\n%\r\n% There is action whenever |t| passes a power of two REPLACE_WITH_DASH_DASH 8, 16, 32, 64, 128.\r\n% It would go on like this forever.  Temporary pulses of a couple of dozen\r\n% rounding errors.  Look back at the animated gif.  It jiggles whenever |t|\r\n% passes a power of two.\r\n\r\n%%\r\n% Roundoff error is rarely important in the numerical solution of ordinary\r\n% differential equations.  It shows up here only because nothing else is\r\n% happening.\r\n\r\n%% kappa = .75, beta = 0\r\n% This is a clean example of synchronization.  All the omegas are the\r\n% same and there is a strong coupling coefficient.  The oscillators\r\n% fall into lock step and the potential rapidly drops to zero.\r\n%\r\n% <<k3_gif2.gif>>\r\n%\r\n% A plot of |theta-t| versus |t| shows the oscillators agreeing to meet\r\n% at their average value.\r\n%\r\n% <<k3_fig2a.png>>\r\n%\r\n% Here is the strength of the nonlinear synchronizing term,\r\n% the gradient of the potential.\r\n%\r\n% <<k3_fig2b.png>>\r\n%\r\n% Here is a closer look at |grad(v)|.  It's a signed logarithmic plot.\r\n% Two of the components of |grad(v)| are positive, two are negative\r\n% and one, colored blue-green, changes sign.  I've plotted the logarithms\r\n% of the absolute values with a split y-axis reflecting the sign of the\r\n% component.  Most of the time, the graphs\r\n% of the logarithms are straight lines, indicating the corresponding\r\n% components are growing or decaying exponentially, starting or ending\r\n% at tiny values.  When these components reach a critical size,\r\n% the oscillators synchronize.\r\n%\r\n% I haven't yet analyzed the slopes of these logarithms, so I don't\r\n% know the rates of exponential growth or decay.  I'll leave that as\r\n% homework.  Please let me know if you come up with anything.\r\n%\r\n% <<k3_fig2c.png>>\r\n\r\n%% kappa = .36, beta = .24\r\n% The remaining cases in this post all have nonzero values of |beta|,\r\n% so the intrinsic frequencies, in the vector |omega|, are not all equal\r\n% to one, but are evenly spaced in the interval |[1-beta,1+beta]|.\r\n% In this particular case, the spacing |beta|\r\n% is large enough that the nonlinear coupling strength,\r\n% |kappa|, cannot force synchronization.  The oscillators just barely\r\n% fail to agree on a common frequency.\r\n%\r\n% <<k3_gif3.gif>>\r\n%\r\n% When the $e^{i \\theta_k}$ are plotted around the unit circle\r\n% the oscillators appear to periodically approach a common value.\r\n% But a plot of $\\theta_k(t)-t$ versus $t$ reveals that they are\r\n% diverging from each other.  The unit circle motion is based on\r\n% $\\theta_k(t) \\ \\mbox{mod} \\ 2\\pi$.\r\n%\r\n% <<k3_fig3a.png>>\r\n%\r\n% |grad(v)| is very busy.\r\n%\r\n% <<k3_fig3b.png>>\r\n\r\n%% kappa = .36, beta = .23\r\n% Decreasing the spread of the intrinsic frequencies a little bit\r\n% from |beta = .24| to |beta = .23| causes the oscillators to approach,\r\n% but not reach, synchronicity.  Their differences remain constant,\r\n% so the potential is constant, but not zero.  The system is stable.\r\n% They are _phase locked_.\r\n%\r\n% <<k3_gif4.gif>>\r\n%\r\n% <<k3_fig4a.png>>\r\n%\r\n% <<k3_fig4b.png>>\r\n%\r\n\r\n%% n = 100, kappa = .10, beta = .05\r\n% Finally, let's increase the size of the population to |n = 100|.\r\n% And, for the first case in this post, introduce some randomness.\r\n% |omega| is sampled from a normal distribution, centered around one,\r\n% with standard deviation |beta|.\r\n% The random number generator has been set with |rng| so that I get\r\n% the same sample on each run.\r\n% Watch the single oscillator, colored blue-green, catch up to the\r\n% others.\r\n% The oscillators approach a stable, phase locked configuration.\r\n% The potential approaches a constant, nonzero value.\r\n%\r\n% <<k3_gif5.gif>>\r\n%\r\n% The plot of |theta-t| shows the evolution of the oscillators into\r\n% three stable clumps, separated by multiples of $2\\pi$.\r\n% Many of the fast oscillators, colored shades of blue, form one clump.\r\n% Some of the slow oscillators, colored shades of yellow, form a slow\r\n% pack.  The majority are in a central group.  The blue-green\r\n% guy is slower than the others deciding which clump to join.  The \r\n% animation views the world mod $2\\pi$ and consequently sees only one\r\n% clump.  (If I were still using our |jet| color map, the fast and slow\r\n% groups would be red and blue, evokinging a political analogy.\r\n% I'm not going there.)\r\n%\r\n% This picture depends strongly on the random sampling.  Running the\r\n% simulation again may produce a different number of clumps.\r\n%\r\n% <<k3_fig5a.png>>\r\n%\r\n% A plot of the gradient of the potential shows it settling down to\r\n% a constant vector.  It also hints at structure yet to be explored.\r\n%\r\n% <<k3_fig5b.png>>\r\n%\r\n\r\n%% Software\r\n% I have updated |kuramoto| on the MATLAB Central File Exchange.\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/72534\r\n% Here is the link>. I have also included it in\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/59085-cleve_s-laboratory\r\n% version 4.80 of Cleve's Laboratory>.\r\n\r\n%% Links\r\n%\r\n% Wikipedia, Kuramoto model, <https:\/\/en.wikipedia.org\/wiki\/Kuramoto_model>.\r\n%\r\n% Dirk Brockman and Steven Strogatz, \"Ride my Kuramotocycle\",\r\n% <https:\/\/www.complexity-explorables.org\/explorables\/ride-my-kuramotocycle>.\r\n%\r\n% Cleve Moler, \"Kuramoto Model of Synchronized Oscillators\",\r\n% <https:\/\/blogs.mathworks.com\/cleve\/2019\/08\/26\/kuramoto-model-of-synchronized-oscillators>.\r\n%\r\n% Cleve Moler, \"Experiments with Kuramoto Oscillators\",\r\n% <https:\/\/blogs.mathworks.com\/cleve\/2019\/09\/16\/experiments-with-kuramoto-oscillators>.\r\n##### SOURCE END ##### 846f2140c1a745528bdde6092d9545b3\r\n-->","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img src=\"https:\/\/blogs.mathworks.com\/cleve\/files\/k3_fig5b-1.png\" class=\"img-responsive attachment-post-thumbnail size-post-thumbnail wp-post-image\" alt=\"\" decoding=\"async\" loading=\"lazy\" \/><\/div><!--introduction--><p>I am working with Indika Rajapakse and Steve Smale to investigate the stability of the dynamic system describing Kuramoto oscillators. Indika and Steve are interested in Kuramoto oscillators for two reasons; the self synchronization provides a model of the cells in a beating heart and the dynamic system is an example for Morse-Smale theory.  I am personally interested in the Kuramoto model as it relates to deep brain stimulation (DBS) for open-loop control of human movement disorders. My <tt>kuramoto<\/tt> program demonstrates both stable and unstable critical points.  Roundoff error may destabilize an unstable critical point.... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/cleve\/2019\/10\/30\/stability-of-kuramoto-oscillators\/\">read more >><\/a><\/p>","protected":false},"author":78,"featured_media":5481,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[24,5,23],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/posts\/5417"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/users\/78"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/comments?post=5417"}],"version-history":[{"count":4,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/posts\/5417\/revisions"}],"predecessor-version":[{"id":5561,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/posts\/5417\/revisions\/5561"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/media\/5481"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/media?parent=5417"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/categories?post=5417"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/tags?post=5417"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}