{"id":5795,"date":"2015-07-13T11:29:37","date_gmt":"2015-07-13T10:29:37","guid":{"rendered":"http:\/\/www.walkingrandomly.com\/?p=5795"},"modified":"2015-07-13T11:29:37","modified_gmt":"2015-07-13T10:29:37","slug":"interactive-explorations-with-maple-an-introduction-to-the-explore-function-using-the-power-series-for-sinx","status":"publish","type":"post","link":"https:\/\/walkingrandomly.com\/?p=5795","title":{"rendered":"Interactive explorations with Maple: An introduction to the Explore function using the power series for sin(x)"},"content":{"rendered":"<p>It is possible to write quick, interactive demonstrations in a variety of languages these days. Functions such as Mathematica&#8217;s <a href=\"https:\/\/reference.wolfram.com\/language\/ref\/Manipulate.html\">Manipulate<\/a>, <a href=\"http:\/\/wiki.sagemath.org\/interact\/\">Sage Math&#8217;s interact<\/a>\u00a0and <a href=\"https:\/\/ipython.org\/ipython-doc\/dev\/api\/generated\/IPython.html.widgets.interaction.html\">IPython&#8217;s interact<\/a> allow programmers to write functional graphical user interfaces with just a few lines of code.<\/p>\n<p>Earlier this week, I hosted a session in the <a href=\"http:\/\/sheffield.ac.uk\/faculty\/engineering\/index\">Faculty of Engineering<\/a> at\u00a0<a href=\"http:\/\/www.sheffield.ac.uk\/\">The University of Sheffield<\/a>\u00a0where <a href=\"http:\/\/www.maplesoft.com\/\">Maplesoft<\/a> showed us, among other things, their version of this technology. This blog post is an extension of my notes from this part of the session.<\/p>\n<ul>\n<li><span style=\"line-height: 13px;\">The Maple Worksheet for this blog post is <a href=\"https:\/\/github.com\/mikecroucher\/WalkingRandomly\/tree\/master\/Maple\">available on github<\/a>.<\/span><\/li>\n<\/ul>\n<p>The series command expands a function as a power series around a point. For example, let&#8217;s expand sin(x) as a power series around the point x=0.<\/p>\n<pre>series(sin(x), x = 0, 10)<\/pre>\n<p><a href=\"https:\/\/www.walkingrandomly.com\/wp-content\/uploads\/2015\/07\/Screen-Shot-2015-07-01-at-14.05.52.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone  wp-image-5798\" alt=\"Screen Shot 2015-07-01 at 14.05.52\" src=\"https:\/\/www.walkingrandomly.com\/wp-content\/uploads\/2015\/07\/Screen-Shot-2015-07-01-at-14.05.52.png\" width=\"583\" height=\"56\" srcset=\"https:\/\/walkingrandomly.com\/wp-content\/uploads\/2015\/07\/Screen-Shot-2015-07-01-at-14.05.52.png 972w, https:\/\/walkingrandomly.com\/wp-content\/uploads\/2015\/07\/Screen-Shot-2015-07-01-at-14.05.52-300x29.png 300w\" sizes=\"auto, (max-width: 583px) 100vw, 583px\" \/><\/a><br \/>\nIf we try to plot this, we get an error message<\/p>\n<pre>plot(series(sin(x), x = 0, 10), x = -2*Pi .. 2*Pi, y = -3 .. 3)\r\n\r\nWarning, unable to evaluate the function to numeric values in the region; see the plotting command's help page to ensure the calling sequence is correct<\/pre>\n<p>This is because the output of the series command is a series data structure &#8212; something that the plot function cannot handle. We can, however, convert this to a polynomial which is something that the plot function can handle<\/p>\n<pre>convert(series(sin(x), x = 0, 10), polynom)<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone  wp-image-5801\" style=\"font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-size: 13px; line-height: 19px;\" alt=\"screenshot_2_wed_1stjuly\" src=\"https:\/\/www.walkingrandomly.com\/wp-content\/uploads\/2015\/07\/screenshot_2_wed_1stjuly.png\" width=\"527\" height=\"50\" srcset=\"https:\/\/walkingrandomly.com\/wp-content\/uploads\/2015\/07\/screenshot_2_wed_1stjuly.png 878w, https:\/\/walkingrandomly.com\/wp-content\/uploads\/2015\/07\/screenshot_2_wed_1stjuly-300x28.png 300w\" sizes=\"auto, (max-width: 527px) 100vw, 527px\" \/><br \/>\nWrapping the above with plot gives:<\/p>\n<pre>plot(convert(series(sin(x), x = 0, 10), polynom), x = -2*Pi .. 2*Pi, y = -3 .. 3);<\/pre>\n<p><a href=\"https:\/\/www.walkingrandomly.com\/wp-content\/uploads\/2015\/07\/Screen-Shot-2015-07-08-at-08.33.03.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-5807\" alt=\"Screen Shot 2015-07-08 at 08.33.03\" src=\"https:\/\/www.walkingrandomly.com\/wp-content\/uploads\/2015\/07\/Screen-Shot-2015-07-08-at-08.33.03-300x237.png\" width=\"300\" height=\"237\" srcset=\"https:\/\/walkingrandomly.com\/wp-content\/uploads\/2015\/07\/Screen-Shot-2015-07-08-at-08.33.03-300x237.png 300w, https:\/\/walkingrandomly.com\/wp-content\/uploads\/2015\/07\/Screen-Shot-2015-07-08-at-08.33.03.png 996w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><br \/>\nLet&#8217;s see how close this is to the sin(x) curve by plotting them both together<\/p>\n<pre>plot([sin(x), convert(series(sin(x), x = 0, 10), polynom)], x = -2*Pi .. 2*Pi, y = -3 .. 3);<\/pre>\n<p><a href=\"https:\/\/www.walkingrandomly.com\/wp-content\/uploads\/2015\/07\/Screen-Shot-2015-07-08-at-08.37.56.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-5808\" alt=\"Screen Shot 2015-07-08 at 08.37.56\" src=\"https:\/\/www.walkingrandomly.com\/wp-content\/uploads\/2015\/07\/Screen-Shot-2015-07-08-at-08.37.56-300x272.png\" width=\"300\" height=\"272\" srcset=\"https:\/\/walkingrandomly.com\/wp-content\/uploads\/2015\/07\/Screen-Shot-2015-07-08-at-08.37.56-300x272.png 300w, https:\/\/walkingrandomly.com\/wp-content\/uploads\/2015\/07\/Screen-Shot-2015-07-08-at-08.37.56.png 862w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><br \/>\nIt would be nice if we could see how the approximation varies as we vary the number of terms in the expansion. Change the value 10 to a parameter a, pass the whole thing to the Explore function and we get an interactive widget.<\/p>\n<pre>Explore(plot([sin(x), convert(series(sin(x), x = 0, a), polynom)], x = -2*Pi .. 2*Pi, y = -3 .. 3), parameters = [a = 2 .. 20]);<\/pre>\n<p>Here&#8217;s a screenshot of it:<\/p>\n<p><a href=\"https:\/\/www.walkingrandomly.com\/wp-content\/uploads\/2015\/07\/Screen-Shot-2015-07-08-at-08.42.49.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-5809\" alt=\"Screen Shot 2015-07-08 at 08.42.49\" src=\"https:\/\/www.walkingrandomly.com\/wp-content\/uploads\/2015\/07\/Screen-Shot-2015-07-08-at-08.42.49-270x300.png\" width=\"270\" height=\"300\" srcset=\"https:\/\/walkingrandomly.com\/wp-content\/uploads\/2015\/07\/Screen-Shot-2015-07-08-at-08.42.49-270x300.png 270w, https:\/\/walkingrandomly.com\/wp-content\/uploads\/2015\/07\/Screen-Shot-2015-07-08-at-08.42.49.png 910w\" sizes=\"auto, (max-width: 270px) 100vw, 270px\" \/><\/a><br \/>\n<strong>Adding extra parameters<\/strong><br \/>\nIt would also be nice to vary the point we expand around. Change the value 0 to b and add an extra parameter to Explore to get two sliders instead of one:<\/p>\n<pre>Explore(plot([sin(x), convert(series(sin(x), x = b, a), polynom)], x = -2*Pi .. 2*Pi, y = -3 .. 3), parameters = [a = 2 .. 20, b = -2*Pi .. 2*Pi]);<\/pre>\n<p>To see what this looks like, open <a href=\"https:\/\/github.com\/mikecroucher\/WalkingRandomly\/tree\/master\/Maple\">the companion worksheet<\/a> in Maple.<\/p>\n<p><strong>Adding labels to the sliders<\/strong><br \/>\nWe can change the labels on the sliders as follows<\/p>\n<pre>Explore(plot([sin(x), convert(series(sin(x), x = b, a), polynom)], x = -2*Pi .. 2*Pi, y = -3 .. 3), parameters = [[a = 2 .. 20, label = `Number Of Terms`], [b = -2*Pi .. 2*Pi, label = `Expansion location`]]);<\/pre>\n<p>To see what this looks like, open\u00a0<a href=\"https:\/\/github.com\/mikecroucher\/WalkingRandomly\/tree\/master\/Maple\">the companion worksheet<\/a>\u00a0in Maple.<\/p>\n<p><strong>Adding initial values<\/strong><br \/>\nFinally, let&#8217;s set some starting values for each slider<\/p>\n<pre>Explore(plot([sin(x), convert(series(sin(x), x = b, a), polynom)], x = -2*Pi .. 2*Pi, y = -3 .. 3), parameters = [[a = 2 .. 20, label = `Number Of Terms`], [b = -2*Pi .. 2*Pi, label = `Expansion location`]], initialvalues = [a = 2, b = 1]);<\/pre>\n<p>The resulting interactive widget looks like this:<\/p>\n<p><a href=\"https:\/\/www.walkingrandomly.com\/wp-content\/uploads\/2015\/07\/Screen-Shot-2015-07-08-at-08.53.35.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-5812\" alt=\"Screen Shot 2015-07-08 at 08.53.35\" src=\"https:\/\/www.walkingrandomly.com\/wp-content\/uploads\/2015\/07\/Screen-Shot-2015-07-08-at-08.53.35-280x300.png\" width=\"280\" height=\"300\" srcset=\"https:\/\/walkingrandomly.com\/wp-content\/uploads\/2015\/07\/Screen-Shot-2015-07-08-at-08.53.35-280x300.png 280w, https:\/\/walkingrandomly.com\/wp-content\/uploads\/2015\/07\/Screen-Shot-2015-07-08-at-08.53.35-956x1024.png 956w, https:\/\/walkingrandomly.com\/wp-content\/uploads\/2015\/07\/Screen-Shot-2015-07-08-at-08.53.35.png 1070w\" sizes=\"auto, (max-width: 280px) 100vw, 280px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>Not bad for one line of code!<\/p>\n<p><strong>Upload to the Maple Cloud<\/strong><\/p>\n<p>At The University of Sheffield, we are lucky because all of our staff and students have access to Maple on both university-owned and personally-owned equipment. If your audience isn&#8217;t as fortunate, they can access the resulting <a href=\"http:\/\/maplecloud.maplesoft.com\/application.jsp?appId=5756111248424960\">worksheet on the Maple Cloud<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>It is possible to write quick, interactive demonstrations in a variety of languages these days. Functions such as Mathematica&#8217;s Manipulate, Sage Math&#8217;s interact\u00a0and IPython&#8217;s interact allow programmers to write functional graphical user interfaces with just a few lines of code. Earlier this week, I hosted a session in the Faculty of Engineering at\u00a0The University of [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[25,4,7,42],"tags":[],"class_list":["post-5795","post","type-post","status-publish","format-standard","hentry","category-maple","category-math-software","category-programming","category-tutorials"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p3swhs-1vt","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/posts\/5795","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5795"}],"version-history":[{"count":16,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/posts\/5795\/revisions"}],"predecessor-version":[{"id":5824,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/posts\/5795\/revisions\/5824"}],"wp:attachment":[{"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5795"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5795"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5795"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}