{"id":5887,"date":"2020-03-13T20:42:26","date_gmt":"2020-03-14T01:42:26","guid":{"rendered":"https:\/\/blogs.mathworks.com\/cleve\/?p=5887"},"modified":"2020-03-16T15:00:18","modified_gmt":"2020-03-16T20:00:18","slug":"it-is-friday-the-13th-again","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/cleve\/2020\/03\/13\/it-is-friday-the-13th-again\/","title":{"rendered":"It is Friday the 13th Again"},"content":{"rendered":"<div class=\"content\"><!--introduction--><p>Today is Friday, March 13, 2020.  In many parts of the world, Friday the 13th is considered unlucky.  I've written blog posts about Friday the 13th before, <a href=\"https:\/\/blogs.mathworks.com\/cleve\/2012\/07\/09\/friday-the-13th\/\">2012<\/a>, <a href=\"https:\/\/blogs.mathworks.com\/cleve\/2018\/04\/13\/friday-the-13th-and-the-datetime-method\/\">2018<\/a>, but I will have something new to say today.<\/p><p><b>NOTE: Somehow the figures were being misplaced.  It seems to be OK now, but I am retaining the anchors in the text, just in case.<\/b><\/p><!--\/introduction--><h3>Contents<\/h3><div><ul><li><a href=\"#a49beec7-3271-4b06-afac-a35358004e8e\">Questions<\/a><\/li><li><a href=\"#54157f59-c793-4fc6-b911-03ead9472774\">Leap Years<\/a><\/li><li><a href=\"#76bf8882-83c0-420f-ab11-e6f0e4fd3829\">Calendars<\/a><\/li><li><a href=\"#eecef1e3-9391-4267-b1f4-e9ff1d1d39af\">Datetime<\/a><\/li><li><a href=\"#5e61e985-9edb-4ccc-92b5-5633184ae8de\">Vectorize<\/a><\/li><li><a href=\"#9270e538-a86f-42da-9081-ca5ffc0de080\">Categorize<\/a><\/li><li><a href=\"#ff847616-2dd2-46ec-8548-02d7f4e96346\">Months<\/a><\/li><li><a href=\"#10598e55-c603-4daf-a621-76f256c5dc80\">Years<\/a><\/li><li><a href=\"#e65f4ad8-ed18-4333-bc19-583953b73c01\">Frequency<\/a><\/li><li><a href=\"#a29ae947-aab0-4201-bf01-f6810ac72b26\">Decade<\/a><\/li><li><a href=\"#638ff258-5c56-498a-bb60-2e118229ae1e\">Quiz<\/a><\/li><\/ul><\/div><h4>Questions<a name=\"a49beec7-3271-4b06-afac-a35358004e8e\"><\/a><\/h4><p>Is Friday the 13 not only <i>unlucky<\/i>, bit is it also <i>unlikely<\/i>? What are the chances that the 13th of any month falls on Friday? Which <i>months<\/i> are more likely to have Friday the 13th? Which <i>years<\/i> are more likely to have Friday the 13th?<\/p><h4>Leap Years<a name=\"54157f59-c793-4fc6-b911-03ead9472774\"><\/a><\/h4><p>Leap years make our calendar a nontrivial mathematical object. The leap year rule can be implemented by this anonymous function.<\/p><pre class=\"codeinput\">    leapyear = @(y) mod(y,4)==0 &amp; mod(y,100)~=0 | mod(y,400)==0;\r\n<\/pre><p>This says that leap years happen every four years, except for the turn of centuries not divisible by 400. Let's try a few year numbers.<\/p><pre class=\"codeinput\">    y = [2020 2021 2000 2100]';\r\n    isleap = [y leapyear(y)]\r\n<\/pre><pre class=\"codeoutput\">isleap =\r\n        2020           1\r\n        2021           0\r\n        2000           1\r\n        2100           0\r\n<\/pre><p>So, this year is a leap year, but next year is not. The turn of the century two years ago in 2000 was a leap year, but the next turn of the century in 2100 will not be one.<\/p><h4>Calendars<a name=\"76bf8882-83c0-420f-ab11-e6f0e4fd3829\"><\/a><\/h4><p>The leap year rule implies that our calendar has a period of 400 years. The calendar for years 2000 to 2399 will be reused for 2400 to 2799. In a 400-year period, there are 97 leap years, 4800 months, 20871 weeks, and 146097 days. So, the average number of days in a calendar year is not 365.25, but<\/p><pre class=\"codeinput\">    dpy = 365+97\/400\r\n<\/pre><pre class=\"codeoutput\">dpy =\r\n  365.2425\r\n<\/pre><p>At first glance, you might say that the probability of the 13th of any month being a Friday is 1\/7, because there are seven days in a week and they are all equally likely.  But that's not quite correct. We can count the number of occurrences of Friday the 13th in the 4800 months in a calendar period. The correct probability is then that count divided by 4800. Since 4800 is not a multiple of 7, the probability does not reduce to 1\/7.<\/p><h4>Datetime<a name=\"eecef1e3-9391-4267-b1f4-e9ff1d1d39af\"><\/a><\/h4><p>The <tt>datetime<\/tt> object, introduced in MATLAB in R2014b, is the tool we need for this job.<\/p><p>The documentation for <tt>datetime<\/tt> is available <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/datetime.html\">here<\/a>, or, from within MATLAB, with the command<\/p><pre>   doc datetime<\/pre><p>For example, here is the date and time when I am writing this post.<\/p><pre class=\"codeinput\">    d = datetime(<span class=\"string\">'now'<\/span>)\r\n<\/pre><pre class=\"codeoutput\">d = \r\n  datetime\r\n   13-Mar-2020 21:17:57\r\n<\/pre><p>I can specify a custom display format that includes the weekday with<\/p><pre class=\"codeinput\">    d = datetime(d,<span class=\"string\">'Format'<\/span>,<span class=\"string\">'eeee, MMMM d, yyyy HH:mm:ss'<\/span>)\r\n<\/pre><pre class=\"codeoutput\">d = \r\n  datetime\r\n   Friday, March 13, 2020 21:17:57\r\n<\/pre><p>The available display formats include support for an international standard, <a href=\"https:\/\/www.iso.org\/iso-8601-date-and-time-format.html\">ISO 8601<\/a>.<\/p><h4>Vectorize<a name=\"5e61e985-9edb-4ccc-92b5-5633184ae8de\"><\/a><\/h4><p>Let's get on with Friday the 13th.  Like most things in MATLAB <tt>datetime<\/tt> works with vectors.  The statements<\/p><pre class=\"codeinput\">    y = 2000;\r\n    m = 1:4800;\r\n    t = 13;\r\n    v = datetime(y,m,t);\r\n<\/pre><p>produce a row vector of 4800 <tt>datetime<\/tt>'s for the 13th of every month. The first few and last few are<\/p><pre class=\"codeinput\">    fprintf(<span class=\"string\">'  %s'<\/span>,v(1:4))\r\n    fprintf(<span class=\"string\">'  ...\\n'<\/span>)\r\n    fprintf(<span class=\"string\">'  %s'<\/span>,v(end-3:end))\r\n<\/pre><pre class=\"codeoutput\">  13-Jan-2000  13-Feb-2000  13-Mar-2000  13-Apr-2000  ...\r\n  13-Sep-2399  13-Oct-2399  13-Nov-2399  13-Dec-2399<\/pre><p>The statement<\/p><pre class=\"codeinput\">    w = weekday(v);\r\n<\/pre><p>produces a row vector of 4800 flints between 1 (for Sunday) and 7 (for Saturday). The first few and last few are<\/p><pre class=\"codeinput\">    fprintf(<span class=\"string\">'%3d'<\/span>,w(1:4))\r\n    fprintf(<span class=\"string\">'  ...'<\/span>)\r\n    fprintf(<span class=\"string\">'%3d'<\/span>,w(end-3:end))\r\n<\/pre><pre class=\"codeoutput\">  5  1  2  5  ...  2  4  7  2<\/pre><p>Now to get the counts of weekdays, all we need is<\/p><pre class=\"codeinput\">    counts = histcounts(w)\r\n<\/pre><pre class=\"codeoutput\">counts =\r\n   687   685   685   687   684   688   684\r\n<\/pre><p>There you have it.  The count for Friday, 688, is higher than for any other day of the week.  The 13th of any month is slightly more likely to fall on a Friday.<\/p><p>The probabilities are<\/p><pre class=\"codeinput\">    prob = counts\/4800\r\n<\/pre><pre class=\"codeoutput\">prob =\r\n    0.1431    0.1427    0.1427    0.1431    0.1425    0.1433    0.1425\r\n<\/pre><p>Compare these values with their mean.<\/p><pre class=\"codeinput\">    avg = mean(prob)\r\n<\/pre><pre class=\"codeoutput\">avg =\r\n    0.1429\r\n<\/pre><p>Four probabilities are below the mean, three are above.<\/p><h4>Categorize<a name=\"9270e538-a86f-42da-9081-ca5ffc0de080\"><\/a><\/h4><p>Let's pair the counts with the days of the week, using a <tt>categorical<\/tt> variable, introduced in R2013b.<\/p><pre class=\"codeinput\">    cat = categorical(w,1:7,weekday_names);\r\n    summary(cat)\r\n<\/pre><pre class=\"codeoutput\">     Sun      Mon      Tue      Wed      Thu      Fri      Sat \r\n     687      685      685      687      684      688      684 \r\n<\/pre><p>When we plot a histogram, the appropriate labels are provided on the x-axis.  Friday the 13th is the winner.<\/p><pre class=\"codeinput\">    histogram(cat,<span class=\"string\">'BarWidth'<\/span>,0.5,<span class=\"string\">'FaceColor'<\/span>,colors(2))\r\n    set(gca,<span class=\"string\">'ylim'<\/span>,[680 690])\r\n    title(<span class=\"string\">'Weekday counts, 400 years'<\/span>)\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/friday_13_again_blog_01.png\" alt=\"\"> <p><b>\"Weekday counts, 400 years\" should be above here.<\/b><\/p><h4>Months<a name=\"ff847616-2dd2-46ec-8548-02d7f4e96346\"><\/a><\/h4><p>Here are several other histograms of distributions of Friday the 13th.  First, over the 400-year period of the calendar, which <i>months<\/i> are more likely to have Friday the 13th? Create a categorial variable by months.<\/p><pre class=\"codeinput\">    friday13s = v(w==6);\r\n    cat_months = categorical(month(friday13s),1:12,month_names);\r\n<\/pre><p>The histogram shows us that this month, March, and five other months, have a number of Friday the 13ths that is slightly above average. August and October have the fewest.<\/p><pre class=\"codeinput\">    histogram(cat_months,<span class=\"string\">'BarWidth'<\/span>,0.5,<span class=\"string\">'FaceColor'<\/span>,colors(3))\r\n    set(gca,<span class=\"string\">'ylim'<\/span>,[55 59],<span class=\"string\">'ytick'<\/span>,56:58)\r\n    title(<span class=\"string\">'Friday 13th, month'<\/span>)\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/friday_13_again_blog_02.png\" alt=\"\"> <p><b>\"Friday 13th, month\" should be above here.<\/b><\/p><h4>Years<a name=\"10598e55-c603-4daf-a621-76f256c5dc80\"><\/a><\/h4><p>Which <i>years<\/i> are more likely to have Friday the 13th? Look at the last digit of the year number.<\/p><pre class=\"codeinput\">    year_mod10 = mod(year(friday13s),10);\r\n    digits = split(string(num2str(0:9)));\r\n    cat_mod10 = categorical(year_mod10,0:9,digits);\r\n<\/pre><p>The histogram reveals that this year, 2020, and any other years that begin a decade, are the least likely to have unlucky Fridays.<\/p><pre class=\"codeinput\">    histogram(cat_mod10,<span class=\"string\">'BarWidth'<\/span>,0.5,<span class=\"string\">'FaceColor'<\/span>,colors(4))\r\n    set(gca,<span class=\"string\">'ylim'<\/span>,[64 73],<span class=\"string\">'ytick'<\/span>,65:72)\r\n    title(<span class=\"string\">'Friday 13th, last digit of year'<\/span>)\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/friday_13_again_blog_03.png\" alt=\"\"> <p><b>\"Friday 13th, last digit of year\" should be above here.<\/b><\/p><h4>Frequency<a name=\"e65f4ad8-ed18-4333-bc19-583953b73c01\"><\/a><\/h4><p>How many unlikely Fridays are there each year?  Here is a rough histogram of the number per year over the entire 400-year period of the calendar.  We can see there appears to be between one and three each year, but to be more specific about the details of the distribution is elusive.<\/p><pre class=\"codeinput\">    years = year(friday13s);\r\n    plot(2000:2399,histc(years,2000:2399),<span class=\"string\">'.'<\/span>)\r\n    set(gca,<span class=\"string\">'xlim'<\/span>,[1990 2409],<span class=\"string\">'ylim'<\/span>,[0 4],<span class=\"string\">'ytick'<\/span>,1:3)\r\n    title(<span class=\"string\">'Friday 13th per year, 400 years'<\/span>)\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/friday_13_again_blog_04.png\" alt=\"\"> <p><b>\"Friday 13th per year, 400 years\" should be above here.<\/b><\/p><h4>Decade<a name=\"a29ae947-aab0-4201-bf01-f6810ac72b26\"><\/a><\/h4><p>Let's concentrate on just this decade, 2020 through 2029. Here is a list of all the 16 Friday the 13ths in this range.<\/p><pre class=\"codeinput\">    decade = (years&gt;=2020 &amp; years&lt;2030);\r\n    disp(friday13s(decade)')\r\n<\/pre><pre class=\"codeoutput\">   13-Mar-2020\r\n   13-Nov-2020\r\n   13-Aug-2021\r\n   13-May-2022\r\n   13-Jan-2023\r\n   13-Oct-2023\r\n   13-Sep-2024\r\n   13-Dec-2024\r\n   13-Jun-2025\r\n   13-Feb-2026\r\n   13-Mar-2026\r\n   13-Nov-2026\r\n   13-Aug-2027\r\n   13-Oct-2028\r\n   13-Apr-2029\r\n   13-Jul-2029\r\n<\/pre><p>And here is the histogram of the counts.  We see two this year (today and again in November). Then there is only one next year, and only one the year after that. But there will be three in 2026.  That's the only three-count this decade.<\/p><pre class=\"codeinput\">    hist(years(decade),2020:0.5:2029,<span class=\"string\">'binwidth'<\/span>,0.5)\r\n    set(get(gca,<span class=\"string\">'child'<\/span>),<span class=\"string\">'FaceColor'<\/span>,colors(5))\r\n    set(gca,<span class=\"string\">'xlim'<\/span>,[2019 2030],<span class=\"string\">'xtick'<\/span>,2020:2029, <span class=\"keyword\">...<\/span>\r\n            <span class=\"string\">'ylim'<\/span>,[0 4],<span class=\"string\">'ytick'<\/span>,1:3)\r\n    title(<span class=\"string\">'Friday 13th per year, 2020-2029'<\/span>)\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/friday_13_again_blog_05.png\" alt=\"\"> <p><b>\"Friday 13th per year, 2020-2029\" should be above here.<\/b><\/p><h4>Quiz<a name=\"638ff258-5c56-498a-bb60-2e118229ae1e\"><\/a><\/h4><p>If you have stayed with me this long, maybe you are ready for some homework.<\/p><div><ul><li>Explain why there has to be at least one Friday the 13th each year.<\/li><li>Explain why there can never be more than three in any year.<\/li><li>How many different ways are there to have three in a year?  2026 is one example.<\/li><\/ul><\/div><p>Now I better quit and get this posted while it is still Friday the 13th.<\/p><p><i>Good luck.<\/i><\/p><script language=\"JavaScript\"> <!-- \r\n    function grabCode_776de2ba67aa422fb2de288b4d7e5ca7() {\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='776de2ba67aa422fb2de288b4d7e5ca7 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 776de2ba67aa422fb2de288b4d7e5ca7';\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_776de2ba67aa422fb2de288b4d7e5ca7()\"><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\n776de2ba67aa422fb2de288b4d7e5ca7 ##### SOURCE BEGIN #####\r\n%% It's Friday the 13th Again\r\n% Today is Friday, March 13, 2020.  In many parts of the world,\r\n% Friday the 13th is considered unlucky.  I've written blog posts\r\n% about Friday the 13th before,\r\n% <https:\/\/blogs.mathworks.com\/cleve\/2012\/07\/09\/friday-the-13th\/ 2012>,\r\n% <https:\/\/blogs.mathworks.com\/cleve\/2018\/04\/13\/friday-the-13th-and-the-datetime-method\/\r\n% 2018>, but I will have something new to say today.\r\n%\r\n% *IMPORTANT NOTE:\r\n% Somehow the figures are being misplaced.  I still want to\r\n% post this today.  I will indicate below the proper location of figures.*\r\n\r\n%% Questions\r\n% Is Friday the 13 not only _unlucky_, bit is it also _unlikely_?\r\n% What are the chances that the 13th of any month falls on Friday?\r\n% Which _months_ are more likely to have Friday the 13th?\r\n% Which _years_ are more likely to have Friday the 13th?\r\n\r\n%% Leap Years\r\n% Leap years make our calendar a nontrivial mathematical object.\r\n% The leap year rule can be implemented by this anonymous function.\r\n\r\n    leapyear = @(y) mod(y,4)==0 & mod(y,100)~=0 | mod(y,400)==0;\r\n\r\n%%\r\n% This says that leap years happen every four years,\r\n% except for the turn of centuries not divisible by 400.\r\n% Let's try a few year numbers.\r\n\r\n    y = [2020 2021 2000 2100]';\r\n    isleap = [y leapyear(y)]\r\n\r\n%% \r\n% So, this year is a leap year, but next year is not.\r\n% The turn of the century two years ago in 2000 was a leap year,\r\n% but the next turn of the century in 2100 will not be one.\r\n\r\n%% Calendars \r\n% The leap year rule implies that our calendar has a period of 400 years.\r\n% The calendar for years 2000 to 2399 will be reused for 2400 to 2799.\r\n% In a 400-year period, there are 97 leap years, 4800 months,\r\n% 20871 weeks, and 146097 days.\r\n% So, the average number of days in a calendar year is not 365.25, but\r\n\r\n    dpy = 365+97\/400 \r\n\r\n%%\r\n% At first glance, you might say that the probability of the 13th of any\r\n% month being a Friday is 1\/7, because there are seven days in a week\r\n% and they are all equally likely.  But that's not quite correct.\r\n% We can count the number of occurrences of Friday the 13th in the 4800\r\n% months in a calendar period.\r\n% The correct probability is then that count divided by 4800.\r\n% Since 4800 is not a multiple of 7, the probability does not reduce\r\n% to 1\/7.\r\n\r\n%% Datetime\r\n% The |datetime| object, introduced in MATLAB in R2014b, is the tool\r\n% we need for this job.\r\n\r\n%%\r\n% The documentation for |datetime| is available\r\n% <https:\/\/www.mathworks.com\/help\/matlab\/ref\/datetime.html here>,\r\n% or, from within MATLAB, with the command\r\n%\r\n%     doc datetime\r\n\r\n%%\r\n% For example, here is the date and time when I am writing this post.\r\n\r\n    d = datetime('now')\r\n   \r\n%%\r\n% I can specify a custom display format that includes the weekday with\r\n\r\n    d = datetime(d,'Format','eeee, MMMM d, yyyy HH:mm:ss')\r\n\r\n%%\r\n% The available display formats include support for an\r\n% international standard, \r\n% <https:\/\/www.iso.org\/iso-8601-date-and-time-format.html ISO 8601>.\r\n\r\n%% Vectorize\r\n% Let's get on with Friday the 13th.  Like most things in MATLAB\r\n% |datetime| works with vectors.  The statements\r\n\r\n    y = 2000;\r\n    m = 1:4800;\r\n    t = 13;\r\n    v = datetime(y,m,t);\r\n    \r\n%%\r\n% produce a row vector of 4800 |datetime|'s for the 13th of every month.\r\n% The first few and last few are\r\n\r\n    fprintf('  %s',v(1:4))\r\n    fprintf('  ...\\n')\r\n    fprintf('  %s',v(end-3:end))  \r\n    \r\n%%\r\n% The statement\r\n\r\n    w = weekday(v);\r\n    \r\n%%\r\n% produces a row vector of 4800 flints between 1 (for Sunday) and 7\r\n% (for Saturday).\r\n% The first few and last few are\r\n   \r\n    fprintf('%3d',w(1:4))\r\n    fprintf('  ...')\r\n    fprintf('%3d',w(end-3:end))  \r\n    \r\n%%\r\n% Now to get the counts of weekdays, all we need is\r\n\r\n    counts = histcounts(w)\r\n    \r\n%%\r\n% There you have it.  The count for Friday, 688, is higher than for\r\n% any other day of the week.  The 13th of any month is slightly more\r\n% likely to fall on a Friday.\r\n\r\n%%\r\n% The probabilities are\r\n\r\n    prob = counts\/4800\r\n    \r\n%%\r\n% Compare these values with their mean.\r\n\r\n    avg = mean(prob)\r\n    \r\n%%\r\n% Four probabilities are below the mean, three are above.\r\n\r\n%% Categorize\r\n% Let's pair the counts with the days of the week,  \r\n% using a |categorical| variable, introduced in R2013b.\r\n\r\n    cat = categorical(w,1:7,weekday_names);\r\n    summary(cat)\r\n    \r\n%%\r\n% When we plot a histogram, the appropriate labels are provided \r\n% on the x-axis.  Friday the 13th is the winner.\r\n\r\n    histogram(cat,'BarWidth',0.5,'FaceColor',colors(2))\r\n    set(gca,'ylim',[680 690])\r\n    title('Weekday counts, 400 years')\r\n%%\r\n% *\"Weekday counts, 400 years\" should be above here.*\r\n\r\n%% Months\r\n% Here are several other histograms of distributions\r\n% of Friday the 13th.  First, over the 400-year period of the calendar,\r\n% which _months_ are more likely to have Friday the 13th?\r\n% Create a categorial variable by months.\r\n\r\n    friday13s = v(w==6);\r\n    cat_months = categorical(month(friday13s),1:12,month_names);\r\n    \r\n%%\r\n% The histogram shows us that this month, March, and five other months,\r\n% have a number of Friday the 13ths that is slightly above average.\r\n% August and October have the fewest.\r\n\r\n    histogram(cat_months,'BarWidth',0.5,'FaceColor',colors(3))\r\n    set(gca,'ylim',[55 59],'ytick',56:58)\r\n    title('Friday 13th, month')\r\n%%\r\n% *\"Friday 13th, month\" should be above here.*\r\n    \r\n%% Years\r\n% Which _years_ are more likely to have Friday the 13th?\r\n% Look at the last digit of the year number.\r\n\r\n    year_mod10 = mod(year(friday13s),10);\r\n    digits = split(string(num2str(0:9)));\r\n    cat_mod10 = categorical(year_mod10,0:9,digits);\r\n    \r\n%%\r\n% The histogram reveals that this year, 2020, and any other years that\r\n% begin a decade, are the least likely to have unlucky Fridays.\r\n\r\n    histogram(cat_mod10,'BarWidth',0.5,'FaceColor',colors(4))\r\n    set(gca,'ylim',[64 73],'ytick',65:72)\r\n    title('Friday 13th, last digit of year')\r\n%%\r\n% *\"Friday 13th, last digit of year\" should be above here.*\r\n    \r\n%% Frequency\r\n% How many unlikely Fridays are there each year?  Here is a rough\r\n% histogram of the number per year over the entire 400-year period\r\n% of the calendar.  We can see there appears to be between one and three\r\n% each year, but to be more specific about the details of the distribution\r\n% is elusive.\r\n\r\n    years = year(friday13s);\r\n    plot(2000:2399,histc(years,2000:2399),'.')\r\n    set(gca,'xlim',[1990 2409],'ylim',[0 4],'ytick',1:3)\r\n    title('Friday 13th per year, 400 years')\r\n%%\r\n% *\"Friday 13th per year, 400 years\" should be above here.*\r\n%% Decade\r\n% Let's concentrate on just this decade, 2020 through 2029.\r\n% Here is a list of all the 16 Friday the 13ths in this range.\r\n\r\n    decade = (years>=2020 & years<2030);\r\n    disp(friday13s(decade)')\r\n    \r\n%%\r\n% And here is the histogram of the counts.  We see two this year\r\n% (today and again in November).\r\n% Then there is only one next year, and only one the year after that.\r\n% But there will be three in 2026.  That's the only three-count this\r\n% decade.\r\n\r\n    hist(years(decade),2020:0.5:2029,'binwidth',0.5)  \r\n    set(get(gca,'child'),'FaceColor',colors(5))\r\n    set(gca,'xlim',[2019 2030],'xtick',2020:2029, ...\r\n            'ylim',[0 4],'ytick',1:3)\r\n    title('Friday 13th per year, 2020-2029')\r\n%%\r\n% *\"Friday 13th per year, 2020-2029\" should be above here.*\r\n\r\n%% Quiz\r\n% If you have stayed with me this long, maybe you are ready for\r\n% some homework.\r\n% \r\n% * Explain why there has to be at least one Friday the 13th each year.\r\n% * Explain why there can never be more than three in any year.\r\n% * How many different ways are there to have three in a year?  2026 is\r\n% one example.\r\n\r\n%%\r\n% Now I better quit and get this posted while it is still Friday the 13th.\r\n\r\n%%\r\n% _Good luck._\r\n##### SOURCE END ##### 776de2ba67aa422fb2de288b4d7e5ca7\r\n-->","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/friday_13_again_blog_01.png\" onError=\"this.style.display ='none';\" \/><\/div><!--introduction--><p>Today is Friday, March 13, 2020.  In many parts of the world, Friday the 13th is considered unlucky.  I've written blog posts about Friday the 13th before, <a href=\"https:\/\/blogs.mathworks.com\/cleve\/2012\/07\/09\/friday-the-13th\/\">2012<\/a>, <a href=\"https:\/\/blogs.mathworks.com\/cleve\/2018\/04\/13\/friday-the-13th-and-the-datetime-method\/\">2018<\/a>, but I will have something new to say today.... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/cleve\/2020\/03\/13\/it-is-friday-the-13th-again\/\">read more >><\/a><\/p>","protected":false},"author":78,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[5,4,37],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/posts\/5887"}],"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=5887"}],"version-history":[{"count":2,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/posts\/5887\/revisions"}],"predecessor-version":[{"id":5901,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/posts\/5887\/revisions\/5901"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/media?parent=5887"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/categories?post=5887"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/tags?post=5887"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}