{"id":1234,"date":"2015-07-27T12:00:07","date_gmt":"2015-07-27T17:00:07","guid":{"rendered":"https:\/\/blogs.mathworks.com\/cleve\/?p=1234"},"modified":"2016-12-05T14:05:28","modified_gmt":"2016-12-05T19:05:28","slug":"discover-e-with-a-graphical-experiment","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/cleve\/2015\/07\/27\/discover-e-with-a-graphical-experiment\/","title":{"rendered":"Discover e with a graphical experiment"},"content":{"rendered":"<div class=\"content\"><!--introduction-->An interactive graphical experiment lets you discover the value of one of the most important numerical quantities in mathematics.\r\n\r\n<!--\/introduction-->\r\n<h3>Contents<\/h3>\r\n<div>\r\n<ul>\r\n \t<li><a href=\"#c5046856-24ff-465b-a32c-c86ce3d47d69\">One of My Favorites<\/a><\/li>\r\n \t<li><a href=\"#0a4fe93a-46f4-43ab-b209-9b39ae281b29\">Approximate derivative<\/a><\/li>\r\n \t<li><a href=\"#4466c39e-e918-41e8-a262-933abf6fafe5\">Derivative of $2^t$ is below<\/a><\/li>\r\n \t<li><a href=\"#0df844f1-285b-44f9-ab0d-27ee74f03370\">Derivative of $3^t$ is above<\/a><\/li>\r\n \t<li><a href=\"#6b3f75d0-de99-47e4-a713-167cd165ebd3\">Action<\/a><\/li>\r\n<\/ul>\r\n<\/div>\r\n<h4>One of My Favorites<a name=\"c5046856-24ff-465b-a32c-c86ce3d47d69\"><\/a><\/h4>\r\nOne of my favorite graphical experiments allows you to find the numerical value of $e$. The program is described in Chapter 8 of <a href=\"https:\/\/www.mathworks.com\/content\/dam\/mathworks\/mathworks-dot-com\/moler\/exm\/chapters\/exponential.pdf\">Experiments with MATLAB<\/a> and is included in the toolbox available with that book. It was originally called <tt>expgui<\/tt>; today it is known as <tt>expshow<\/tt>. <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/37977-experiments-with-matlab-experiments-with-matlab\/content\/exm_2014\/expshow.m\">Here is a link<\/a> to the code. I hope you are able to start up MATLAB and actually run <tt>expshow<\/tt> while you are reading this blog.\r\n<h4>Approximate derivative<a name=\"0a4fe93a-46f4-43ab-b209-9b39ae281b29\"><\/a><\/h4>\r\nLet's say you've forgotten how to find the derivative of $a^t$ with respect to $t$. Be careful. Don't blindly follow your memory that the derivative of $t^n$ is $n t^{n-1}$ and claim that the derivative of $a^t$ is $t a^{t-1}$.\r\n\r\nFor graphical purposes, we can use an approximate derivative, replacing the tangent by a secant with a step size of $10^{-4}$. Here is the core of <tt>expshow<\/tt> and the resulting screen shot with $a = 2$\r\n<pre class=\"codeinput\">   t = 0:1\/64:2;\r\n   h = .0001;\r\n   <span class=\"comment\">% Compute y = a^t and its approximate derivative.<\/span>\r\n   y = a.^t;\r\n   yp = (a.^(t+h) - a.^t)\/h;\r\n<\/pre>\r\n<img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/cleve\/expshow2t.gif\" alt=\"\" hspace=\"5\" vspace=\"5\" \/>\r\n<h4>Derivative of $2^t$ is below<a name=\"4466c39e-e918-41e8-a262-933abf6fafe5\"><\/a><\/h4>\r\nThe blue line is the graph of $2^t$. At $t = 1$ it passes through $y = 2$ and at $t = 2$ it hits $y = 4$. The sienna line is the graph of the derivative of $2^t$. The important facts are that it has the same shape as the blue line and lies entirely below it.\r\n<h4>Derivative of $3^t$ is above<a name=\"0df844f1-285b-44f9-ab0d-27ee74f03370\"><\/a><\/h4>\r\nNow take your mouse and move the blue line. It's very satisfying to be actually interact with this experiment. Push the blue line until the sienna line moves above it, to somewhere around $a = 3$.\r\n\r\n<img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/cleve\/expshow3t.gif\" alt=\"\" hspace=\"5\" vspace=\"5\" \/>\r\n\r\nWith $a = 3$, at $t = 1$ the graph passes through $y = 3$ and at $t = 2$ it hits $y = 9$. The sienna line is now the graph of the derivative of $3^t$. The important facts are that it still has the same shape as the blue line and now lies entirely above it.\r\n<h4>Action<a name=\"6b3f75d0-de99-47e4-a713-167cd165ebd3\"><\/a><\/h4>\r\nNow you know what to do.\r\n\r\n<img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/cleve\/expshow.gif\" alt=\"\" hspace=\"5\" vspace=\"5\" \/>\r\n\r\nUsing the mouse, move the blue line until the two lines lie on top of each other. You have found the only function in the world that is equal to its own derivative and, in the process, discovered that, to three decimal places, the crucial value of the base is 2.718. And you did this without touching the keyboard or typing in any numbers.\r\n\r\n<script>\/\/ <![CDATA[\r\nfunction grabCode_8eca2a4c00e747ac8252e464377862ac() {\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='8eca2a4c00e747ac8252e464377862ac ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 8eca2a4c00e747ac8252e464377862ac';\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 2015 The MathWorks, Inc.';\r\n\r\n        w = window.open();\r\n        d = w.document;\r\n        d.write('\r\n\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\r\n\r\n\\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;\">\r\n<a><span style=\"font-size: x-small; font-style: italic;\">Get\r\nthe MATLAB code<noscript>(requires JavaScript)<\/noscript><\/span><\/a>\r\n\r\nPublished with MATLAB\u00ae R2015a<\/p>\r\n\r\n<\/div>\r\n<!--\r\n8eca2a4c00e747ac8252e464377862ac ##### SOURCE BEGIN #####\r\n%% Discover e with a graphical experiment\r\n% An interactive graphical experiment lets you discover the value of\r\n% one of the most important numerical quantities in mathematics.\r\n\r\n%% One of My Favorites\r\n% One of my favorite graphical experiments allows you to find the numerical\r\n% value of $e$.  The program is described in Chapter 8 of\r\n% <https:\/\/www.mathworks.com\/moler\/exm\/chapters\/exponential.pdf % Experiments with MATLAB> and is included in the toolbox available with\r\n% that book.  It was originally called |expgui|;\r\n% today it is known as |expshow|.\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/37977-experiments-with-matlab-experiments-with-matlab\/content\/exm_2014\/expshow.m % Here is a link> to the code.\r\n% I hope you are able to start up MATLAB and actually run |expshow| while\r\n% you are reading this blog.\r\n\r\n%% Approximate derivative\r\n% Let's say you've forgotten how to find the derivative of $a^t$ with respect\r\n% to $t$.  Be careful.  Don't blindly follow your memory that the derivative\r\n% of $t^n$ is $n t^{n-1}$ and claim that the derivative of $a^t$ is\r\n% $t a^{t-1}$.\r\n\r\n%%\r\n% For graphical purposes, we can use an approximate derivative, replacing the\r\n% tangent by a secant with a step size of $10^{-4}$.  Here is the core of\r\n% |expshow| and the resulting screen shot with $a = 2$\r\n\r\nt = 0:1\/64:2;\r\nh = .0001;\r\n% Compute y = a^t and its approximate derivative.\r\ny = a.^t;\r\nyp = (a.^(t+h) - a.^t)\/h;\r\n\r\n%%\r\n%\r\n% <<expshow2t.gif>>\r\n%\r\n\r\n%% Derivative of $2^t$ is below\r\n% The blue line is the graph of $2^t$.  At $t = 1$ it passes through $y = 2$\r\n% and at $t = 2$ it hits $y = 4$.  The sienna line is the graph of the\r\n% derivative of $2^t$.  The important facts are that it has the same shape as\r\n% the blue line and lies entirely below it.\r\n\r\n%% Derivative of $3^t$ is above\r\n% Now take your mouse and move the blue line.  It's very satisfying to be\r\n% actually interact with this experiment.  Push the blue line until the\r\n% sienna line moves above it, to somewhere around $a = 3$.\r\n%\r\n% <<expshow3t.gif>>\r\n%\r\n% With $a = 3$, at $t = 1$ the graph passes through $y = 3$\r\n% and at $t = 2$ it hits $y = 9$.  The sienna line is now the graph of the\r\n% derivative of $3^t$.  The important facts are that it still has the same\r\n% shape as the blue line and now lies entirely above it.\r\n\r\n%% Action\r\n% Now you know what to do.\r\n%\r\n% <<expshow.gif>>\r\n%\r\n% Using the mouse, move the blue line until the two lines lie on top of each\r\n% other.  You have found the only function in the world that is equal to its\r\n% own derivative and, in the process, discovered that, to three decimal places,\r\n% the crucial value of the base is 2.718.  And you did this without touching\r\n% the keyboard or typing in any numbers.\r\n\r\n##### SOURCE END ##### 8eca2a4c00e747ac8252e464377862ac\r\n-->","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"https:\/\/blogs.mathworks.com\/images\/cleve\/expshow2t.gif\" onError=\"this.style.display ='none';\" \/><\/div><!--introduction-->An interactive graphical experiment lets you discover the value of one of the most important numerical quantities in mathematics.\r\n\r\n<!--\/introduction-->... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/cleve\/2015\/07\/27\/discover-e-with-a-graphical-experiment\/\">read more >><\/a><\/p>","protected":false},"author":78,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[12,24,5],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/posts\/1234"}],"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=1234"}],"version-history":[{"count":2,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/posts\/1234\/revisions"}],"predecessor-version":[{"id":2191,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/posts\/1234\/revisions\/2191"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/media?parent=1234"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/categories?post=1234"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/tags?post=1234"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}