{"id":2326,"date":"2010-02-10T13:43:44","date_gmt":"2010-02-10T12:43:44","guid":{"rendered":"http:\/\/www.walkingrandomly.com\/?p=2326"},"modified":"2011-02-14T18:44:58","modified_gmt":"2011-02-14T17:44:58","slug":"a-little-mathematics-for-valentines-day","status":"publish","type":"post","link":"https:\/\/walkingrandomly.com\/?p=2326","title":{"rendered":"A little mathematics for Valentine&#8217;s day"},"content":{"rendered":"<p>This is not a serious post but then mathematics doesn&#8217;t have to be serious all the time does it?\u00a0 Ever wondered what the equation of a 3D heart looks like?\u00a0 An <a href=\"https:\/\/www.walkingrandomly.com\/?p=59\">old post of mine<\/a> will help you find the answer using Mathematica.\u00a0 Click on the image for more details (and a demonstration that you can run using the free <a href=\"http:\/\/www.wolfram.com\/products\/player\/\">Mathematica player<\/a>).<\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/www.walkingrandomly.com\/?p=59\"><img decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/www.walkingrandomly.com\/images\/mathematica\/heart_demo.jpg\" alt=\"math for yor valentine\" \/><\/a><\/p>\n<p style=\"text-align: left;\">I don&#8217;t save all of my love for Mathematica though.  I&#8217;ve got some for <a href=\"http:\/\/www.mathworks.co.uk\/\">MATLAB<\/a> too:<\/p>\n<pre>%code to plot a heart shape in MATLAB\r\n%set up mesh\r\nn=100;\r\nx=linspace(-3,3,n);\r\ny=linspace(-3,3,n);\r\nz=linspace(-3,3,n);\r\n[X,Y,Z]=ndgrid(x,y,z);\r\n%Compute function at every point in mesh\r\nF=320 * ((-X.^2 .* Z.^3 -9.*Y.^2.*Z.^3\/80) + (X.^2 + 9.* Y.^2\/4 + Z.^2-1).^3);\r\n%generate plot\r\nisosurface(F,0)\r\nview([-67.5 2]);\r\n<\/pre>\n<p style=\"text-align: left;\">Did you know that the equation for a heart (or a <a href=\"http:\/\/en.wikipedia.org\/wiki\/Cardioid\">cardioid<\/a> if you want to get technical) is very similar to the equation for a flower?\u00a0 The <a href=\"http:\/\/en.wikipedia.org\/wiki\/Polar_coordinate_system\">polar equation<\/a> you need is\u00a0 <img decoding=\"async\" src=\"http:\/\/demonstrations.wolfram.com\/ThePolarEquationsOfHeartsAndFlowers\/HTMLImages\/index.en\/1.gif\" alt=\"\" align=\"absmiddle\" \/> and you get a rotated cardioid for n=1.\u00a0 Change n to 6 and you get a flower.\u00a0 Let&#8217;s use the free maths package, <a href=\"http:\/\/www.sagemath.org\/\">SAGE<\/a>, this time.<\/p>\n<p>First, define the function:<\/p>\n<pre>def eqn(x,n):\r\n    return(1-sin(n*x))\r\n<\/pre>\n<p>then plot it for n=1<\/p>\n<pre>polar_plot(eqn(x,1), (x,-pi, pi),aspect_ratio=1,axes=False)\r\n<\/pre>\n<p style=\"text-align: left;\"><img decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/www.walkingrandomly.com\/images\/SAGE\/sage_heart.png\" alt=\"SAGE heart\" \/><br \/>\nand for n=7<\/p>\n<pre>polar_plot(eqn(x,7), (x,-pi, pi),aspect_ratio=1,axes=False)\r\n<\/pre>\n<p style=\"text-align: center;\"><img decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/www.walkingrandomly.com\/images\/SAGE\/sage_flower.png\" alt=\"SAGE heart\" \/><\/p>\n<p style=\"text-align: left;\">Back to Mathematica and the Wolfram Demonstrations project.  We have a<a href=\"https:\/\/www.walkingrandomly.com\/?p=65\"> Valentine&#8217;s version of the traditional Tangram puzzle<\/a>.<\/p>\n<p style=\"text-align: left;\"><a href=\"https:\/\/www.walkingrandomly.com\/?p=65\"><img decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/www.walkingrandomly.com\/images\/games\/heart.gif\" alt=\"Broken Heart Tangram\" \/><\/a><\/p>\n<p style=\"text-align: left;\">Feel free to let me know of any other Valentine&#8217;s math that you discover, <a href=\"http:\/\/en.wikipedia.org\/wiki\/Wittgenstein%27s_rod\">puzzles<\/a>, <a href=\"http:\/\/images.google.co.uk\/images?q=heart+fractal\">fractals<\/a> or <a href=\"http:\/\/www.mathematische-basteleien.de\/heart.htm\">equations<\/a>, it&#8217;s all good :)<\/p>\n<p style=\"text-align: left;\"><strong>Update Feb 14th 2011<\/strong><\/p>\n<p style=\"text-align: left;\">Mariano Beguerisse D\u00edaz sent me some MATLAB code that uses a variation on the standard mandelbrot and I turned it into the movie below.\u00a0 His original code is in the comments section<\/p>\n<p><object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" width=\"480\" height=\"390\" codebase=\"http:\/\/download.macromedia.com\/pub\/shockwave\/cabs\/flash\/swflash.cab#version=6,0,40,0\"><param name=\"allowFullScreen\" value=\"true\" \/><param name=\"allowscriptaccess\" value=\"always\" \/><param name=\"src\" value=\"http:\/\/www.youtube.com\/v\/R8CKF35nosA?fs=1&amp;hl=en_GB\" \/><param name=\"allowfullscreen\" value=\"true\" \/><\/object><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is not a serious post but then mathematics doesn&#8217;t have to be serious all the time does it?\u00a0 Ever wondered what the equation of a 3D heart looks like?\u00a0 An old post of mine will help you find the answer using Mathematica.\u00a0 Click on the image for more details (and a demonstration that you [&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":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[6],"tags":[],"class_list":["post-2326","post","type-post","status-publish","format-standard","hentry","category-general-math"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p3swhs-Bw","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/posts\/2326","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=2326"}],"version-history":[{"count":9,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/posts\/2326\/revisions"}],"predecessor-version":[{"id":3213,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/posts\/2326\/revisions\/3213"}],"wp:attachment":[{"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2326"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2326"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2326"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}