{"id":2680,"date":"2017-09-09T00:01:26","date_gmt":"2017-09-09T07:01:26","guid":{"rendered":"http:\/\/c-for-dummies.com\/blog\/?p=2680"},"modified":"2017-09-02T08:34:46","modified_gmt":"2017-09-02T15:34:46","slug":"ugly-e-math-stuff","status":"publish","type":"post","link":"https:\/\/c-for-dummies.com\/blog\/?p=2680","title":{"rendered":"Ugly <em>e<\/em> Math Stuff"},"content":{"rendered":"<p>I&#8217;m no math genius. I&#8217;d love to understand it all, and I appreciate the complexities, but I&#8217;m just the noob first-time player walking across a field in <em>Call of Duty<\/em> where I&#8217;m a target to all the more experienced players. In short: The study of compound interest eventually gives rise to the mathematical concept of <em>e<\/em>, also known as Euler&#8217;s number.<br \/>\n<!--more--><br \/>\nLike &pi;, <em>e<\/em> is an irrational, transcendental number that has properties so compelling that it would qualify as the centerfold for the math geek&#8217;s version of <em>Playboy<\/em>.<\/p>\n<p>The most important thing I know about <em>e<\/em> is that it&#8217;s often called <em>Euler&#8217;s number<\/em>, after Swiss mathematician Leonhard Euler. And the most important thing about that knowledge tidbit is knowing that &#8220;Euler&#8221; is pronounced &#8220;Oiler.&#8221;<\/p>\n<p><em>e<\/em> is a constant: 2.718282&#8230; It&#8217;s considered the sum of an infinite series, which means that you can keep making specific calculations long enough that the total eeks up to the value of <em>e<\/em>.<\/p>\n<p>This concept plays into the notion of compound interest (covered in <a href=\"http:\/\/c-for-dummies.com\/blog\/?p=2666\">last week&#8217;s Lesson<\/a>), because as you continue to compound and compound, you end up with the value 2.718282&#8230; Centuries ago, mathematicians discovered this effect and they haven&#8217;t shut up about it since.<\/p>\n<p>The following code is a variation on the compound interest calculation presented last week. It&#8217;s a type of infinite series, where values keep getting larger but the result eventually settles on a specific number, <em>e<\/em>:<\/p>\n<pre class=\"screen\">\r\n#include &lt;stdio.h&gt;\r\n#include &lt;math.h&gt;\r\n\r\nint main()\r\n{\r\n    long n;\r\n    float p;\r\n\r\n    for(n=1;n&lt;100000;n+=1000)\r\n    {\r\n        p = pow( ( 1.0 + (1.0\/n) ), n );\r\n        printf(\"%f\\n\",p);\r\n    }\r\n\r\n    return(0);\r\n}<\/pre>\n<p>The function on Line 11 of the code is similar to the compound interest function described in last week&#8217;s Lesson. The term variable <code>t<\/code> is missing (or assumed to be 1) and the rate is set to 1, so it&#8217;s not shown. Figure 1 illustrates how the math geeks write it (two ways).<\/p>\n<div id=\"attachment_2689\" style=\"width: 590px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-2689\" src=\"http:\/\/c-for-dummies.com\/blog\/wp-content\/uploads\/2017\/09\/0909-figure1_e-calculation.png\" alt=\"\" width=\"580\" height=\"160\" class=\"size-full wp-image-2689\" srcset=\"https:\/\/c-for-dummies.com\/blog\/wp-content\/uploads\/2017\/09\/0909-figure1_e-calculation.png 580w, https:\/\/c-for-dummies.com\/blog\/wp-content\/uploads\/2017\/09\/0909-figure1_e-calculation-300x83.png 300w, https:\/\/c-for-dummies.com\/blog\/wp-content\/uploads\/2017\/09\/0909-figure1_e-calculation-500x138.png 500w\" sizes=\"auto, (max-width: 580px) 100vw, 580px\" \/><p id=\"caption-attachment-2689\" class=\"wp-caption-text\">Figure 1. Two different ways that the value of <em>e<\/em> is calculated.<\/p><\/div>\n<p>The output is 100 lines long, and the first few lines jump the value pretty close to <em>e<\/em>:<\/p>\n<pre><code>2.000000\r\n2.716925\r\n2.717603\r\n2.717829<\/code><\/pre>\n<p>As the value of variable <code>n<\/code> increases, the output gets closer:<\/p>\n<pre><code>2.718267\r\n2.718268\r\n2.718268\r\n2.718268\r\n2.718268<\/code><\/pre>\n<p>The C library function <em>log()<\/em> is the natural logarithm, which uses <em>e<\/em> as the base. The concept completely befuddles me, though I&#8217;ve used the <em>log()<\/em> function to realistically animate a bouncing ball. I&#8217;m sure the <em>log()<\/em> function has other uses that would delight the propeller heads.<\/p>\n<p>Mathematically, if you take <em>e<sup>e<\/sup><\/em> you get 15.154262. The natural logarithm of that value is <em>e<\/em>, which the following code proves:<\/p>\n<pre class=\"screen\">\r\n#include &lt;stdio.h&gt;\r\n#include &lt;math.h&gt;\r\n\r\nint main()\r\n{\r\n    printf(\"e = %f\\n\",log(15.154262));\r\n\r\n    return(0);\r\n}<\/pre>\n<p>The <em>log()<\/em> function requires the <code>math.h<\/code> header file, included at Line 2. Here&#8217;s the output:<\/p>\n<pre><code>e = 2.718282<\/code><\/pre>\n<p>And that&#8217;s as far as I dare tread over the deep waters of mathematics.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Coming off the topic of compound interest is the fascinating mathematical constant, <em>e<\/em>. <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=2680\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-2680","post","type-post","status-publish","format-standard","hentry","category-main"],"_links":{"self":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2680","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2680"}],"version-history":[{"count":5,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2680\/revisions"}],"predecessor-version":[{"id":2699,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2680\/revisions\/2699"}],"wp:attachment":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2680"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2680"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2680"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}