{"id":5366,"date":"2019-10-14T15:08:22","date_gmt":"2019-10-14T20:08:22","guid":{"rendered":"https:\/\/blogs.mathworks.com\/cleve\/?p=5366"},"modified":"2019-10-14T15:08:22","modified_gmt":"2019-10-14T20:08:22","slug":"prime-spiral-2","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/cleve\/2019\/10\/14\/prime-spiral-2\/","title":{"rendered":"Prime Spiral #2"},"content":{"rendered":"<div class=\"content\"><!--introduction--><p>Today's post was inspired by a YouTube video, <a href=\"https:\/\/www.youtube.com\/watch?v=EK32jo7i5LQ&amp;t=931s\">Why do prime numbers make these spirals?<\/a>, on the channel <a href=\"https:\/\/www.youtube.com\/channel\/UCYO_jab_esuFRV4b17AJtAw\"><i>3Blue1Brown<\/i><\/a>, created by Grant Sanderson. In my opinion this is the best math channel on YouTube. He has beautiful graphics and superb exposition. I recommend you take a look, if you haven't already.<\/p><p>My 2015 post <a href=\"https:\/\/blogs.mathworks.com\/cleve\/2015\/01\/05\/prime-spiral\/\">Prime Spiral<\/a> was about a completely different prime spiral discovered by Stan Ulam.<\/p><!--\/introduction--><h3>Contents<\/h3><div><ul><li><a href=\"#89697ecd-fa87-4355-bde2-5841ea4d5e4a\">Spiral Polar Plots<\/a><\/li><li><a href=\"#f4693912-806d-42fc-ad00-00a26c3b9999\">r &lt;= 100<\/a><\/li><li><a href=\"#7777458c-4d06-4ceb-94de-999efe151209\">r &lt;= 300<\/a><\/li><li><a href=\"#d600a627-56ee-4838-9552-38e7383c99a0\">r &lt;= 600<\/a><\/li><li><a href=\"#2d6d2083-26ee-4236-b834-5ae2bb8a2323\">r &lt;= 2000<\/a><\/li><li><a href=\"#05b07480-363e-4765-a096-8492ce0555d8\">r &lt;= 20000<\/a><\/li><li><a href=\"#15e219b5-228b-4b50-b9ff-53afdea23918\">r &lt;= 100000<\/a><\/li><li><a href=\"#36c10105-859d-4c46-a7d1-5b24ece185a0\">prime_spiral_2.m<\/a><\/li><\/ul><\/div><h4>Spiral Polar Plots<a name=\"89697ecd-fa87-4355-bde2-5841ea4d5e4a\"><\/a><\/h4><p>The following figure shows the plotting scheme.  We are using polar coordinates, $r, \\theta$, with $\\theta$ measured in radians.<\/p><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/ps2_pix1.png\" alt=\"\"> <\/p><p>Each integer $n$ is plotted at the point where both $r$ and $\\theta$ are equal to $n$.  So, for example, \"6\" is placed 6 units from the origin, at an angle of 6 radians from the positive x-axis. Since 6 is a little less than $2\\pi$, this puts 6 in the fourth quadrant, a little bit under the x-axis.  Moreover 12 is near 6 and 18 near 12. The multiples of 6 lie on an arc that is turning clockwise, orthogonal to the counterclockwise spiral of the underlying numbering scheme. There are six arcs altogether because 6 is almost $2\\pi$.<\/p><p>The primes are shown in blue.  They occupy only two of the six arms because the numbers on the other four arms are all divisible by 2 or 3.<\/p><h4>r &lt;= 100<a name=\"f4693912-806d-42fc-ad00-00a26c3b9999\"><\/a><\/h4><p>Here is a plot of the integers up to 100.  The six clockwise spirals are clearly visible.  The two arms with the blue primes stand out, but the only property of prime numbers that is relevant is that they are not divisible by 2 and 3, the factors of 6.<\/p><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/ps2_pix2.png\" alt=\"\"> <\/p><h4>r &lt;= 300<a name=\"7777458c-4d06-4ceb-94de-999efe151209\"><\/a><\/h4><p>Here is a plot of the integers up to 300.  It's a bit jumbled.  The six arms are less visible, but do you see anything taking their place?<\/p><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/ps2_pix3.png\" alt=\"\"> <\/p><h4>r &lt;= 600<a name=\"d600a627-56ee-4838-9552-38e7383c99a0\"><\/a><\/h4><p>The numbers up to 600.  Now a new family of spirals is visible. There are 44 of them.  That's because 44 is close to a multiple of $2\\pi$. This fact is better known as 22\/7 is a fair approximation to $\\pi$.  The spirals are turning counterclockwise because 44 is greater than $7\\pi$ whereas the earlier spirals are turning clockwise because 6 is less than $2\\pi$.<\/p><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/ps2_pix4.png\" alt=\"\"> <\/p><h4>r &lt;= 2000<a name=\"2d6d2083-26ee-4236-b834-5ae2bb8a2323\"><\/a><\/h4><p>The integers up to 2000.  The 44 arcs are dominant.  Homework: which arms contain the primes?<\/p><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/ps2_pix5.png\" alt=\"\"> <\/p><h4>r &lt;= 20000<a name=\"05b07480-363e-4765-a096-8492ce0555d8\"><\/a><\/h4><p>It was getting crowded, so now it's just the blue points, the primes, up to 20,000.  What is that big, white swath?<\/p><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/ps2_pix6.png\" alt=\"\"> <\/p><h4>r &lt;= 100000<a name=\"15e219b5-228b-4b50-b9ff-53afdea23918\"><\/a><\/h4><p>The primes less than 100,000.  New structures emerge.  These radial arms appear because 355\/115 is a remarkably good approximation to $\\pi$. We are finally seeing evidence of a deep fact about the primes, Dirichlet's theorem on the distribution of primes among residue classes. See Grant Sanderson's <a href=\"https:\/\/www.youtube.com\/channel\/UCYO_jab_esuFRV4b17AJtAw\">video<\/a> for the details.<\/p><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/ps2_pix7.png\" alt=\"\"> <\/p><h4>prime_spiral_2.m<a name=\"36c10105-859d-4c46-a7d1-5b24ece185a0\"><\/a><\/h4><p>Here an animated gif showing my app <tt>prime_spiral_2<\/tt> in action. It automatically zooms in and out continuously, or you can drive it yourself with a scroll bar.  This app is included in <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/59085-cleve_s-laborator\">release 4.7<\/a> of Cleve's Laboratory.  Send me email if you would like a standalone copy.<\/p><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/prime_spiral_2.gif\" alt=\"\"> <\/p><script language=\"JavaScript\"> <!-- \r\n    function grabCode_e45bdc73a9e0433d8edb72743d1f6cd6() {\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='e45bdc73a9e0433d8edb72743d1f6cd6 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' e45bdc73a9e0433d8edb72743d1f6cd6';\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_e45bdc73a9e0433d8edb72743d1f6cd6()\"><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\ne45bdc73a9e0433d8edb72743d1f6cd6 ##### SOURCE BEGIN #####\r\n%% Prime Spiral #2\r\n% Today's post was inspired by a YouTube video,\r\n% <https:\/\/www.youtube.com\/watch?v=EK32jo7i5LQ&t=931s\r\n% Why do prime numbers make these spirals?>, on the channel\r\n% <https:\/\/www.youtube.com\/channel\/UCYO_jab_esuFRV4b17AJtAw\r\n% _3Blue1Brown_>, created by Grant Sanderson.\r\n% In my opinion this is the best math channel on YouTube.\r\n% He has beautiful graphics and superb exposition.\r\n% I recommend you take a look, if you haven't already.\r\n%\r\n% My 2015 post\r\n% <https:\/\/blogs.mathworks.com\/cleve\/2015\/01\/05\/prime-spiral\/\r\n% Prime Spiral> was about a completely different prime spiral\r\n% discovered by Stan Ulam.\r\n\r\n%% Spiral Polar Plots\r\n% The following figure shows the plotting scheme.  We are using polar\r\n% coordinates, $r, \\theta$, with $\\theta$ measured in radians.\r\n% \r\n% <<ps2_pix1.png>>\r\n%\r\n% Each integer $n$ is plotted at the point where both $r$ and $\\theta$\r\n% are equal to $n$.  So, for example, \"6\" is placed 6 units from the\r\n% origin, at an angle of 6 radians from the positive x-axis.\r\n% Since 6 is a little less than $2\\pi$, this puts 6 in the fourth\r\n% quadrant, a little bit under the x-axis.  Moreover 12 is near 6 and\r\n% 18 near 12. The multiples of 6 lie on an arc that is turning clockwise,\r\n% orthogonal to the counterclockwise spiral of the underlying numbering\r\n% scheme. There are six arcs altogether because 6 is almost $2\\pi$.\r\n%\r\n% The primes are shown in blue.  They occupy only two of the six arms\r\n% because the numbers on the other four arms are all divisible by 2 or 3.\r\n\r\n%% r <= 100\r\n% Here is a plot of the integers up to 100.  The six clockwise spirals\r\n% are clearly visible.  The two arms with the blue primes stand out,\r\n% but the only property of prime numbers that is relevant is that they\r\n% are not divisible by 2 and 3, the factors of 6.\r\n%\r\n% <<ps2_pix2.png>>\r\n\r\n%% r <= 300\r\n% Here is a plot of the integers up to 300.  It's a bit jumbled.  The\r\n% six arms are less visible, but do you see anything taking their place?\r\n%\r\n% <<ps2_pix3.png>>\r\n%\r\n\r\n%% r <= 600\r\n% The numbers up to 600.  Now a new family of spirals is visible.\r\n% There are 44 of them.  That's because 44 is close to a multiple of\r\n% $2\\pi$. This fact is better known as 22\/7 is a fair approximation\r\n% to $\\pi$.  The spirals are turning counterclockwise because 44 is\r\n% greater than $7\\pi$ whereas the earlier spirals are turning clockwise\r\n% because 6 is less than $2\\pi$.\r\n%\r\n% <<ps2_pix4.png>>\r\n%\r\n\r\n%% r <= 2000\r\n% The integers up to 2000.  The 44 arcs are dominant.  Homework: which\r\n% arms contain the primes?\r\n%\r\n% <<ps2_pix5.png>>\r\n%\r\n \r\n%% r <= 20000\r\n% It was getting crowded, so now it's just the blue points, the primes,\r\n% up to 20,000.  What is that big, white swath?\r\n%\r\n% <<ps2_pix6.png>>\r\n%\r\n\r\n%% r <= 100000\r\n% The primes less than 100,000.  New structures emerge.  These radial\r\n% arms appear because 355\/115 is a remarkably good approximation to $\\pi$.\r\n% We are finally seeing evidence of a deep fact about the primes,\r\n% Dirichlet's theorem on the distribution of primes among residue classes.\r\n% See Grant Sanderson's\r\n% <https:\/\/www.youtube.com\/channel\/UCYO_jab_esuFRV4b17AJtAw\r\n% video> for the details.\r\n%\r\n% <<ps2_pix7.png>>\r\n%\r\n\r\n%% prime_spiral_2.m\r\n% Here an animated gif showing my app |prime_spiral_2| in action.\r\n% It automatically zooms in and out continuously, or you can drive it\r\n% yourself with a scroll bar.  This app is included in\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/59085-cleve_s-laborator\r\n% release 4.7> of Cleve's Laboratory.  Send me email if you would like\r\n% a standalone copy.\r\n% \r\n% <<prime_spiral_2.gif>>\r\n##### SOURCE END ##### e45bdc73a9e0433d8edb72743d1f6cd6\r\n-->","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img src=\"https:\/\/blogs.mathworks.com\/cleve\/files\/ps2_pix6.png\" class=\"img-responsive attachment-post-thumbnail size-post-thumbnail wp-post-image\" alt=\"\" decoding=\"async\" loading=\"lazy\" \/><\/div><!--introduction--><p>Today's post was inspired by a YouTube video, <a href=\"https:\/\/www.youtube.com\/watch?v=EK32jo7i5LQ&amp;t=931s\">Why do prime numbers make these spirals?<\/a>, on the channel <a href=\"https:\/\/www.youtube.com\/channel\/UCYO_jab_esuFRV4b17AJtAw\"><i>3Blue1Brown<\/i><\/a>, created by Grant Sanderson. In my opinion this is the best math channel on YouTube. He has beautiful graphics and superb exposition. I recommend you take a look, if you haven't already.... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/cleve\/2019\/10\/14\/prime-spiral-2\/\">read more >><\/a><\/p>","protected":false},"author":78,"featured_media":5402,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[5,23,36],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/posts\/5366"}],"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=5366"}],"version-history":[{"count":2,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/posts\/5366\/revisions"}],"predecessor-version":[{"id":5408,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/posts\/5366\/revisions\/5408"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/media\/5402"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/media?parent=5366"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/categories?post=5366"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/tags?post=5366"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}