{"id":3010,"date":"2018-02-19T12:00:43","date_gmt":"2018-02-19T17:00:43","guid":{"rendered":"https:\/\/blogs.mathworks.com\/cleve\/?p=3010"},"modified":"2018-02-20T08:54:38","modified_gmt":"2018-02-20T13:54:38","slug":"fun-with-the-pascal-triangle","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/cleve\/2018\/02\/19\/fun-with-the-pascal-triangle\/","title":{"rendered":"Fun With The Pascal Triangle"},"content":{"rendered":"<div class=\"content\">\r\n\r\n<!--introduction-->\r\n\r\nThe Wikipedia article on <a href=\"https:\/\/en.wikipedia.org\/wiki\/Pascal%27s_triangle\">Pascal's Triangle<\/a> has hundreds of properties of the triangle and there are dozens of other Web pages devoted to it. Here are a few facts that I find most interesting.\r\n\r\n<!--\/introduction-->\r\n<h3>Contents<\/h3>\r\n<div>\r\n<ul>\r\n \t<li><a href=\"#15bf8054-a491-4a9c-bb11-db1330f81d7e\">Blaise Pascal<\/a><\/li>\r\n \t<li><a href=\"#09e46a90-017c-4ffd-aec6-e7c49381edad\">Binomial Coefficients<\/a><\/li>\r\n \t<li><a href=\"#06c99097-6cfc-44e4-9a1e-702729c6058e\">Pascal Matrices<\/a><\/li>\r\n \t<li><a href=\"#2f45ba2b-77b7-47cb-ac5d-435671e4ba78\">Pascal Triangle<\/a><\/li>\r\n \t<li><a href=\"#fd16bb5d-9721-444c-ad22-36bf2a73c1d0\">Square Root of Identity<\/a><\/li>\r\n \t<li><a href=\"#a1cc4871-aa8f-4159-8e48-c434ab63de89\">Cube Root of Identity<\/a><\/li>\r\n \t<li><a href=\"#9f710b7c-53fe-4ecd-95d5-573744da7c6e\">Sierpinski<\/a><\/li>\r\n \t<li><a href=\"#6bdb8de5-5817-4e59-8667-298d2509bc5d\">Fibonacci<\/a><\/li>\r\n \t<li><a href=\"#71357bca-07c4-4ab4-8863-e511eaee0bbf\">pi<\/a><\/li>\r\n \t<li><a href=\"#670ca725-8b34-4afb-8827-e86746c3d03f\">Matrix Exponential<\/a><\/li>\r\n \t<li><a href=\"#21341042-d439-46df-8dc9-54a24b80c5e9\">Thanks<\/a><\/li>\r\n<\/ul>\r\n<\/div>\r\n<h4>Blaise Pascal<a name=\"15bf8054-a491-4a9c-bb11-db1330f81d7e\"><\/a><\/h4>\r\n<img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/cleve\/files\/blaise-pascal.jpg\" alt=\"\" hspace=\"5\" vspace=\"5\" \/>\r\n\r\n<a href=\"https:\/\/en.wikipedia.org\/wiki\/Blaise_Pascal\">Blaise Pascal<\/a> (1623-1662) was a 17th century French mathematician, physicist, inventor and theologian. His <i>Trait\u00e9 du triangle arithm\u00e9tique<\/i> (<i>Treatise on Arithmetical Triangle<\/i>) was published posthumously in 1665. But this was not the first publication about the triangle. Various versions appear in Indian, Chinese, Persian, Italian and other manuscripts centuries before Pascal.\r\n<h4>Binomial Coefficients<a name=\"09e46a90-017c-4ffd-aec6-e7c49381edad\"><\/a><\/h4>\r\nThe <i>binomial coefficient<\/i> usually denoted by ${n} \\choose {k}$ is the number of ways of picking $k$ unordered outcomes from $n$ possibilities. These coefficients appear in the expansion of the binomial $(x+1)^n$. For example, when $n = 7$\r\n<pre class=\"codeinput\">  syms <span class=\"string\">x<\/span>\r\n  n = 7;\r\n  x7 = expand((x+1)^n)\r\n<\/pre>\r\n<pre class=\"codeoutput\">x7 =\r\nx^7 + 7*x^6 + 21*x^5 + 35*x^4 + 35*x^3 + 21*x^2 + 7*x + 1\r\n<\/pre>\r\nFormally, the binomial coefficients are given by\r\n\r\n$${{n} \\choose {k}} = \\frac {n!} {k! (n-k)!}$$\r\n\r\nBut premature floating point overflow of the factorials makes this an unsatisfactory basis for computation. A better way employs the recursion\r\n\r\n$$ {{n} \\choose {k}} = {{n-1} \\choose {k}} + {{n-1} \\choose {k-1}}$$\r\n\r\nThis is used by the MATLAB function <tt>nchoosek(n,k)<\/tt>.\r\n<h4>Pascal Matrices<a name=\"06c99097-6cfc-44e4-9a1e-702729c6058e\"><\/a><\/h4>\r\nMATLAB offers two Pascal matrices. One is symmetric, positive definite and has the binomial coefficients on the antidiagonals.\r\n<pre class=\"codeinput\">   P = pascal(7)\r\n<\/pre>\r\n<pre class=\"codeoutput\">P =\r\n     1     1     1     1     1     1     1\r\n     1     2     3     4     5     6     7\r\n     1     3     6    10    15    21    28\r\n     1     4    10    20    35    56    84\r\n     1     5    15    35    70   126   210\r\n     1     6    21    56   126   252   462\r\n     1     7    28    84   210   462   924\r\n<\/pre>\r\nThe other is lower triangular, with the binomial coefficients in the rows. (We will see why the even numbered columns have minus signs in a moment.)\r\n<pre class=\"codeinput\">   L = pascal(7,1)\r\n<\/pre>\r\n<pre class=\"codeoutput\">L =\r\n     1     0     0     0     0     0     0\r\n     1    -1     0     0     0     0     0\r\n     1    -2     1     0     0     0     0\r\n     1    -3     3    -1     0     0     0\r\n     1    -4     6    -4     1     0     0\r\n     1    -5    10   -10     5    -1     0\r\n     1    -6    15   -20    15    -6     1\r\n<\/pre>\r\nThe individual elements are\r\n<pre class=\"language-matlab\">P(i,j) = P(j,i) = nchoosek(i+j-2,j-1)\r\n<\/pre>\r\nAnd (temporarily ignoring the minus signs) for <tt>i<\/tt> $\\ge$ <tt>j<\/tt>\r\n<pre class=\"language-matlab\">L(i,j) = nchoosek(i-1,j-1)\r\n<\/pre>\r\nThe first fun fact is that <tt>L<\/tt> is the (lower) Cholesky factor of <tt>P<\/tt>.\r\n<pre class=\"codeinput\">   L = chol(P)'\r\n<\/pre>\r\n<pre class=\"codeoutput\">L =\r\n     1     0     0     0     0     0     0\r\n     1     1     0     0     0     0     0\r\n     1     2     1     0     0     0     0\r\n     1     3     3     1     0     0     0\r\n     1     4     6     4     1     0     0\r\n     1     5    10    10     5     1     0\r\n     1     6    15    20    15     6     1\r\n<\/pre>\r\nSo we can reconstruct <tt>P<\/tt> from <tt>L<\/tt>.\r\n<pre class=\"codeinput\">   P = L*L'\r\n<\/pre>\r\n<pre class=\"codeoutput\">P =\r\n     1     1     1     1     1     1     1\r\n     1     2     3     4     5     6     7\r\n     1     3     6    10    15    21    28\r\n     1     4    10    20    35    56    84\r\n     1     5    15    35    70   126   210\r\n     1     6    21    56   126   252   462\r\n     1     7    28    84   210   462   924\r\n<\/pre>\r\n<h4>Pascal Triangle<a name=\"2f45ba2b-77b7-47cb-ac5d-435671e4ba78\"><\/a><\/h4>\r\nThe traditional Pascal triangle is obtained by rotating P clockwise 45 degrees, or by sliding the rows of L to the right in half increments. Each element of the resulting triangle is the sum of the two above it.\r\n<pre class=\"codeinput\">   triprint(L)\r\n<\/pre>\r\n<pre class=\"codeoutput\">                         1\r\n                       1   1\r\n                     1   2   1\r\n                   1   3   3   1\r\n                 1   4   6   4   1\r\n               1   5  10  10   5   1\r\n             1   6  15  20  15   6   1\r\n<\/pre>\r\n<h4>Square Root of Identity<a name=\"fd16bb5d-9721-444c-ad22-36bf2a73c1d0\"><\/a><\/h4>\r\nWhen the even numbered columns of <tt>L<\/tt> are given minus signs the matrix becomes a square root of the identity.\r\n<pre class=\"codeinput\">   L = pascal(n,1)\r\n   L_squared = L^2\r\n<\/pre>\r\n<pre class=\"codeoutput\">L =\r\n     1     0     0     0     0     0     0\r\n     1    -1     0     0     0     0     0\r\n     1    -2     1     0     0     0     0\r\n     1    -3     3    -1     0     0     0\r\n     1    -4     6    -4     1     0     0\r\n     1    -5    10   -10     5    -1     0\r\n     1    -6    15   -20    15    -6     1\r\nL_squared =\r\n     1     0     0     0     0     0     0\r\n     0     1     0     0     0     0     0\r\n     0     0     1     0     0     0     0\r\n     0     0     0     1     0     0     0\r\n     0     0     0     0     1     0     0\r\n     0     0     0     0     0     1     0\r\n     0     0     0     0     0     0     1\r\n<\/pre>\r\nHere is an exercise for you. What is <tt>sqrt(eye(n))<\/tt>? Why isn't it <tt>L<\/tt>?\r\n<h4>Cube Root of Identity<a name=\"a1cc4871-aa8f-4159-8e48-c434ab63de89\"><\/a><\/h4>\r\nWhen I first saw this, I was amazed. Rotate L counterclockwise. The result is a cube root of the identity.\r\n<pre class=\"codeinput\">   X = rot90(L,-1)\r\n   X_cubed = X^3\r\n<\/pre>\r\n<pre class=\"codeoutput\">X =\r\n     1     1     1     1     1     1     1\r\n    -6    -5    -4    -3    -2    -1     0\r\n    15    10     6     3     1     0     0\r\n   -20   -10    -4    -1     0     0     0\r\n    15     5     1     0     0     0     0\r\n    -6    -1     0     0     0     0     0\r\n     1     0     0     0     0     0     0\r\nX_cubed =\r\n     1     0     0     0     0     0     0\r\n     0     1     0     0     0     0     0\r\n     0     0     1     0     0     0     0\r\n     0     0     0     1     0     0     0\r\n     0     0     0     0     1     0     0\r\n     0     0     0     0     0     1     0\r\n     0     0     0     0     0     0     1\r\n<\/pre>\r\n<h4>Sierpinski<a name=\"9f710b7c-53fe-4ecd-95d5-573744da7c6e\"><\/a><\/h4>\r\nWhich binomial coefficients are odd? It's a fledgling fractal.\r\n<pre class=\"codeinput\">   odd = @(x) mod(x,2)==1;\r\n   n = 56;\r\n   L = abs(pascal(n,1));\r\n   spy(odd(L))\r\n   title(<span class=\"string\">'odd(L)'<\/span>)\r\n<\/pre>\r\n<img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/cleve\/files\/pascal_blog_01.png\" alt=\"\" hspace=\"5\" vspace=\"5\" \/>\r\n<h4>Fibonacci<a name=\"6bdb8de5-5817-4e59-8667-298d2509bc5d\"><\/a><\/h4>\r\nThe sums of the antidiagonals of <tt>L<\/tt> are the Fibonacci numbers.\r\n<pre class=\"codeinput\">   n = 12;\r\n   A = fliplr(abs(pascal(n,1)))\r\n   <span class=\"keyword\">for<\/span> k = 1:n\r\n       F(k) = sum(diag(A,n-k));\r\n   <span class=\"keyword\">end<\/span>\r\n   F\r\n<\/pre>\r\n<pre class=\"codeoutput\">A =\r\n     0     0     0     0     0     0     0     0     0     0     0     1\r\n     0     0     0     0     0     0     0     0     0     0     1     1\r\n     0     0     0     0     0     0     0     0     0     1     2     1\r\n     0     0     0     0     0     0     0     0     1     3     3     1\r\n     0     0     0     0     0     0     0     1     4     6     4     1\r\n     0     0     0     0     0     0     1     5    10    10     5     1\r\n     0     0     0     0     0     1     6    15    20    15     6     1\r\n     0     0     0     0     1     7    21    35    35    21     7     1\r\n     0     0     0     1     8    28    56    70    56    28     8     1\r\n     0     0     1     9    36    84   126   126    84    36     9     1\r\n     0     1    10    45   120   210   252   210   120    45    10     1\r\n     1    11    55   165   330   462   462   330   165    55    11     1\r\nF =\r\n     1     1     2     3     5     8    13    21    34    55    89   144\r\n<\/pre>\r\n<h4>pi<a name=\"71357bca-07c4-4ab4-8863-e511eaee0bbf\"><\/a><\/h4>\r\nThe elements in the third column of lower triangular Pascal matrix are the <i>triangle numbers<\/i>. The n-th triangle number is the number of bowling pins in the n-th row of an array of bowling pins.\r\n\r\n$$t_n = {{n+1} \\choose {2}}$$\r\n<pre class=\"codeinput\">   L = pascal(12,1);\r\n   t = L(3:end,3)'\r\n<\/pre>\r\n<pre class=\"codeoutput\">t =\r\n     1     3     6    10    15    21    28    36    45    55\r\n<\/pre>\r\nHere's an unusual series relating the triangle numbers to $\\pi$. The signs go + + - - + + - - .\r\n<pre>pi - 2 = 1 + 1\/3 - 1\/6 - 1\/10 + 1\/15 + 1\/21 - 1\/28 - 1\/36 + 1\/45 + 1\/55 - ...<\/pre>\r\n<pre class=\"codeinput\">    type <span class=\"string\">pi_pascal<\/span>\r\n<\/pre>\r\n<pre class=\"codeoutput\">function pie = pi_pascal(n)\r\ntk = 1;\r\ns = 1;\r\nfor k = 2:n\r\n    tk = tk + k;\r\n    if mod(k+1,4) &gt; 1\r\n        s = s + 1\/tk;\r\n    else\r\n        s = s - 1\/tk;\r\n    end\r\nend\r\npie = 2 + s;\r\n<\/pre>\r\nTen million terms gives $\\pi$ to 14 decimal places.\r\n<pre class=\"codeinput\">    format <span class=\"string\">long<\/span>\r\n    pie = pi_pascal(10000000)\r\n    err = pi - pie\r\n<\/pre>\r\n<pre class=\"codeoutput\">pie =\r\n   3.141592653589817\r\nerr =\r\n    -2.398081733190338e-14\r\n<\/pre>\r\n<h4>Matrix Exponential<a name=\"670ca725-8b34-4afb-8827-e86746c3d03f\"><\/a><\/h4>\r\nFinally, I love this one. The solution to the (potentially infinite) set of ordinary differential equations\r\n\r\n$\\dot{x_1} = x_1$\r\n\r\n$\\dot{x_j} = x_j + (j-1) x_{j-1}$\r\n\r\nis\r\n\r\n$x_j = e^t (t + 1)^{j-1}$\r\n\r\nThis means that the matrix exponential of the simple diagonal matrix\r\n<pre class=\"codeinput\">  D = diag(1:7,-1)\r\n<\/pre>\r\n<pre class=\"codeoutput\">D =\r\n     0     0     0     0     0     0     0     0\r\n     1     0     0     0     0     0     0     0\r\n     0     2     0     0     0     0     0     0\r\n     0     0     3     0     0     0     0     0\r\n     0     0     0     4     0     0     0     0\r\n     0     0     0     0     5     0     0     0\r\n     0     0     0     0     0     6     0     0\r\n     0     0     0     0     0     0     7     0\r\n<\/pre>\r\nis\r\n<pre class=\"codeinput\">  expm_D = round(expm(D))\r\n<\/pre>\r\n<pre class=\"codeoutput\">expm_D =\r\n     1     0     0     0     0     0     0     0\r\n     1     1     0     0     0     0     0     0\r\n     1     2     1     0     0     0     0     0\r\n     1     3     3     1     0     0     0     0\r\n     1     4     6     4     1     0     0     0\r\n     1     5    10    10     5     1     0     0\r\n     1     6    15    20    15     6     1     0\r\n     1     7    21    35    35    21     7     1\r\n<\/pre>\r\n<h4>Thanks<a name=\"21341042-d439-46df-8dc9-54a24b80c5e9\"><\/a><\/h4>\r\nThanks to Nick Higham for <tt>pascal.m<\/tt>, <tt>gallery.m<\/tt> and section 28.4 of\r\n\r\nN. J. Higham, <i>Accuracy and Stability of Numerical Algorithms<\/i>, Second edition, SIAM, 2002.\r\n\r\n<a href=\"http:\/\/epubs.siam.org\/doi\/book\/10.1137\/1.9780898718027\">http:\/\/epubs.siam.org\/doi\/book\/10.1137\/1.9780898718027<\/a>\r\n\r\n<script language=\"JavaScript\"> <!-- \r\n    function grabCode_1edd50d2d04740ebb72fefb92312caa5() {\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='1edd50d2d04740ebb72fefb92312caa5 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 1edd50d2d04740ebb72fefb92312caa5';\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 2018 The MathWorks, Inc.';\r\n\r\n        w = window.open();\r\n        d = w.document;\r\n        d.write('<\/p>\r\n<p>\r\n<\/p>\r\n<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>\r\n<p>\r\n<\/p>\r\n<p>\\n');\r\n\r\n        d.title = title + ' (MATLAB code)';\r\n        d.close();\r\n    }   \r\n     --> <\/script>\r\n<p style=\"text-align: right; font-size: xx-small; font-weight: lighter; font-style: italic; color: gray;\"><a><span style=\"font-size: x-small; font-style: italic;\">Get\r\nthe MATLAB code<noscript>(requires JavaScript)<\/noscript><\/span><\/a><\/p>\r\nPublished with MATLAB\u00ae R2018a\r\n\r\n<\/div>\r\n<!--\r\n1edd50d2d04740ebb72fefb92312caa5 ##### SOURCE BEGIN #####\r\n%% Fun With The Pascal Triangle\r\n% The Wikipedia article on\r\n% <https:\/\/en.wikipedia.org\/wiki\/Pascal%27s_triangle % Pascal's Triangle> has hundreds of properties of the\r\n% triangle and there are dozens of other Web pages devoted to it.\r\n% Here are a few facts that I find most interesting.\r\n\r\n%% Blaise Pascal\r\n%\r\n% <<blaise-pascal.jpg>>\r\n%\r\n\r\n%%\r\n% <https:\/\/en.wikipedia.org\/wiki\/Blaise_Pascal Blaise Pascal> (1623-1662)\r\n% was a 17th century French mathematician, physicist, inventor and\r\n% theologian.  His _Trait\u00c3\u00a9 du triangle arithm\u00c3\u00a9tique_ (_Treatise on\r\n% Arithmetical Triangle_) was published posthumously in 1665.\r\n% But this was not the first publication about the triangle.\r\n% Various versions appear in Indian, Chinese, Persian, Italian\r\n% and other manuscripts centuries before Pascal.\r\n\r\n%% Binomial Coefficients\r\n% The _binomial coefficient_ usually denoted by ${n} \\choose {k}$\r\n% is the number of ways of picking $k$ unordered outcomes from $n$\r\n% possibilities.  These coefficients appear in the expansion of\r\n% the binomial $(x+1)^n$.  For example, when $n = 7$\r\n\r\nsyms x\r\nn = 7;\r\nx7 = expand((x+1)^n)\r\n\r\n%%\r\n% Formally, the binomial coefficients are given by\r\n%\r\n% $${{n} \\choose {k}} = \\frac {n!} {k! (n-k)!}$$\r\n\r\n%%\r\n% But premature floating point overflow of the factorials makes this an\r\n% unsatisfactory basis for computation.  A better way employs the recursion\r\n%\r\n% $$ {{n} \\choose {k}} =  {{n-1} \\choose {k}} + {{n-1} \\choose {k-1}}$$\r\n%\r\n% This is used by the MATLAB function |nchoosek(n,k)|.\r\n\r\n%% Pascal Matrices\r\n% MATLAB offers two Pascal matrices.  One is symmetric, positive\r\n% definite and has the binomial coefficients on the antidiagonals.\r\n\r\nP = pascal(7)\r\n\r\n%%\r\n% The other is lower triangular, with the binomial coefficients in the\r\n% rows.  (We will see why the even numbered columns have minus signs\r\n% in a moment.)\r\n\r\nL = pascal(7,1)\r\n\r\n%%\r\n% The individual elements are\r\n%\r\n%   P(i,j) = P(j,i) = nchoosek(i+j-2,j-1)\r\n%\r\n% And (temporarily ignoring the minus signs) for |i| $\\ge$ |j|\r\n%\r\n%   L(i,j) = nchoosek(i-1,j-1)\r\n\r\n%%\r\n% The first fun fact is that |L| is the (lower) Cholesky factor of |P|.\r\n\r\nL = chol(P)'\r\n\r\n%%\r\n% So we can reconstruct |P| from |L|.\r\n\r\nP = L*L'\r\n\r\n%% Pascal Triangle\r\n% The traditional Pascal triangle is obtained by rotating P clockwise\r\n% 45 degrees, or by sliding the rows of L to the right in half increments.\r\n% Each element of the resulting triangle is the sum of the two above it.\r\n\r\ntriprint(L)\r\n\r\n%% Square Root of Identity\r\n% When the even numbered columns of |L| are given minus signs\r\n% the matrix becomes a square root of the identity.\r\n\r\nL = pascal(n,1)\r\nL_squared = L^2\r\n\r\n%%\r\n% Here is an exercise for you.\r\n% What is |sqrt(eye(n))|?  Why isn't it |L|?\r\n\r\n%% Cube Root of Identity\r\n% When I first saw this, I was amazed.  Rotate L counterclockwise.\r\n% The result is a cube root of the identity.\r\n\r\nX = rot90(L,-1)\r\nX_cubed = X^3\r\n\r\n%% Sierpinski\r\n% Which binomial coefficients are odd?  It's a fledgling fractal.\r\n\r\nodd = @(x) mod(x,2)==1;\r\nn = 56;\r\nL = abs(pascal(n,1));\r\nspy(odd(L))\r\ntitle('odd(L)')\r\n\r\n%% Fibonacci\r\n% The sums of the antidiagonals of |L| are the Fibonacci numbers.\r\n\r\nn = 12;\r\nA = fliplr(abs(pascal(n,1)))\r\nfor k = 1:n\r\nF(k) = sum(diag(A,n-k));\r\nend\r\nF\r\n\r\n%% pi\r\n% The elements in the third column of lower triangular Pascal matrix\r\n% are the _triangle numbers_.\r\n% The n-th triangle number is the number of bowling pins in the n-th row\r\n% of an array of bowling pins.\r\n%\r\n% $$t_n = {{n+1} \\choose {2}}$$\r\n\r\nL = pascal(12,1);\r\nt = L(3:end,3)'\r\n\r\n%%\r\n% Here's an unusual series relating the triangle numbers to $\\pi$.\r\n% The signs go + + - - + + - - .\r\n%\r\n%  pi - 2 = 1 + 1\/3 - 1\/6 - 1\/10 + 1\/15 + 1\/21 - 1\/28 - 1\/36 + 1\/45 + 1\/55 - ...\r\n\r\n%%\r\n\r\ntype pi_pascal\r\n\r\n%%\r\n% Ten million terms gives $\\pi$ to 14 decimal places.\r\n\r\nformat long\r\npie = pi_pascal(10000000)\r\nerr = pi - pie\r\n\r\n%% Matrix Exponential\r\n% Finally, I love this one.\r\n% The solution to the (potentially infinite) set of ordinary differential\r\n% equations\r\n%\r\n% $\\dot{x_1} = x_1$\r\n%\r\n% $\\dot{x_j} = x_j + (j-1) x_{j-1}$\r\n%\r\n% is\r\n%\r\n% $x_j = e^t (t + 1)^{j-1}$\r\n\r\n%%\r\n% This means that the matrix exponential of the simple diagonal matrix\r\n\r\nD = diag(1:7,-1)\r\n\r\n%%\r\n% is\r\n\r\nexpm_D = round(expm(D))\r\n\r\n%% Thanks\r\n% Thanks to Nick Higham for |pascal.m|, |gallery.m| and section 28.4 of\r\n%\r\n% N. J. Higham, _Accuracy and Stability of Numerical Algorithms_,\r\n% Second edition, SIAM, 2002.\r\n%\r\n% <http:\/\/epubs.siam.org\/doi\/book\/10.1137\/1.9780898718027>\r\n%\r\n##### SOURCE END ##### 1edd50d2d04740ebb72fefb92312caa5\r\n-->","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"https:\/\/blogs.mathworks.com\/cleve\/files\/blaise-pascal.jpg\" onError=\"this.style.display ='none';\" \/><\/div><!--introduction-->\r\n\r\nThe Wikipedia article on <a href=\"https:\/\/en.wikipedia.org\/wiki\/Pascal%27s_triangle\">Pascal's Triangle<\/a> has hundreds of properties of the triangle and there are dozens of other Web pages devoted to it. Here are a few facts that I find most interesting.\r\n\r\n<!--\/introduction-->... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/cleve\/2018\/02\/19\/fun-with-the-pascal-triangle\/\">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,6,16],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/posts\/3010"}],"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=3010"}],"version-history":[{"count":3,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/posts\/3010\/revisions"}],"predecessor-version":[{"id":3050,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/posts\/3010\/revisions\/3050"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/media?parent=3010"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/categories?post=3010"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/tags?post=3010"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}