{"id":6027,"date":"2020-04-15T17:04:22","date_gmt":"2020-04-15T22:04:22","guid":{"rendered":"https:\/\/blogs.mathworks.com\/cleve\/?p=6027"},"modified":"2020-04-15T23:48:10","modified_gmt":"2020-04-16T04:48:10","slug":"champagne-portraits-of-complex-functions","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/cleve\/2020\/04\/15\/champagne-portraits-of-complex-functions\/","title":{"rendered":"Champagne Portraits of Complex Functions"},"content":{"rendered":"<div class=\"content\"><!--introduction--><p>Lots of tiny bubbles.<\/p><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/animated_bubbles.gif\" alt=\"\"> <\/p><!--\/introduction--><h3>Contents<\/h3><div><ul><li><a href=\"#8a2e9074-bbc8-426f-abef-743e221d18f3\">Domain<\/a><\/li><li><a href=\"#3f807248-c0b1-4c5c-9bf1-644415dd0a46\">Colors<\/a><\/li><li><a href=\"#2096fbe3-9fc3-47d7-a404-a58c4567498f\">Powers<\/a><\/li><li><a href=\"#ff7b42f4-f9ca-4ab1-af8a-0f4faa5327b3\">z^2<\/a><\/li><li><a href=\"#96bfecb4-6360-4fed-8323-de1abc7a5703\">z^3<\/a><\/li><li><a href=\"#92599083-0e2a-4fb4-a264-5d8c1afccf94\">z^9<\/a><\/li><li><a href=\"#36becae0-cc8b-460c-a168-c5863137bafe\">1\/z<\/a><\/li><li><a href=\"#54e01433-6987-4c15-8609-a9ce3c341f78\">sqrt(z)<\/a><\/li><li><a href=\"#fb4c8742-0bf7-497a-b037-b670246a6015\">-sqrt(z)<\/a><\/li><li><a href=\"#8ef650dd-8894-4fa4-83fd-8830654bc6d2\">Trig functions<\/a><\/li><li><a href=\"#17b605d5-a362-4b60-8a7d-78fdd8b726d1\">sin(z)<\/a><\/li><li><a href=\"#94ce67ec-f04b-4ffd-a22f-9637361ab429\">cos(z)<\/a><\/li><li><a href=\"#620aeba4-a8e9-4aec-ab19-49aceb4da41c\">tan(z)<\/a><\/li><li><a href=\"#3d11746e-d820-4431-8759-81def46d969a\">cot(z)<\/a><\/li><li><a href=\"#8fb0cbca-77a2-46ca-82f8-55e171e673c7\">Exponentials<\/a><\/li><li><a href=\"#a62bfad4-0036-4b2c-b4a9-60d45d6b7758\">exp(z)<\/a><\/li><li><a href=\"#996294bc-d653-4a33-8bc0-1721cc876132\">exp(pi*z)\/exp(pi)<\/a><\/li><li><a href=\"#2bf591cb-5a76-4303-962f-ce7eab97a3a9\">log(z)<\/a><\/li><li><a href=\"#26ccaafc-911d-49b4-a63a-76efcf6e0819\">Polynomials and rationals<\/a><\/li><li><a href=\"#47cbd348-c13f-46fe-bf62-9e86831d38b9\">z^3 - z<\/a><\/li><li><a href=\"#f90c97a0-bacf-4775-b12b-89def0edbea2\">.5\/(z^5-z\/5)<\/a><\/li><li><a href=\"#26521358-3910-421f-80a5-98c6ef3ae697\">Essential singularity.<\/a><\/li><li><a href=\"#a847be25-ee4e-44c0-b4d7-d72513b6be73\">exp(-1\/(8 z^2)<\/a><\/li><li><a href=\"#c9e586d9-28fe-4674-b308-1f9fbd3f7138\">Quiz<\/a><\/li><li><a href=\"#37292be1-e038-4611-b8de-f3aeb20cb5de\">Code<\/a><\/li><\/ul><\/div><h4>Domain<a name=\"8a2e9074-bbc8-426f-abef-743e221d18f3\"><\/a><\/h4><p>The basic domain is the quadruple unit square,<\/p><p>$$\\max{(|x|,|y|)} \\le 1, \\ z = x+iy $$<\/p><h4>Colors<a name=\"3f807248-c0b1-4c5c-9bf1-644415dd0a46\"><\/a><\/h4><p>I could use the HSV colormap.<\/p><pre class=\"codeinput\">   hsv_bubbles(@(z) z)\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/bubblez_blog_01.png\" alt=\"\"> <p>But I prefer \"periodic parula\", the <tt>parula<\/tt> colormap concatenated with its reverse, <tt>[parula; flipud(parula)]<\/tt>.<\/p><pre class=\"codeinput\">   bubbles(@(z) z)\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/bubblez_blog_02.png\" alt=\"\"> <h4>Powers<a name=\"2096fbe3-9fc3-47d7-a404-a58c4567498f\"><\/a><\/h4><h4>z^2<a name=\"ff7b42f4-f9ca-4ab1-af8a-0f4faa5327b3\"><\/a><\/h4><pre class=\"codeinput\">   bubbles(@(z) z.^2)\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/bubblez_blog_03.png\" alt=\"\"> <h4>z^3<a name=\"96bfecb4-6360-4fed-8323-de1abc7a5703\"><\/a><\/h4><pre class=\"codeinput\">   bubbles(@(z) z.^3)\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/bubblez_blog_04.png\" alt=\"\"> <h4>z^9<a name=\"92599083-0e2a-4fb4-a264-5d8c1afccf94\"><\/a><\/h4><pre class=\"codeinput\">   bubbles(@(z) z.^9)\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/bubblez_blog_05.png\" alt=\"\"> <h4>1\/z<a name=\"36becae0-cc8b-460c-a168-c5863137bafe\"><\/a><\/h4><pre class=\"codeinput\">   bubbles(@(z) 1.\/z)\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/bubblez_blog_06.png\" alt=\"\"> <h4>sqrt(z)<a name=\"54e01433-6987-4c15-8609-a9ce3c341f78\"><\/a><\/h4><p>A complex number has two square roots.  One is in the right half plane.<\/p><pre class=\"codeinput\">   bubbles(@sqrt)\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/bubblez_blog_07.png\" alt=\"\"> <h4>-sqrt(z)<a name=\"fb4c8742-0bf7-497a-b037-b670246a6015\"><\/a><\/h4><p>And the other is in the left half plane.<\/p><pre class=\"codeinput\">   bubbles(@(z) -sqrt(z))\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/bubblez_blog_08.png\" alt=\"\"> <h4>Trig functions<a name=\"8ef650dd-8894-4fa4-83fd-8830654bc6d2\"><\/a><\/h4><h4>sin(z)<a name=\"17b605d5-a362-4b60-8a7d-78fdd8b726d1\"><\/a><\/h4><pre class=\"codeinput\">   bubbles(@sin)\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/bubblez_blog_09.png\" alt=\"\"> <h4>cos(z)<a name=\"94ce67ec-f04b-4ffd-a22f-9637361ab429\"><\/a><\/h4><pre class=\"codeinput\">   bubbles(@cos)\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/bubblez_blog_10.png\" alt=\"\"> <h4>tan(z)<a name=\"620aeba4-a8e9-4aec-ab19-49aceb4da41c\"><\/a><\/h4><pre class=\"codeinput\">   bubbles(@tan)\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/bubblez_blog_11.png\" alt=\"\"> <h4>cot(z)<a name=\"3d11746e-d820-4431-8759-81def46d969a\"><\/a><\/h4><pre class=\"codeinput\">   bubbles(@cot)\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/bubblez_blog_12.png\" alt=\"\"> <h4>Exponentials<a name=\"8fb0cbca-77a2-46ca-82f8-55e171e673c7\"><\/a><\/h4><h4>exp(z)<a name=\"a62bfad4-0036-4b2c-b4a9-60d45d6b7758\"><\/a><\/h4><p>These polar angles are between -1 and +1 radian.<\/p><pre class=\"codeinput\">   bubbles(@exp)\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/bubblez_blog_13.png\" alt=\"\"> <h4>exp(pi*z)\/exp(pi)<a name=\"996294bc-d653-4a33-8bc0-1721cc876132\"><\/a><\/h4><p>These fill out the entire complex plane.<\/p><pre class=\"codeinput\">   bubbles(@(z) exp(pi*z)\/exp(pi))\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/bubblez_blog_14.png\" alt=\"\"> <h4>log(z)<a name=\"2bf591cb-5a76-4303-962f-ce7eab97a3a9\"><\/a><\/h4><pre class=\"codeinput\">   bubbles(@log)\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/bubblez_blog_15.png\" alt=\"\"> <h4>Polynomials and rationals<a name=\"26ccaafc-911d-49b4-a63a-76efcf6e0819\"><\/a><\/h4><h4>z^3 - z<a name=\"47cbd348-c13f-46fe-bf62-9e86831d38b9\"><\/a><\/h4><pre class=\"codeinput\">   bubbles(@(z) z.^3-z)\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/bubblez_blog_16.png\" alt=\"\"> <h4>.5\/(z^5-z\/5)<a name=\"f90c97a0-bacf-4775-b12b-89def0edbea2\"><\/a><\/h4><pre class=\"codeinput\">   bubbles(@(z) .5.\/(z.^5-z\/5))\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/bubblez_blog_17.png\" alt=\"\"> <h4>Essential singularity.<a name=\"26521358-3910-421f-80a5-98c6ef3ae697\"><\/a><\/h4><h4>exp(-1\/(8 z^2)<a name=\"a847be25-ee4e-44c0-b4d7-d72513b6be73\"><\/a><\/h4><pre class=\"codeinput\">   bubbles(@(z) exp(-1.\/(8*z.^2)))\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/bubblez_blog_18.png\" alt=\"\"> <h4>Quiz<a name=\"c9e586d9-28fe-4674-b308-1f9fbd3f7138\"><\/a><\/h4><p>What is happening in the animation at the top of this post? If you think you know, or even if you just know part of the answer, submit a comment.  I'll have some sort of prize for the first, or best, solution.<\/p><h4>Code<a name=\"37292be1-e038-4611-b8de-f3aeb20cb5de\"><\/a><\/h4><p>Also available at <a href=\"https:\/\/blogs.mathworks.com\/cleve\/files\/bubbles.m\">https:\/\/blogs.mathworks.com\/cleve\/files\/bubbles.m<\/a>.<\/p><pre class=\"codeinput\">   type <span class=\"string\">bubbles<\/span>\r\n<\/pre><pre class=\"codeoutput\">\r\nfunction bubbles(F)\r\n    % bubbles. Color portrait of complex-valued function F(z),\r\n    % ex. bubbles(@sin)\r\n    %     bubbles(@(z) .5.\/(z.^5-z\/5) )\r\n    \r\n    if nargin &lt; 1\r\n       F = @(z)z;\r\n    end\r\n    \r\n    axis(1.5*[-1 1 -1 1])\r\n    axis square\r\n    box on\r\n    cla\r\n    \r\n    m = 256;\r\n    colormap = [parula(m);flipud(parula(m))]; \r\n        \r\n    n = 25;\r\n    s = -1:2\/(n-1):1;\r\n    [x,y] = meshgrid(s);\r\n    z = x + y*1i;\r\n    circle = exp((0:32)\/16*pi*1i)\/n;\r\n    \r\n    w = F(z);\r\n    r = abs(w);\r\n    theta = angle(w)+pi;\r\n    \r\n    scale = 20;\r\n    for k = 1:n\r\n        for j = 1:n\r\n            t = m*theta(k,j)\/pi\/scale;\r\n            idx = ceil(scale*t+realmin);\r\n            color = colormap(idx,:);\r\n            p = w(k,j) + r(k,j)*circle;\r\n            patch(real(p),imag(p),color)\r\n        end\r\n    end\r\n \r\n    titleF = char(F);\r\n    if (titleF(1) == '@')\r\n        titleF(1:4) = [];\r\n    end\r\n    title(titleF)\r\n    snapnow\r\nend\r\n<\/pre><script language=\"JavaScript\"> <!-- \r\n    function grabCode_cfcf76f3a3af4aea836de188c96708d6() {\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='cfcf76f3a3af4aea836de188c96708d6 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' cfcf76f3a3af4aea836de188c96708d6';\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 2020 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_cfcf76f3a3af4aea836de188c96708d6()\"><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; R2019b<br><\/p><\/div><!--\r\ncfcf76f3a3af4aea836de188c96708d6 ##### SOURCE BEGIN #####\r\n%% Champagne Portraits of Complex Functions\r\n% Lots of tiny bubbles.\r\n%\r\n% <<animated_bubbles.gif>>\r\n\r\n%% Domain\r\n% The basic domain is the quadruple unit square,\r\n%\r\n% $$\\max{(|x|,|y|)} \\le 1, \\ z = x+iy $$\r\n\r\n%% Colors\r\n% I could use the HSV colormap.\r\n\r\n   hsv_bubbles(@(z) z)\r\n   \r\n%%\r\n% But I prefer \"periodic parula\", the |parula| colormap concatenated\r\n% with its reverse, |[parula; flipud(parula)]|.\r\n\r\n   bubbles(@(z) z)\r\n   \r\n%% Powers\r\n%% z^2\r\n\r\n   bubbles(@(z) z.^2)\r\n\r\n%% z^3\r\n\r\n   bubbles(@(z) z.^3)\r\n   \r\n%% z^9\r\n\r\n   bubbles(@(z) z.^9) \r\n   \r\n%% 1\/z\r\n\r\n   bubbles(@(z) 1.\/z)\r\n\r\n%% sqrt(z)\r\n% A complex number has two square roots.  One is in the right half plane.\r\n\r\n   bubbles(@sqrt)\r\n   \r\n%% -sqrt(z)\r\n% And the other is in the left half plane.\r\n\r\n   bubbles(@(z) -sqrt(z))\r\n   \r\n%% Trig functions\r\n%% sin(z)\r\n\r\n   bubbles(@sin)\r\n   \r\n%% cos(z)\r\n\r\n   bubbles(@cos)\r\n   \r\n %% tan(z)\r\n\r\n   bubbles(@tan)\r\n   \r\n %% cot(z)\r\n\r\n   bubbles(@cot)\r\n   \r\n%% Exponentials\r\n%% exp(z)\r\n% These polar angles are between -1 and +1 radian.\r\n\r\n   bubbles(@exp) \r\n   \r\n%% exp(pi*z)\/exp(pi)\r\n% These fill out the entire complex plane.\r\n\r\n   bubbles(@(z) exp(pi*z)\/exp(pi))\r\n\r\n%% log(z)\r\n\r\n   bubbles(@log)\r\n   \r\n%% Polynomials and rationals\r\n%% z^3 - z\r\n\r\n   bubbles(@(z) z.^3-z)   \r\n\r\n %% .5\/(z^5-z\/5)\r\n \r\n   bubbles(@(z) .5.\/(z.^5-z\/5))\r\n   \r\n%% Essential singularity.\r\n%% exp(-1\/(8 z^2)\r\n \r\n   bubbles(@(z) exp(-1.\/(8*z.^2)))\r\n   \r\n%% Quiz\r\n% What is happening in the animation at the top of this post?\r\n% If you think you know, or even if you just know part of the answer, \r\n% submit a comment.  I'll have some sort of prize for the first, or best,\r\n% solution.\r\n\r\n%% Code\r\n% Also available at\r\n% https:\/\/blogs.mathworks.com\/cleve\/files\/bubbles.m.\r\n\r\n   type bubbles\r\n##### SOURCE END ##### cfcf76f3a3af4aea836de188c96708d6\r\n-->","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img src=\"https:\/\/blogs.mathworks.com\/cleve\/files\/bubblez_blog_16.png\" class=\"img-responsive attachment-post-thumbnail size-post-thumbnail wp-post-image\" alt=\"\" decoding=\"async\" loading=\"lazy\" \/><\/div><!--introduction--><p>Lots of tiny bubbles.... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/cleve\/2020\/04\/15\/champagne-portraits-of-complex-functions\/\">read more >><\/a><\/p>","protected":false},"author":78,"featured_media":6157,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[12,32,5,23,17],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/posts\/6027"}],"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=6027"}],"version-history":[{"count":4,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/posts\/6027\/revisions"}],"predecessor-version":[{"id":6121,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/posts\/6027\/revisions\/6121"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/media\/6157"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/media?parent=6027"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/categories?post=6027"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/tags?post=6027"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}