{"id":2210,"date":"2016-12-25T12:00:57","date_gmt":"2016-12-25T17:00:57","guid":{"rendered":"https:\/\/blogs.mathworks.com\/cleve\/?p=2210"},"modified":"2016-12-14T14:21:08","modified_gmt":"2016-12-14T19:21:08","slug":"seasons-greetings-fractal","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/cleve\/2016\/12\/25\/seasons-greetings-fractal\/","title":{"rendered":"Season&#8217;s Greetings Fractal"},"content":{"rendered":"\r\n\r\n<div class=\"content\"><!--introduction--><p>I don't recall where I found this seasonal fractal. And I can't explain how it works. So please submit a comment if you can shed any light on either of these questions.<\/p><!--\/introduction--><h3>Contents<\/h3><div><ul><li><a href=\"#3dc8ad7b-6659-4a95-a406-2f83d6003710\">Season's Greetings<\/a><\/li><li><a href=\"#a57918c0-2ede-405c-b6ce-f423f55d3cf8\">The Formula<\/a><\/li><li><a href=\"#9a0ea520-e5c5-4025-b215-1cae86f7b9bf\">Traditional p = 2<\/a><\/li><li><a href=\"#7320c9cd-c085-471a-985f-16efc39b7328\">p = 2\/3<\/a><\/li><li><a href=\"#16343437-fd67-401c-8ce3-e8f71dc39f77\">p = 5\/4<\/a><\/li><li><a href=\"#bc3defe3-f305-4dfc-b0a6-cb9fb2aaed73\">p = 4<\/a><\/li><li><a href=\"#79ea7a41-68a5-4ab0-bd6e-4df5ba27b6db\">Today's code<\/a><\/li><li><a href=\"#14164629-065a-495e-9b7b-255db4d58cd4\">Postscript<\/a><\/li><\/ul><\/div><h4>Season's Greetings<a name=\"3dc8ad7b-6659-4a95-a406-2f83d6003710\"><\/a><\/h4><p>I have featured a fractal at this time of the year in two previous years.  I see Christmas trees or perhaps a holly decoration.<\/p><div><ul><li><a href=\"https:\/\/blogs.mathworks.com\/cleve\/2012\/12\/24\/seasons-greetings\/?s_tid=srchtitle\">Season's Greetings 2012<\/a><\/li><li><a href=\"https:\/\/blogs.mathworks.com\/cleve\/2014\/12\/25\/seasons-greetings-2014\/?s_tid=srchtitle\">Season's Greetings 2014<\/a><\/li><\/ul><\/div><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/cleve\/files\/greeting_2012.png\" alt=\"\"> <\/p><h4>The Formula<a name=\"a57918c0-2ede-405c-b6ce-f423f55d3cf8\"><\/a><\/h4><p>All these figures are obtained by varying the parameters in a formula that generates complex numbers $z$ from the partial sums.<\/p><p>$$ z = \\sum_n{\\exp{(\\phi n^p+\\sigma) \\pi i}} $$<\/p><p>A vector of points in the complex plane is produced by taking $n$ to be a vector of consecutive integers and using the MATLAB cumulative summation function <tt>cumsum<\/tt> to compute the partial sums. There are 8600 points in the figure above and 100,000 points in the figures below.<\/p><p>The default value of the parameter $\\phi$ is my old friend the <tt>golden ratio<\/tt>.<\/p><p>$$ \\phi = \\frac{1+\\sqrt{5}}{2} $$<\/p><p>In previous posts I've taken $\\phi$ to be other rational and irrational numbers, but today I am sticking to this value.<\/p><p>The parameter $\\sigma$ controls the angular orientation.  Taking $\\sigma$ near $1\/8$ makes the large Christmas tree vertical.<\/p><p>While trying how to understand how this thing works I've varied the power $p$ from its usual value of 2 and taken hundreds of thousands of points. This produces today's pictures.  Different values of $p$ produce wildly different results.<\/p><p>For a real variable $x$, the expression $\\exp (x \\pi i)$ is periodic and lies on the unit circle in the complex plane.  So we are plotting the cumulative sum of values taken from around the unit circle.  At first glance, this appears to be a complex valued random number generator. But it is a lousy generator because we can see Christmas trees in the output.<\/p><h4>Traditional p = 2<a name=\"9a0ea520-e5c5-4025-b215-1cae86f7b9bf\"><\/a><\/h4><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/cleve\/files\/greetings1.gif\" alt=\"\"> <\/p><h4>p = 2\/3<a name=\"7320c9cd-c085-471a-985f-16efc39b7328\"><\/a><\/h4><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/cleve\/files\/greetings2.gif\" alt=\"\"> <\/p><h4>p = 5\/4<a name=\"16343437-fd67-401c-8ce3-e8f71dc39f77\"><\/a><\/h4><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/cleve\/files\/greetings3.gif\" alt=\"\"> <\/p><h4>p = 4<a name=\"bc3defe3-f305-4dfc-b0a6-cb9fb2aaed73\"><\/a><\/h4><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/cleve\/files\/greetings4.gif\" alt=\"\"> <\/p><h4>Today's code<a name=\"79ea7a41-68a5-4ab0-bd6e-4df5ba27b6db\"><\/a><\/h4><pre class=\"codeinput\">   type <span class=\"string\">greetings_gifs<\/span>\r\n<\/pre><pre class=\"codeoutput\">\r\nfunction greetings_gifs\r\n% Generate animated season's greeting gifs.\r\n\r\n    % Generate the fractal\r\n    phi = (1+sqrt(5))\/2;\r\n    s = 1\/8;\r\n    n = 100000;\r\n    for gifnum = 1:4\r\n        switch gifnum\r\n            case 1, p = 2;\r\n            case 2, p = 2\/3;\r\n            case 3, p = 1.25;\r\n            case 4, p = 4;\r\n        end\r\n        w = exp((phi*(0:n).^p+s)*pi*1i);\r\n        z = cumsum(w);\r\n\r\n        % Find local extrema\r\n        ks = extrema(z);\r\n\r\n        % Make an animated gif\r\n        plotit(z,p,ks,gifnum)\r\n \r\n    end % gifnum\r\n    \r\n    % ------------------------\r\n    \r\n    function ks = extrema(z)\r\n        n = length(z)-1;\r\n        m = n\/40;\r\n        ks = [];\r\n        for j = 0:m:n-m\r\n            zj = z(j+1:j+m);\r\n            w = zj - mean(zj);\r\n            k = find(abs(w) == max(abs(w))) + j;\r\n            ks = [ks k];\r\n        end\r\n    end % extrema\r\n    \r\n    function plotit(z,p,ks,gifnum)\r\n        % Make an animated gif\r\n        shg\r\n        plot(z,'.')\r\n        axis square\r\n        ax = axis;\r\n        gif_frame(['greetings' int2str(gifnum) '.gif'])\r\n        clf\r\n        axis(ax)\r\n        axis square\r\n        gif_frame\r\n        for j = 1:length(ks)\r\n            k = ks(j);\r\n            plot(z(1:k),'k.','markersize',0.5)\r\n            axis(ax)\r\n            axis square\r\n            hold on\r\n            plot(z(ks(1:j)),'g.','markersize',18)\r\n            plot(z(k),'r.','markersize',24)\r\n            hold off\r\n            title(sprintf('p = %4.2f',p))\r\n            gif_frame\r\n        end\r\n        gif_frame(5)\r\n        gif_frame('reset')\r\n    end % plotit\r\nend % greetings_gifs\r\n<\/pre><h4>Postscript<a name=\"14164629-065a-495e-9b7b-255db4d58cd4\"><\/a><\/h4><p><i>Happy New Year.<\/i><\/p><script language=\"JavaScript\"> <!-- \r\n    function grabCode_ce9fc6f29e12441182d484eced8f1c03() {\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='ce9fc6f29e12441182d484eced8f1c03 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' ce9fc6f29e12441182d484eced8f1c03';\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 2016 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_ce9fc6f29e12441182d484eced8f1c03()\"><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; R2016a<br><\/p><\/div><!--\r\nce9fc6f29e12441182d484eced8f1c03 ##### SOURCE BEGIN #####\r\n%% Season's Greetings Fractal\r\n% I don't recall where I found this seasonal fractal.\r\n% And I can't explain how it works.\r\n% So please submit a comment if you can shed any light on either of these\r\n% questions.\r\n\r\n%% Season's Greetings\r\n% I have featured a fractal at this time of the year in two\r\n% previous years.  I see Christmas trees or perhaps a holly decoration.\r\n%\r\n% * <https:\/\/blogs.mathworks.com\/cleve\/2012\/12\/24\/seasons-greetings\/?s_tid=srchtitle\r\n% Season's Greetings 2012>\r\n% * <https:\/\/blogs.mathworks.com\/cleve\/2014\/12\/25\/seasons-greetings-2014\/?s_tid=srchtitle\r\n% Season's Greetings 2014>\r\n%\r\n% <<greeting_2012.png>>\r\n%\r\n\r\n%% The Formula\r\n% All these figures are obtained by varying the parameters in a\r\n% formula that generates complex numbers $z$ from the partial sums.\r\n%\r\n% $$ z = \\sum_n{\\exp{(\\phi n^p+\\sigma) \\pi i}} $$\r\n%\r\n\r\n%%\r\n% A vector of points in the complex plane is produced by taking $n$ to be\r\n% a vector of consecutive integers and using the MATLAB cumulative\r\n% summation function |cumsum| to compute the partial sums.\r\n% There are 8600 points in the figure above and 100,000 points in the\r\n% figures below.\r\n\r\n%%\r\n% The default value of the parameter $\\phi$ is my old friend the\r\n% |golden ratio|.\r\n%\r\n% $$ \\phi = \\frac{1+\\sqrt{5}}{2} $$\r\n%\r\n% In previous posts I've taken $\\phi$ to be other rational and irrational\r\n% numbers, but today I am sticking to this value.\r\n\r\n%%\r\n% The parameter $\\sigma$ controls the angular orientation.  Taking\r\n% $\\sigma$ near $1\/8$ makes the large Christmas tree vertical.\r\n\r\n%%\r\n% While trying how to understand how this thing works I've varied the power\r\n% $p$ from its usual value of 2 and taken hundreds of thousands of points.\r\n% This produces today's pictures.  Different values of $p$ produce wildly\r\n% different results.\r\n\r\n%%\r\n% For a real variable $x$, the expression $\\exp (x \\pi i)$ is periodic and\r\n% lies on the unit circle in the complex plane.  So we are plotting \r\n% the cumulative sum of values taken from around the unit circle.  At first \r\n% glance, this appears to be a complex valued random number generator.\r\n% But it is a lousy generator because we can see Christmas trees in the\r\n% output.\r\n\r\n%% Traditional p = 2\r\n% <<greetings1.gif>>\r\n%\r\n\r\n%% p = 2\/3\r\n% <<greetings2.gif>>\r\n%\r\n\r\n%% p = 5\/4 \r\n% <<greetings3.gif>>\r\n%\r\n\r\n%% p = 4\r\n% <<greetings4.gif>>\r\n%\r\n\r\n%% Today's code\r\n\r\n   type greetings_gifs\r\n   \r\n%% Postscript\r\n% _Happy New Year._\r\n##### SOURCE END ##### ce9fc6f29e12441182d484eced8f1c03\r\n-->","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img src=\"https:\/\/blogs.mathworks.com\/cleve\/files\/greeting_2012.png\" class=\"img-responsive attachment-post-thumbnail size-post-thumbnail wp-post-image\" alt=\"\" decoding=\"async\" loading=\"lazy\" \/><\/div><!--introduction--><p>I don't recall where I found this seasonal fractal. And I can't explain how it works. So please submit a comment if you can shed any light on either of these questions.... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/cleve\/2016\/12\/25\/seasons-greetings-fractal\/\">read more >><\/a><\/p>","protected":false},"author":78,"featured_media":2211,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[18,5,23,26],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/posts\/2210"}],"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=2210"}],"version-history":[{"count":2,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/posts\/2210\/revisions"}],"predecessor-version":[{"id":2218,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/posts\/2210\/revisions\/2218"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/media\/2211"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/media?parent=2210"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/categories?post=2210"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/tags?post=2210"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}