[{"id":246998,"date":"2026-05-03T15:49:41","date_gmt":"2026-05-03T20:49:41","guid":{"rendered":"https:\/\/www.johndcook.com\/blog\/?p=246998"},"modified":"2026-05-03T18:24:56","modified_gmt":"2026-05-03T23:24:56","slug":"guitar-pick","status":"publish","type":"post","link":"https:\/\/www.johndcook.com\/blog\/2026\/05\/03\/guitar-pick\/","title":{"rendered":"The shape of a guitar pick"},"content":{"rendered":"<p>I saw a <a href=\"https:\/\/x.com\/sculd_88\/status\/2050841316435841231\">post<\/a> on X that plotted the function<\/p>\n<p style=\"padding-left: 40px;\">(log\u00a0<em>x<\/em>)\u00b2 + (log\u00a0<em>y<\/em>)\u00b2 = 1.<\/p>\n<p>Of course the plot of<\/p>\n<p style=\"padding-left: 40px;\"><em>x<\/em>\u00b2 + <em>y<\/em>\u00b2 = 1<\/p>\n<p>is a circle, but I never thought what taking logs would do to the shape.<\/p>\n<p>Here&#8217;s what the contours look like setting the right hand side equal to 1, 2, 3, \u2026, 10.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium\" src=\"https:\/\/www.johndcook.com\/logcircle.png\" width=\"360\" height=\"363\" \/><\/p>\n<pre>ContourPlot[Log[x]^2 + Log[y]^2, {x, 0, 10}, {y, 0, 10}, \r\n    Contours -&gt; Range[10]]<\/pre>\n<p>The dark blue contour near the origin reminded me of a guitar pick, so I decided to take a stab at creating an equation for the shape of a guitar pick.<\/p>\n<p>I wanted to rotate the image so the axis of symmetry for the pick is vertical, so I replaced <em>x<\/em> and\u00a0<em>y<\/em> with\u00a0<em>x<\/em> +\u00a0<em>y<\/em> and\u00a0<em>x<\/em> \u2212\u00a0<em>y<\/em>.<\/p>\n<p>The aspect ratio was too wide, so I experimented with<\/p>\n<p style=\"padding-left: 40px;\">log(<em>y<\/em> +\u00a0<em>kx<\/em>)\u00b2 + log(<em>y<\/em> \u2212\u00a0<em>kx<\/em>)\u00b2 =\u00a0<em>r<\/em>\u00b2<\/p>\n<p>where increasing\u00a0<em>k<\/em> increases the height-to-width ratio. After a little experimentation I settled on\u00a0<em>k<\/em> = 1.5 and\u00a0<em>r<\/em> = 1.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium\" src=\"https:\/\/www.johndcook.com\/logcircle2.png\" width=\"360\" height=\"360\" \/><\/p>\n<p>This has an aspect ratio of roughly 5:4, which is about what I measured from a photo of a guitar pick.<\/p>\n<h2>Updating: refining the fit<\/h2>\n<p>After posting this article on X, Paul Graham <a href=\"https:\/\/x.com\/paulg\/status\/2051047606114005425?s=20\">replied<\/a> with a photo of a Fender guitar pick with the image above overlaid. The fit was fairly good, but the aspect ratio wasn&#8217;t quite right.<\/p>\n<p>So then I did a little research. The shape referred to in this post is known as the &#8220;351,&#8221; but even for the 351 shape the aspect ratio varies slightly between picks.<\/p>\n<p>Setting\u00a0<em>k<\/em> = 1.6 gives a better fit to Paul Graham&#8217;s pick.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium\" src=\"https:\/\/www.johndcook.com\/pgpick.png\" width=\"360\" height=\"422\" \/><\/p>\n<p>The blue line represents my fit using <em>k<\/em> = 1.5 and the red line represents my fit using <em>k<\/em> = 1.6.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I saw a post on X that plotted the function (log\u00a0x)\u00b2 + (log\u00a0y)\u00b2 = 1. Of course the plot of x\u00b2 + y\u00b2 = 1 is a circle, but I never thought what taking logs would do to the shape. Here&#8217;s what the contours look like setting the right hand side equal to 1, 2, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[9],"tags":[],"class_list":["post-246998","post","type-post","status-publish","format-standard","hentry","category-math"],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/246998","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/comments?post=246998"}],"version-history":[{"count":0,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/246998\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/media?parent=246998"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/categories?post=246998"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/tags?post=246998"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}},{"id":246995,"date":"2026-04-30T19:06:12","date_gmt":"2026-05-01T00:06:12","guid":{"rendered":"https:\/\/www.johndcook.com\/blog\/?p=246995"},"modified":"2026-04-30T19:14:12","modified_gmt":"2026-05-01T00:14:12","slug":"burmanns-theorem","status":"publish","type":"post","link":"https:\/\/www.johndcook.com\/blog\/2026\/04\/30\/burmanns-theorem\/","title":{"rendered":"Approximating even functions by powers of cosine"},"content":{"rendered":"<p>A couple days ago I wrote a post about t<a href=\"https:\/\/www.johndcook.com\/blog\/2026\/04\/28\/even-series-trick\/\">urning a trick into a technique<\/a>, finding another use for a clever way to construct simple, accurate approximations. I used as my example approximating the Bessel function <em>J<\/em>(<em>x<\/em>) with (1 + cos(x))\/2. I learned via a helpful <a href=\"https:\/\/mathstodon.xyz\/@tpfto\/116484963022062150\">comment<\/a> on Mathstodon that my approximation was the first-order part of a more general series<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" style=\"background-color: white;\" src=\"https:\/\/www.johndcook.com\/burmann1.svg\" alt=\"J_0(x) = 1 + \\frac{\\cos(x) - 1}{2} - \\frac{(\\cos(x) - 1)^2}{48} + \\frac{7(\\cos(x) - 1)^3}{1440} + \\cdots\" width=\"504\" height=\"44\" \/><\/p>\n<p>The first-order approximation has error <em>O<\/em>(<em>x<\/em><sup>4<\/sup>), as shown in the earlier post. Adding the second-order term makes the error <em>O<\/em>(<em>x<\/em><sup>6<\/sup>), and adding the third-order term makes it <em>O<\/em>(<em>x<\/em><sup>8<\/sup>).<\/p>\n<p>I&#8217;ve written a few times about cosine approximations to the normal probability density. For example, see <a href=\"https:\/\/www.johndcook.com\/blog\/2023\/07\/05\/normal-approximation\/\">this post<\/a>. We could use the same idea as the series above to approximate the normal density with a series of powers of cosine. This gives us<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" style=\"background-color: white;\" src=\"https:\/\/www.johndcook.com\/burmann2.svg\" alt=\"\\exp(-x^2\/2) = 1 + (\\cos(x) - 1) + \\frac{(\\cos(x) - 1)^2}{3} + \\frac{2(\\cos(x) - 1)^3}{45} + \\cdots\" width=\"569\" height=\"44\" \/><\/p>\n<p>and as before, the first, second, and third order truncated series have error <em>O<\/em>(<em>x<\/em><sup>4<\/sup>), <em>O<\/em>(<em>x<\/em><sup>6<\/sup>), and <em>O<\/em>(<em>x<\/em><sup>8<\/sup>).<\/p>\n<p>The general theory behind what&#8217;s going on here is an extension of <a href=\"https:\/\/mathworld.wolfram.com\/BuermannsTheorem.html\">B\u00fcrmann&#8217;s theorem<\/a>. The original version of the theorem relies on a series inversion theorem that in turn relies on the approximating function, in our case cos(<em>x<\/em>) \u2212 1, not having zero derivative at the center of the series. But there is a more general form of B\u00fcrmann&#8217;s theorem based on a <a href=\"https:\/\/www.johndcook.com\/blog\/2025\/09\/21\/mollweide-for-high-latitudes\/\">more general form of series inversion<\/a>. We will always need a more general version of the theorem when working with even functions because even functions have zero derivative at zero.<\/p>\n<p>Here&#8217;s another example, this time using the Bessel function <em>J<\/em><sub>1<\/sub>, an odd function, which does use the original version of B\u00fcrmann&#8217;s theorem to approximate <em>J<\/em><sub>1<\/sub>\u00a0by powers of sine.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" style=\"background-color: white;\" src=\"https:\/\/www.johndcook.com\/burmann3.svg\" alt=\"J_1(x) = \\frac{1}{2} \\sin(x) + \\frac{1}{48} \\sin^3(x) + \\frac{17}{1920} \\sin^5(x) + \\cdots\" width=\"406\" height=\"41\" \/><\/p>\n<p>In this case truncating the series after sin<sup><em>k<\/em><\/sup>(<em>x<\/em>) gives an error <em>O<\/em>(<em>x<\/em><sup><em>k<\/em> + 2<\/sup>).<\/p>\n<p>You can find more on B\u00fcrmann&#8217;s theorem in <a href=\"https:\/\/www.johndcook.com\/blog\/2022\/07\/20\/whittaker-and-watson\/\">Whittker and Watson<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A couple days ago I wrote a post about turning a trick into a technique, finding another use for a clever way to construct simple, accurate approximations. I used as my example approximating the Bessel function J(x) with (1 + cos(x))\/2. I learned via a helpful comment on Mathstodon that my approximation was the first-order [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[9],"tags":[129],"class_list":["post-246995","post","type-post","status-publish","format-standard","hentry","category-math","tag-special-functions"],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/246995","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/comments?post=246995"}],"version-history":[{"count":0,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/246995\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/media?parent=246995"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/categories?post=246995"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/tags?post=246995"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}},{"id":246993,"date":"2026-04-30T09:51:08","date_gmt":"2026-04-30T14:51:08","guid":{"rendered":"https:\/\/www.johndcook.com\/blog\/?p=246993"},"modified":"2026-04-30T15:18:27","modified_gmt":"2026-04-30T20:18:27","slug":"derivative-of-relu","status":"publish","type":"post","link":"https:\/\/www.johndcook.com\/blog\/2026\/04\/30\/derivative-of-relu\/","title":{"rendered":"Three ways to differentiate ReLU"},"content":{"rendered":"<p>When a function is not differentiable in the classical sense there are multiple ways to compute a generalized derivative. This post will look at three generalizations of the classical derivative, each applied to the ReLU (rectified linear unit) function. The ReLU function is a commonly used <a href=\"https:\/\/www.johndcook.com\/blog\/2023\/07\/01\/activation-functions\/\">activation function<\/a> for neural networks. It&#8217;s also called the ramp function for obvious reasons.<\/p>\n<p><img decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/www.johndcook.com\/ReLU_plot.png\" \/><\/p>\n<p>The function is simply\u00a0<em>r<\/em>(<em>x<\/em>) = max(0,\u00a0<em>x<\/em>).<\/p>\n<h2>Pointwise derivative<\/h2>\n<p>The <strong>pointwise<\/strong> derivative would be 0 for\u00a0<em>x<\/em> &lt; 0, 1 for <em>x<\/em> &gt; 0, and undefined at\u00a0<em>x<\/em> = 0. So except at 0, the pointwise derivative of the ramp function is the <a href=\"https:\/\/www.johndcook.com\/blog\/2010\/01\/06\/heaviside\/\">Heaviside<\/a> function.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" style=\"background-color: white;\" src=\"https:\/\/www.johndcook.com\/heaviside3.svg\" alt=\"H(x) = \\left\\{ \\begin{array}{ll} 1 &amp; \\mbox{if } x \\geq 0 \\\\ 0 &amp; \\mbox{if } x &lt; 0 \\end{array} \\right.\" width=\"173\" height=\"48\" \/><br \/>\nIn a real analysis course, you&#8217;d simply say\u00a0<em>r<\/em>\u2032(<em>x<\/em>) =<em>H<\/em>(<em>x<\/em>) because functions are only defined up to equivalent modulo sets of measure zero, i.e. the definition at\u00a0<em>x<\/em> = 0 doesn&#8217;t matter.<\/p>\n<h2>Distributional derivative<\/h2>\n<p>In\u00a0<strong>distribution theory<\/strong> you&#8217;d identify the function\u00a0<em>r<\/em>(<em>x<\/em>) with the distribution whose action on a test function \u03c6 is<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" style=\"background-color: white;\" src=\"https:\/\/www.johndcook.com\/ramp_action.svg\" alt=\"\\langle r, \\varphi \\rangle = \\int_{-\\infty}^\\infty r(x)\\, \\varphi(x) \\, dx\" width=\"207\" height=\"45\" \/><\/p>\n<p>Then the derivative of <em>r<\/em> would be the distribution <em>r<\/em>\u2032 satisfying<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" style=\"background-color: white;\" src=\"https:\/\/www.johndcook.com\/ramp_derivative_action.svg\" alt=\"\\langle r^{\\prime}, \\varphi\\rangle = -\\langle r, \\varphi^{\\prime} \\rangle\" width=\"132\" height=\"19\" \/><\/p>\n<p>for all smooth functions \u03c6 with compact support. You can prove using integration by parts that the above equals the integral of \u03c6 from 0 to \u221e, which is the same as the action of <em>H<\/em>(<em>x<\/em>) on \u03c6.<\/p>\n<p>In this case the distributional derivative of\u00a0<em>r<\/em> is the same as the pointwise derivative of\u00a0<em>r<\/em> interpreted as a distribution. This does not happen in general [1]. For example, the pointwise derivative of <em>H<\/em> is zero but the distributional derivative of <em>H<\/em> is \u03b4, the Dirac delta distribution.<\/p>\n<p>For more on distributional derivatives, see <a href=\"https:\/\/www.johndcook.com\/blog\/2009\/10\/25\/how-to-differentiate-a-non-differentiable-function\/\">How to differentiate a non-differentiable function<\/a>.<\/p>\n<h2>Subgradient<\/h2>\n<p>The subgradient of a function <em>f<\/em> at a point <em>x<\/em>, written \u2202<em>f<\/em>(<em>x<\/em>), is the set of slopes of tangent lines to the graph of\u00a0<em>f<\/em> at\u00a0<em>x<\/em>. If\u00a0<em>f<\/em> is differentiable at\u00a0<em>x<\/em>, then there is only one slope, namely\u00a0<em>f<\/em>\u2032(<em>x<\/em>), and we typically say the subgradient of <em>f<\/em> at\u00a0<em>x<\/em> is simply <em>f<\/em>\u2032(<em>x<\/em>) when strictly speaking we should say it is the one-element set {<em>f<\/em>\u2032(<em>x<\/em>)}.<\/p>\n<p>A line tangent to the graph of the ReLU function at a negative value of <em>x<\/em> has slope 0, and a tangent line at a positive\u00a0<em>x<\/em> has slope 1. But because there&#8217;s a sharp corner at\u00a0<em>x<\/em> = 0, a tangent at this point could have any slope between 0 and 1.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" style=\"background-color: white;\" src=\"https:\/\/www.johndcook.com\/subgradient.svg\" alt=\"\\partial f(x) = \\left\\{ \\begin{array}{cl} 1 &amp; \\text{if } x &gt; 0 \\\\&lt;br \/&gt; \\left[0,1\\right] &amp; \\text{if } x = 0 \\\\&lt;br \/&gt; 0 &amp; \\text{if } x &lt; 0 \\end{array} \\right.\" width=\"214\" height=\"73\" \/><\/p>\n<p>My dissertation was full of subgradients of convex functions. This made me uneasy because subgradients are not real-valued functions; they&#8217;re set-valued functions. Most of the time you can blithely ignore this distinction, but there&#8217;s always a nagging suspicion that it&#8217;s going to bite you unexpectedly.<\/p>\n<p>&nbsp;<\/p>\n<p>[1] When\u00a0<em>is<\/em> the pointwise derivative of <em>f<\/em> as a function equal to the derivative of\u00a0<em>f<\/em> as a distribution? It&#8217;s not enough for\u00a0<em>f<\/em> to be continuous, but it is sufficient for <em>f<\/em> to be\u00a0<em>absolutely<\/em> continuous.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When a function is not differentiable in the classical sense there are multiple ways to compute a generalized derivative. This post will look at three generalizations of the classical derivative, each applied to the ReLU (rectified linear unit) function. The ReLU function is a commonly used activation function for neural networks. It&#8217;s also called the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[9],"tags":[],"class_list":["post-246993","post","type-post","status-publish","format-standard","hentry","category-math"],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/246993","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/comments?post=246993"}],"version-history":[{"count":0,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/246993\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/media?parent=246993"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/categories?post=246993"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/tags?post=246993"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}},{"id":246992,"date":"2026-04-28T16:44:58","date_gmt":"2026-04-28T21:44:58","guid":{"rendered":"https:\/\/www.johndcook.com\/blog\/?p=246992"},"modified":"2026-04-28T16:44:58","modified_gmt":"2026-04-28T21:44:58","slug":"even-series-trick","status":"publish","type":"post","link":"https:\/\/www.johndcook.com\/blog\/2026\/04\/28\/even-series-trick\/","title":{"rendered":"Turning a trick into a technique"},"content":{"rendered":"<p>Someone said a technique is a trick that works twice.<\/p>\n<p>I wanted to see if I could get anything interesting by turning the trick in the <a href=\"https:\/\/www.johndcook.com\/blog\/2026\/04\/28\/circular-arc-approximation\/\">previous post<\/a> into a technique. The trick created a high-order approximation by subtracting a multiple one even function from another. Even functions only have even-order terms, and by using the right multiple you can cancel out the second-order term as well.<\/p>\n<p>For an example, I&#8217;d like to approximate the Bessel function <em>J<\/em><sub>0<\/sub>(<em>x<\/em>) by the better known cosine function. Both are even functions.<\/p>\n<p style=\"padding-left: 40px;\"><em>J<\/em><sub>0<\/sub>(<em>x<\/em>) = 1 \u2212 <em>x<\/em><sup>2<\/sup>\/4 + <em>x<\/em><sup>4<\/sup>\/64 + \u2026<br \/>\ncos(<em>x<\/em>) = 1 \u2212 <em>x<\/em><sup>2<\/sup>\/2 + <em>x<\/em><sup>4<\/sup>\/24 + \u2026<\/p>\n<p>and so<\/p>\n<p style=\"padding-left: 40px;\">2 <em>J<\/em><sub>0<\/sub>(<em>x<\/em>) \u2212 cos(<em>x<\/em>) = 1 \u2212 <em>x<\/em><sup>4<\/sup>\/96 + \u2026<\/p>\n<p>which means<\/p>\n<p style=\"padding-left: 40px;\"><em>J<\/em><sub>0<\/sub>(<em>x<\/em>) \u2248 (1 + cos(<em>x<\/em>))\/2<\/p>\n<p>is an excellent approximation for small <em>x<\/em>.<\/p>\n<p>Let&#8217;s try this for a couple examples.<\/p>\n<p><em>J<\/em><sub>0<\/sub>(0.2) = 0.990025 and (1 + cos(0.2))\/2 = 0.990033.<\/p>\n<p><em>J<\/em><sub>0<\/sub>(0.05) = 0.99937510 and (1 + cos(0.05))\/2 = 0.99937513.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Someone said a technique is a trick that works twice. I wanted to see if I could get anything interesting by turning the trick in the previous post into a technique. The trick created a high-order approximation by subtracting a multiple one even function from another. Even functions only have even-order terms, and by using [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[9],"tags":[129],"class_list":["post-246992","post","type-post","status-publish","format-standard","hentry","category-math","tag-special-functions"],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/246992","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/comments?post=246992"}],"version-history":[{"count":0,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/246992\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/media?parent=246992"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/categories?post=246992"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/tags?post=246992"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}},{"id":246991,"date":"2026-04-28T08:09:42","date_gmt":"2026-04-28T13:09:42","guid":{"rendered":"https:\/\/www.johndcook.com\/blog\/?p=246991"},"modified":"2026-04-28T14:17:05","modified_gmt":"2026-04-28T19:17:05","slug":"circular-arc-approximation","status":"publish","type":"post","link":"https:\/\/www.johndcook.com\/blog\/2026\/04\/28\/circular-arc-approximation\/","title":{"rendered":"Circular arc approximation"},"content":{"rendered":"<p>Suppose you have an arc <em>a<\/em>, a portion of a circle of radius <em>r<\/em>, and you know two things: the length <em>c<\/em> of the chord of the arc, and the length\u00a0<em>b<\/em>\u00a0of the chord of half the arc, illustrated below.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium\" src=\"https:\/\/www.johndcook.com\/circular_arc_approx1.png\" width=\"360\" height=\"360\" \/><\/p>\n<p>Here \u03b8 is the central angle of the arc. Then the length of the arc, <em>r<\/em>\u03b8, is approximately<\/p>\n<p style=\"padding-left: 40px;\"><span style=\"background-color: #dee;\"><em>a<\/em> = <em>r<\/em>\u03b8 \u2248 12 <em>b<\/em>\u00b2\/(<em>c<\/em> + 4<em>b<\/em>).<\/span><\/p>\n<p>If the arc is moderately small, the approximation is very accurate.<\/p>\n<p>This approximation is simple, accurate, and not obvious, much like the one in <a href=\"https:\/\/www.johndcook.com\/blog\/2026\/04\/23\/solve-a-right-triangle\/\">this post<\/a><\/p>\n<h2>Derivation<\/h2>\n<p>Let \u03c6 = \u03b8\/4. Then the angle between the chords <em>b<\/em> and <em>c<\/em> is \u03c6. This follows from the inscribed angle theorem, illustrated below.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium\" src=\"https:\/\/www.johndcook.com\/circular_arc_approx2.png\" width=\"360\" height=\"360\" \/><\/p>\n<p>There are two right triangles in the diagram above that have an angle \u03c6: a smaller triangle with hypotenuse <em>b<\/em> and a larger triangle with hypotenuse 2<em>r<\/em>. From the smaller triangle we learn<\/p>\n<p style=\"padding-left: 40px;\">cos(\u03c6) =\u00a0<em>c<\/em> \/\u00a02<em>b<\/em><\/p>\n<p>and from the larger triangle we learn<\/p>\n<p style=\"padding-left: 40px;\">sin(\u03c6) = <em>b<\/em> \/ 2<em>r<\/em>.<\/p>\n<p>Now expand in power series.<\/p>\n<p style=\"padding-left: 40px;\"><em>c<\/em> \/ 2<em>b<\/em> = cos(\u03c6) = 1 \u2212 \u03c6<sup>2<\/sup>\/2! + \u03c6<sup>4<\/sup>\/4! \u2212 \u2026<br \/>\n2<em>b<\/em> \/\u00a0<em>a<\/em> = sin(\u03c6) \/ \u03c6 = 1 \u2212 \u03c6<sup>2<\/sup>\/3! + \u03c6<sup>4<\/sup>\/5! \u2212 \u2026<\/p>\n<p>If we multiply 2<em>b<\/em> \/\u00a0<em>a<\/em> by 3 and subtract <em>c<\/em> \/ 2<em>b<\/em> then the \u03c6<sup>2<\/sup> terms cancel out and we get<\/p>\n<p style=\"padding-left: 40px;\">6<em>b<\/em> \/\u00a0<em>a<\/em> \u2212\u00a0<em>c<\/em> \/ 2<em>b<\/em> = 2 \u2212 \u03c6<sup>4<\/sup>\/60 + \u2026<\/p>\n<p>and so<\/p>\n<p style=\"padding-left: 40px;\">6<em>b<\/em> \/\u00a0<em>a<\/em> \u2212\u00a0<em>c<\/em> \/ 2<em>b<\/em> \u2248 2<\/p>\n<p>to a very high degree of accuracy when \u03c6 is small. The approximation follows by solving for\u00a0<em>a<\/em>.<\/p>\n<h2>Example<\/h2>\n<p>Let \u03b8 = \u03c0\/3 and so \u03c6 = 0.26\u2026, not a particularly small value of \u03c6, but small enough for the approximation to work well.<\/p>\n<p>Set <em>r<\/em> = 1 so <em>a<\/em> = \u03b8. Then<\/p>\n<p style=\"padding-left: 40px;\"><em>b<\/em> = 2 sin(\u03c0\/12) = 0.51764<\/p>\n<p>and<\/p>\n<p style=\"padding-left: 40px;\"><em>c<\/em> = 2<em>b<\/em> cos(\u03c0\/12) = 1.<\/p>\n<p>Now in application, we know\u00a0<em>b<\/em> and\u00a0<em>c<\/em>, not \u03b8, and so pretend we\u00a0<strong>measured<\/strong>\u00a0<em>b<\/em> = 0.51764 and\u00a0<em>c<\/em> = 1. Then we would approximate\u00a0<em>a<\/em> by<\/p>\n<p style=\"padding-left: 40px;\">12<em>b<\/em>\u00b2\/(<em>c<\/em> + 4<em>b<\/em>) = 1.04718<\/p>\n<p>while the exact value is 1.04720. Unless you can measure lengths to more than four significant figures, the approximation may has well be exact because approximation error would be less than measurement error.<\/p>\n<p>&nbsp;<\/p>\n<p>[1] J. M. Bruce. Approximation to a Circular Arc. The American Mathematical Monthly. Vol. 49, No. 3 (March 1942), pp. 184\u2013185<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Suppose you have an arc a, a portion of a circle of radius r, and you know two things: the length c of the chord of the arc, and the length\u00a0b\u00a0of the chord of half the arc, illustrated below. Here \u03b8 is the central angle of the arc. Then the length of the arc, r\u03b8, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[9],"tags":[224],"class_list":["post-246991","post","type-post","status-publish","format-standard","hentry","category-math","tag-geometry"],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/246991","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/comments?post=246991"}],"version-history":[{"count":0,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/246991\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/media?parent=246991"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/categories?post=246991"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/tags?post=246991"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}},{"id":246989,"date":"2026-04-25T11:16:12","date_gmt":"2026-04-25T16:16:12","guid":{"rendered":"https:\/\/www.johndcook.com\/blog\/?p=246989"},"modified":"2026-04-25T11:18:14","modified_gmt":"2026-04-25T16:18:14","slug":"exact-solution-nonlinear-pendulum","status":"publish","type":"post","link":"https:\/\/www.johndcook.com\/blog\/2026\/04\/25\/exact-solution-nonlinear-pendulum\/","title":{"rendered":"Closed-form solution to the nonlinear pendulum equation"},"content":{"rendered":"<p>The <a href=\"https:\/\/www.johndcook.com\/blog\/2026\/04\/24\/nonlinear-pendulum\/\">previous post<\/a> looks at the nonlinear pendulum equation and what difference it makes to the solutions if you linearize the equation.<\/p>\n<p>If the initial displacement is small enough, you can simply replace sin \u03b8 with \u03b8. If the initial displacement is larger, you can improve the accuracy quite a bit by solving the linearized equation and then adjusting the period.<\/p>\n<p>You can also find an exact solution, but not in terms of elementary functions; you have to use Jacobi elliptic functions. These are functions somewhat analogous to trig functions, though it&#8217;s not helpful to try to pin down the analogies. For example, the Jacobi function sn is like the sine function in some ways but very different in others, depending on the range of arguments.<\/p>\n<p>We start with the differential equation<\/p>\n<p style=\"padding-left: 40px;\">\u03b8\u2033(<em>t<\/em>) + <em>c<\/em>\u00b2 sin( \u03b8(<em>t<\/em>) ) = 0<\/p>\n<p>where <em>c<\/em>\u00b2 = <em>g<\/em>\/<em>L<\/em>, i.e. the gravitational constant divided by pendulum length, and initial conditions \u03b8(0) = \u03b8<sub>0<\/sub> and \u03b8\u2032(0) = 0. We assume \u2212\u03c0 &lt; \u03b8<sub>0<\/sub> &lt; \u03c0.<\/p>\n<p>Then the solution is<\/p>\n<p style=\"padding-left: 40px;\">\u03b8(<em>t<\/em>) = 2 arcsin( <em>a<\/em> cd(<em>c<\/em><em>t<\/em> | <em>m<\/em> ) )<\/p>\n<p>where <em>a<\/em> = sin(\u03b8<sub>0<\/sub>\/2), <em>m<\/em> =\u00a0<em>a<\/em>\u00b2, and cd is one of the 12 Jacobi elliptic functions. Note that cd, like all the Jacobi functions, has an argument and a parameter. In the equation above the argument is\u00a0<em>ct<\/em> and the parameter is\u00a0<em>m<\/em>.<\/p>\n<p>The last plot in the previous post was misleading, showing roughly equal parts genuine difference and error from solving the differential equation numerically. Here&#8217;s the code that was used to solve the nonlinear equation.<\/p>\n<pre>from scipy.special import ellipj, ellipk\r\nfrom numpy import sin, cos, pi, linspace, arcsin\r\nfrom scipy.integrate import solve_ivp\r\n\r\ndef exact_period(\u03b8):\r\n    return 2*ellipk(sin(\u03b8\/2)**2)\/pi\r\n\r\ndef nonlinear_ode(t, z):\r\n    x, y = z\r\n    return [y, -sin(x)]    \r\n\r\ntheta0 = pi\/3\r\nb = 2*pi*exact_period(theta0)\r\nt = linspace(0, 2*b, 2000)\r\n\r\nsol = solve_ivp(nonlinear_ode, [0, 2*b], [theta0, 0], t_eval=t)\r\n<\/pre>\n<p>The solution is contained in <code>sol.y[0]<\/code>.<\/p>\n<p>Let&#8217;s compare the numerical solution to the exact solution.<\/p>\n<pre>def f(t, c, theta0):\r\n    a = sin(theta0\/2)\r\n    m = a**2\r\n    sn, cn, dn, ph = ellipj(c*t, m)\r\n    return 2*arcsin(a*cn\/dn)\r\n<\/pre>\n<p>There are a couple things to note about the code. First,SciPy doesn&#8217;t implement the cd function, but it can be computed as cn\/dn. Second, the function <code>ellipj<\/code> returns four functions at once because it takes about as much time to calculate all four as it does to compute one of them.<\/p>\n<p>Here is a plot of the error in solving the differential equation.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium\" src=\"https:\/\/www.johndcook.com\/nonlinpend4.png\" width=\"480\" height=\"360\" \/><\/p>\n<p>And here is the difference between the exact solution to the nonlinear pendulum equation and the stretched solution to the linear equation.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium\" src=\"https:\/\/www.johndcook.com\/nonlinpend5.png\" width=\"480\" height=\"360\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The previous post looks at the nonlinear pendulum equation and what difference it makes to the solutions if you linearize the equation. If the initial displacement is small enough, you can simply replace sin \u03b8 with \u03b8. If the initial displacement is larger, you can improve the accuracy quite a bit by solving the linearized [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[9],"tags":[47,129],"class_list":["post-246989","post","type-post","status-publish","format-standard","hentry","category-math","tag-differential-equations","tag-special-functions"],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/246989","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/comments?post=246989"}],"version-history":[{"count":0,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/246989\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/media?parent=246989"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/categories?post=246989"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/tags?post=246989"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}},{"id":246988,"date":"2026-04-25T08:12:39","date_gmt":"2026-04-25T13:12:39","guid":{"rendered":"https:\/\/www.johndcook.com\/blog\/?p=246988"},"modified":"2026-04-25T08:12:39","modified_gmt":"2026-04-25T13:12:39","slug":"nth-derivative-of-a-quotient","status":"publish","type":"post","link":"https:\/\/www.johndcook.com\/blog\/2026\/04\/25\/nth-derivative-of-a-quotient\/","title":{"rendered":"nth derivative of a quotient"},"content":{"rendered":"<p>There&#8217;s a nice formula for the\u00a0<em>n<\/em>th derivative of a product. It looks a lot like the binomial theorem.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" style=\"background-color: white;\" src=\"https:\/\/www.johndcook.com\/leibniz.svg\" alt=\"(gh)^{(n)} = \\sum_{k=0}^n \\binom{n}{k} g^{(k)} h^{(n-k)}\" width=\"212\" height=\"54\" \/><\/p>\n<p>There is also a formula for the\u00a0<em>n<\/em>th derivative of a quotient, but it&#8217;s more complicated and less known.<\/p>\n<p>We start by writing the quotient rule in an unusual way.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" style=\"background-color: white;\" src=\"https:\/\/www.johndcook.com\/quotient1.svg\" alt=\"\\left(\\frac{g}{h}\\right)^{(1)} = \\frac{1}{h^2} \\left| \\begin{array}{cc} h &amp; g \\\\ h^\\prime &amp; g^\\prime \\\\ \\end{array} \\right|\" width=\"171\" height=\"48\" \/><\/p>\n<p>Applying the quotient rule twice gives the following.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" style=\"background-color: white;\" src=\"https:\/\/www.johndcook.com\/quotient2.svg\" alt=\"\\left(\\frac{g}{h}\\right)^{(2)} = \\frac{1}{h^3} \\left| \\begin{array}{ccc} h &amp; 0 &amp; g \\\\ h^\\prime &amp; h &amp; g^\\prime \\\\ h^{\\prime\\prime} &amp; 2h^\\prime &amp; g^{\\prime\\prime} \\\\ \\end{array} \\right|\" width=\"222\" height=\"72\" \/><\/p>\n<p>And here&#8217;s the general rule in all its glory.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" style=\"background-color: white;\" src=\"https:\/\/www.johndcook.com\/quotientn.svg\" alt=\"\\left(\\frac{g}{h}\\right)^{(n)} = \\frac{1}{h^{\\,n+1}} \\left| \\begin{array}{cccccc} h &amp; 0 &amp; 0 &amp; \\cdots &amp; 0 &amp; g \\\\[3pt] h^\\prime &amp; h &amp; 0 &amp; \\cdots &amp; 0 &amp; g^\\prime \\\\[3pt] h^{\\prime\\prime} &amp; 2h^\\prime &amp; h &amp; \\cdots &amp; 0 &amp; g^{\\prime\\prime} \\\\[3pt] \\cdots &amp; \\cdots &amp; \\cdots &amp; \\cdots &amp; \\cdots &amp; \\cdots \\\\[3pt] h^{(n)} &amp; \\binom{n}{1}h^{(n-1)} &amp; \\binom{n}{2}h^{(n-2)} &amp; \\cdots &amp; \\binom{n}{1}h^\\prime &amp; g^{(n)} \\end{array} \\right|\" width=\"492\" height=\"144\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>Source: V. F. Ivanoff. The <em>n<\/em>th Derivative of a Fractional Function. The American Mathematical Monthly, Vol. 55, No. 8 (Oct., 1948), p. 491<\/p>\n","protected":false},"excerpt":{"rendered":"<p>There&#8217;s a nice formula for the\u00a0nth derivative of a product. It looks a lot like the binomial theorem. There is also a formula for the\u00a0nth derivative of a quotient, but it&#8217;s more complicated and less known. We start by writing the quotient rule in an unusual way. Applying the quotient rule twice gives the following. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-246988","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/246988","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/comments?post=246988"}],"version-history":[{"count":0,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/246988\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/media?parent=246988"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/categories?post=246988"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/tags?post=246988"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}},{"id":246986,"date":"2026-04-24T18:53:29","date_gmt":"2026-04-24T23:53:29","guid":{"rendered":"https:\/\/www.johndcook.com\/blog\/?p=246986"},"modified":"2026-04-25T11:19:01","modified_gmt":"2026-04-25T16:19:01","slug":"nonlinear-pendulum","status":"publish","type":"post","link":"https:\/\/www.johndcook.com\/blog\/2026\/04\/24\/nonlinear-pendulum\/","title":{"rendered":"How nonlinearity affects a pendulum"},"content":{"rendered":"<p>The equation of motion for a pendulum is the differential equation<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium\" style=\"background-color: white;\" src=\"https:\/\/www.johndcook.com\/nonlinear_pendulum.svg\" alt=\"\\theta'' + \\frac{g}{\\ell}\\sin \\theta = 0\" width=\"119\" height=\"33\" \/><\/p>\n<p>where\u00a0<em>g<\/em> is the acceleration due to gravity and \u2113 is the length of the pendulum. When this is presented in an introductory physics class, the instructor will immediately say something like &#8220;we&#8217;re only interested in the case where \u03b8 is small, so we can rewrite the equation as<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium\" style=\"background-color: white;\" src=\"https:\/\/www.johndcook.com\/linear_pendulum.svg\" alt=\"\\theta'' + \\frac{g}{\\ell} \\theta = 0\" width=\"91\" height=\"33\" \/><\/p>\n<h2>Questions<\/h2>\n<p>This raises a lot of questions, or at least it should.<\/p>\n<ol>\n<li>Why not leave sin \u03b8 alone?<\/li>\n<li>What justifies replacing sin \u03b8 with just \u03b8?<\/li>\n<li>How small does \u03b8 have to be for this to be OK?<\/li>\n<li>How do the solutions to the exact and approximate equations differ?<\/li>\n<\/ol>\n<p>First, sine is a nonlinear function, making the differential equation nonlinear. The nonlinear pendulum equation cannot be solved using mathematics that students in an introductory physics class have seen. There is a <a href=\"https:\/\/www.johndcook.com\/blog\/2026\/04\/25\/exact-solution-nonlinear-pendulum\/\">closed-form solution<\/a>, but only if you extend &#8220;closed-form&#8221; to mean more than the elementary functions a student would see in a calculus class.<\/p>\n<p>Second, the approximation is justified because sin \u03b8 \u2248 \u03b8 when \u03b8 is small. That&#8217;s true, but it&#8217;s kinda subtle. Here&#8217;s a <a href=\"https:\/\/www.johndcook.com\/blog\/2010\/07\/27\/sine-approximation-for-small-x\/\">post<\/a> unpacking that.<\/p>\n<p>The third question doesn&#8217;t have a simple answer, though simple answers are often given. An instructor could make up an answer on the spot and say &#8220;less than 10 degrees&#8221; or something like that. A more thorough answer requires answering the fourth question.<\/p>\n<p>I address how nonlinear affects the solutions in a <a href=\"https:\/\/www.johndcook.com\/blog\/2023\/11\/20\/nonlinear-pendulum-period\/\">post<\/a> a couple years ago. This post will expand a bit on that post.<\/p>\n<h2>Longer period<\/h2>\n<p>The primary difference between the nonlinear and linear pendulum equations is that the solutions to the nonlinear equation have longer periods. The solution to the linear equation is a cosine. Solving the equation determines the frequency, amplitude, and phase shift of the cosine, but qualitatively it&#8217;s just a cosine. The solution to the corresponding nonlinear equation, with sin \u03b8 rather than \u03b8, is not exactly a cosine, but it looks a lot like a cosine, only the period is a little longer [1].<\/p>\n<p>OK, the nonlinear pendulum has a longer period, but how much longer? The period is increased by a factor\u00a0<em>f<\/em>(\u03b8<sub>0<\/sub>) where \u03b8<sub>0<\/sub>\u00a0is the initial displacement.<\/p>\n<p>You can find the exact answer in my <a href=\"https:\/\/www.johndcook.com\/blog\/2023\/11\/20\/nonlinear-pendulum-period\/\">earlier post<\/a>. The exact answer depends on a special function called the \u201ccomplete elliptic integral of the first kind,\u201d but to a good approximation<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium\" src=\"https:\/\/www.johndcook.com\/nonlinear_pendulum_period3.svg\" alt=\"f(\\theta) \\approx \\frac{1}{\\sqrt{\\cos(\\theta\/2)}}\" width=\"141\" height=\"45\" \/><\/p>\n<p>The earlier post compares this approximation to the exact function.<\/p>\n<h2>Linear solution with adjusted period<\/h2>\n<p>Since the nonlinear pendulum equation is roughly the same as the linear equation with a longer period, you can approximate the solution to the nonlinear equation by solving the linear equation but increasing the period. How good is that approximation?<\/p>\n<p>Let&#8217;s do an example with \u03b8<sub>0<\/sub> = 60\u00b0 = \u03c0\/3 radians. Then sin \u03b8<sub>0<\/sub> = 0.866 but \u03b8<sub>0<\/sub>, in radians, is 1.047, so we definitely can&#8217;t say sin \u03b8<sub>0<\/sub> is approximately \u03b8<sub>0<\/sub>. To make things simple, let&#8217;s set \u2113 =\u00a0<em>g<\/em>. Also, assume the pendulum starts from rest, i.e. \u03b8'(0) = 0.<\/p>\n<p>Here&#8217;s a plot of the solutions to the nonlinear and linear equations.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium\" src=\"https:\/\/www.johndcook.com\/nonlinpend1.png\" width=\"480\" height=\"360\" \/><\/p>\n<p>Obviously the solution to the nonlinear equation has a longer period. In fact it&#8217;s 7.32% longer. (The approximation above would have estimated 7.46%.)<\/p>\n<p>Here&#8217;s a plot comparing the solution of the nonlinear equation and the solution to the linear equations with period stretched by 7.32%.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium\" src=\"https:\/\/www.johndcook.com\/nonlinpend2.png\" width=\"480\" height=\"360\" \/><\/p>\n<p>The solutions differ by less than the width of the plotting line, so it&#8217;s too small to see. But we can see there&#8217;s a difference when we subtract the two solutions.<\/p>\n<p>Here&#8217;s a plot of the solutions to the nonlinear and linear equations.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium\" src=\"https:\/\/www.johndcook.com\/nonlinpend3.png\" width=\"480\" height=\"360\" \/><\/p>\n<p><b>Update<\/b>: The plot above is misleading. Part of what it shows is numerical error from solving the pendulum equation. When we redo the plot using the exact solution the error is about half as large. And the error is periodic, as we&#8217;d expect. See <a href=\"https:\/\/www.johndcook.com\/blog\/2026\/04\/25\/exact-solution-nonlinear-pendulum\/\">this post<\/a> for more on the exact solution using Jacobi functions and the differential equation solver that was used to make the original plot.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium\" src=\"https:\/\/www.johndcook.com\/nonlinpend5.png\" width=\"480\" height=\"360\" \/><\/p>\n<h2>Related posts<\/h2>\n<ul>\n<li class=\"link\"><a href=\"https:\/\/www.johndcook.com\/blog\/2013\/02\/19\/mechanical-vibrations\/\">Mechanical vibrations<\/a><\/li>\n<li class=\"link\"><a href=\"https:\/\/www.johndcook.com\/blog\/2025\/12\/23\/bowie-integrator-and-the-nonlinear-pendulum\/\">Bowie integrator and the nonlinear pendulum<\/a><\/li>\n<\/ul>\n<p>[1] The period of a pendulum depends on its length \u2113, and so we can think of the nonlinear term effectively replacing \u2113 by a longer effective length \u2113<sub>eff<\/sub>.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The equation of motion for a pendulum is the differential equation where\u00a0g is the acceleration due to gravity and \u2113 is the length of the pendulum. When this is presented in an introductory physics class, the instructor will immediately say something like &#8220;we&#8217;re only interested in the case where \u03b8 is small, so we can [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[9],"tags":[47],"class_list":["post-246986","post","type-post","status-publish","format-standard","hentry","category-math","tag-differential-equations"],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/246986","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/comments?post=246986"}],"version-history":[{"count":0,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/246986\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/media?parent=246986"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/categories?post=246986"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/tags?post=246986"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}},{"id":246984,"date":"2026-04-23T10:56:02","date_gmt":"2026-04-23T15:56:02","guid":{"rendered":"https:\/\/www.johndcook.com\/blog\/?p=246984"},"modified":"2026-04-23T11:08:47","modified_gmt":"2026-04-23T16:08:47","slug":"solve-an-oblique-triangle","status":"publish","type":"post","link":"https:\/\/www.johndcook.com\/blog\/2026\/04\/23\/solve-an-oblique-triangle\/","title":{"rendered":"Approximation to solve an oblique triangle"},"content":{"rendered":"<p>The <a href=\"https:\/\/www.johndcook.com\/blog\/2026\/04\/23\/solve-a-right-triangle\/\">previous post<\/a> gave a simple and accurate approximation for the smaller angle of a right triangle. Given a\u00a0right triangle with sides <em>a<\/em>,\u00a0<em>b<\/em>, and\u00a0<em>c<\/em>, where\u00a0<em>a<\/em> is the shortest side and\u00a0<em>c<\/em> is the hypotenuse, the angle opposite side <em>a<\/em> is approximately<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" style=\"background-color: white;\" src=\"https:\/\/www.johndcook.com\/oblique1.svg\" alt=\"A \\approx \\frac{3a}{b + 2c}\" width=\"87\" height=\"40\" \/><\/p>\n<p>in radians. The previous post worked in degrees, but here we&#8217;ll use radians.<\/p>\n<p>If the triangle is oblique rather than a right triangle, there an approximation for the angle <em>A<\/em> that doesn&#8217;t require inverse trig functions, though it does require square roots. The approximation is derived in [1] using the same series that is the basis of the approximation in the earlier post, the power series for 2 csc(<em>x<\/em>) + cot(<em>x<\/em>).<\/p>\n<p>For an oblique triangle, the approximation is<img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" style=\"background-color: white;\" src=\"https:\/\/www.johndcook.com\/oblique2.svg\" alt=\"A \\approx \\frac{6 \\sqrt{(s - b)(s - c)}}{2\\sqrt{bc} + \\sqrt{s(s-a)}}\" width=\"179\" height=\"57\" \/><\/p>\n<p>where\u00a0<em>s<\/em> is the semiperimeter.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" style=\"background-color: white;\" src=\"https:\/\/www.johndcook.com\/oblique3.svg\" alt=\"s = \\frac{a + b + c}{2}\" width=\"101\" height=\"41\" \/><\/p>\n<p>For comparison, we can find the exact value of <em>A<\/em> using the law of cosines.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" style=\"background-color: white;\" src=\"https:\/\/www.johndcook.com\/oblique4.svg\" alt=\"a^2 = b^2 + c^2 - 2 bc \\cos A\" width=\"191\" height=\"18\" \/><\/p>\n<p>and so<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" style=\"background-color: white;\" src=\"https:\/\/www.johndcook.com\/oblique5.svg\" alt=\"A = \\cos^{-1}\\left(\\frac{b^2 + c^2 - a^2}{2bc}\\right)\" width=\"199\" height=\"49\" \/><\/p>\n<p>Here&#8217;s a little Python script to see how accurate the approximation is.<\/p>\n<pre>from math import sqrt, acos\r\n\r\ndef approx(a, b, c):\r\n    \"approximate the angle opposite a\"\r\n    s = (a + b + c)\/2\r\n    return 6*sqrt((s - b)*(s - c)) \/ (2*sqrt(b*c) + sqrt(s*(s - a)))\r\n\r\ndef exact(a, b, c):\r\n    \"exact value of the angle opposite a\"    \r\n    return acos((b**2 + c**2 - a**2)\/(2*b*c))\r\n\r\na, b, c = 6, 7, 12\r\nprint( approx(a, b, c) )\r\nprint( exact(a, b, c) )\r\n<\/pre>\n<p>This prints<\/p>\n<pre>0.36387538476776243\r\n0.36387760856668505\r\n<\/pre>\n<p>showing that in our example the approximation is good to five decimal places.<\/p>\n<p>[1] H. E. Stelson. Note on the approximate solution of an oblique triangle without tables. American Mathematical Monthly. Vol 56, No. 2 (February, 1949), pp. 84\u201395.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The previous post gave a simple and accurate approximation for the smaller angle of a right triangle. Given a\u00a0right triangle with sides a,\u00a0b, and\u00a0c, where\u00a0a is the shortest side and\u00a0c is the hypotenuse, the angle opposite side a is approximately in radians. The previous post worked in degrees, but here we&#8217;ll use radians. If the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[9],"tags":[],"class_list":["post-246984","post","type-post","status-publish","format-standard","hentry","category-math"],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/246984","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/comments?post=246984"}],"version-history":[{"count":0,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/246984\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/media?parent=246984"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/categories?post=246984"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/tags?post=246984"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}},{"id":246983,"date":"2026-04-23T07:13:35","date_gmt":"2026-04-23T12:13:35","guid":{"rendered":"https:\/\/www.johndcook.com\/blog\/?p=246983"},"modified":"2026-04-23T11:26:29","modified_gmt":"2026-04-23T16:26:29","slug":"solve-a-right-triangle","status":"publish","type":"post","link":"https:\/\/www.johndcook.com\/blog\/2026\/04\/23\/solve-a-right-triangle\/","title":{"rendered":"Simple approximation for solving a right triangle"},"content":{"rendered":"<p>Suppose you have a right triangle with sides\u00a0<em>a<\/em>,\u00a0<em>b<\/em>, and\u00a0<em>c<\/em>, where\u00a0<em>a<\/em> is the shortest side and\u00a0<em>c<\/em> is the hypotenuse. Then the following approximation from [1] for the angle <em>A<\/em>\u00a0opposite side <em>a<\/em> seems too simple and too accurate to be true. In degrees,<\/p>\n<p style=\"padding-left: 40px;\"><em>A<\/em> \u2248 <em>a<\/em> 172\u00b0 \/ (<em>b<\/em> + 2<em>c<\/em>).<\/p>\n<p>The approximation above only involves simple arithmetic. No trig functions. Not even a square root. It could be carried out with pencil and paper or even mentally. And yet it is surprisingly accurate.<\/p>\n<p>If we use the 3, 4, 5 triangle as an example, the exact value of the smallest angle is<\/p>\n<p style=\"padding-left: 40px;\"><em>A<\/em> = arctan(3\/4) \u00d7 180\u00b0\/\u03c0 \u2248 36.8699\u00b0<\/p>\n<p>and the approximate value is<\/p>\n<p style=\"padding-left: 40px;\"><em>A<\/em> \u2248\u00a0 3 \u00d7 172\u00b0 \/ (4 + 2\u00d75) = 258\u00b0\/7 \u2248 36.8571\u00b0,<\/p>\n<p>a difference of 0.0128\u00b0. When the angle is more acute the approximation is even better.<\/p>\n<h2>Derivation<\/h2>\n<p>Where does this magical approximation come from? It boils down to the series<\/p>\n<p style=\"padding-left: 40px;\">2 csc(<em>x<\/em>) + cot(<em>x<\/em>) = 3\/<em>x<\/em> +\u00a0<em>x<\/em>\u00b3\/60 +\u00a0<em>O<\/em>(<em>x<\/em><sup>4<\/sup>)<\/p>\n<p>where <em>x<\/em> is in radians. When <em>x<\/em> is small, \u00a0<em>x<\/em>\u00b3\/60 is extremely small and so we have<\/p>\n<p style=\"padding-left: 40px;\">2 csc(<em>x<\/em>) + cot(<em>x<\/em>) \u2248 3\/<em>x.<\/em><\/p>\n<p>Apply this approximation with csc(<em>x<\/em>) =\u00a0<em>c<\/em>\/<em>a<\/em> and cot(<em>x<\/em>) =\u00a0<em>b<\/em>\/<em>a<\/em>. and you have<\/p>\n<p style=\"padding-left: 40px;\"><em>x<\/em> \u2248 3<em>a<\/em>\/(<em>b<\/em> + 2<em>c<\/em>)<\/p>\n<p>in radians. Multiply by 180\u00b0\/\u03c0 to convert to degrees, and note that 540\/\u03c0 \u2248 172.<\/p>\n<h2>Discovery<\/h2>\n<p>It&#8217;s unmotivated to say &#8220;just expand 2 csc(<em>x<\/em>) + cot(<em>x<\/em>) in a series.&#8221; Where did\u00a0<em>that<\/em> come from?<\/p>\n<p>There&#8217;s a line in [1] that says &#8220;It can been seen, either from tables or from a consideration of power series that the radian measure of a small angle lies approximately one-third of the way from the sine to the tangent.&#8221; In other words<\/p>\n<p style=\"padding-left: 40px;\">3<em>x<\/em> \u2248 2 sin(<em>x<\/em>) + tan(<em>x<\/em>)<em>.<\/em><\/p>\n<p>You can verify that by adding the power series and noting that the cubic terms cancel out.<\/p>\n<p>But that&#8217;s just the beginning. The author then makes the leap to conjecturing that if the weighted <em>arithmetic<\/em> mean gives a good approximation, maybe the weighted\u00a0<em>harmonic<\/em> mean gives an even better approximation, and that leads to considering<\/p>\n<p style=\"padding-left: 40px;\">2 csc(<em>x<\/em>) + cot(<em>x<\/em>) \u2248 3\/<em>x.<\/em><\/p>\n<h2>Extension<\/h2>\n<p>See the <a href=\"https:\/\/www.johndcook.com\/blog\/2026\/04\/23\/solve-an-oblique-triangle\/\">next post<\/a> for an extension to oblique triangles. Not as simple, but based on the same trick.<\/p>\n<p>&nbsp;<\/p>\n<p>[1] J. S. Frame. Solving a right triangle without tables. The American Mathematical Monthly, Vol. 50, No. 10 (Dec., 1943), pp. 622-626<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Suppose you have a right triangle with sides\u00a0a,\u00a0b, and\u00a0c, where\u00a0a is the shortest side and\u00a0c is the hypotenuse. Then the following approximation from [1] for the angle A\u00a0opposite side a seems too simple and too accurate to be true. In degrees, A \u2248 a 172\u00b0 \/ (b + 2c). The approximation above only involves simple [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[9],"tags":[],"class_list":["post-246983","post","type-post","status-publish","format-standard","hentry","category-math"],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/246983","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/comments?post=246983"}],"version-history":[{"count":0,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/posts\/246983\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/media?parent=246983"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/categories?post=246983"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.johndcook.com\/blog\/wp-json\/wp\/v2\/tags?post=246983"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}]