{"id":455,"date":"2008-12-15T17:20:53","date_gmt":"2008-12-15T16:20:53","guid":{"rendered":"http:\/\/www.walkingrandomly.com\/?p=455"},"modified":"2008-12-15T17:20:53","modified_gmt":"2008-12-15T16:20:53","slug":"a-little-love-for-matlab-plotting-algebraic-surfaces","status":"publish","type":"post","link":"https:\/\/walkingrandomly.com\/?p=455","title":{"rendered":"A little love for MATLAB &#8211; plotting algebraic surfaces"},"content":{"rendered":"<p>Back in February <a href=\"https:\/\/www.walkingrandomly.com\/?p=59\">I blogged about<\/a> a little Mathematica demonstration I wrote which plotted several heart shaped algebraic surfaces. One or two people wrote in the comments section asking how to do such plots in MATLAB and I thought that it was about time I came up with the code.<br \/>\n<code><br \/>\n%code to plot a heart shape in MATLAB<br \/>\n%set up mesh<br \/>\nn=100;<br \/>\nx=linspace(-3,3,n);<br \/>\ny=linspace(-3,3,n);<br \/>\nz=linspace(-3,3,n);<br \/>\n[X,Y,Z]=ndgrid(x,y,z);<br \/>\n%Compute function at every point in mesh<br \/>\nF=320 * ((-X.^2 .* Z.^3 -9.*Y.^2.*Z.^3\/80) + (X.^2 + 9.* Y.^2\/4 + Z.^2-1).^3);<br \/>\n%generate plot<br \/>\nisosurface(F,0)<br \/>\nview([-67.5 2]);<br \/>\n<\/code><\/p>\n<p>It&#8217;s not really the right time of year for hearts though is it?  So let&#8217;s plot a star instead.<\/p>\n<p style=\"text-align: center;\"><img decoding=\"async\" class=\"aligncenter\" src=\"\/images\/matlab\/star.jpg\" alt=\"MATLAB star\" \/><\/p>\n<p><code><br \/>\n%Code to plot a 3D star in MATLAB<br \/>\n%set up mesh<br \/>\nn=200;<br \/>\nx=linspace(-2,2,n);<br \/>\ny=linspace(-2,2,n);<br \/>\nz=linspace(-2,2,n);<br \/>\n[X,Y,Z]=ndgrid(x,y,z);<br \/>\n%Compute function at every point in mesh<br \/>\nF=X.^2+Y.^2+Z.^2+1000*(X.^2+Y.^2).*(X.^2+Z.^2).*(Y.^2+Z.^2);<br \/>\n%generate plot<br \/>\nisosurface(F,1);<br \/>\naxis off;<br \/>\nview([-48 18]);<br \/>\n<\/code><\/p>\n<p>For more examples of algebraic surfaces see the <a href=\"http:\/\/www.freigeist.cc\/gallery.html\">Algebraic Surfaces Gallery<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Back in February I blogged about a little Mathematica demonstration I wrote which plotted several heart shaped algebraic surfaces. One or two people wrote in the comments section asking how to do such plots in MATLAB and I thought that it was about time I came up with the code. %code to plot a heart [&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":[11],"tags":[],"class_list":["post-455","post","type-post","status-publish","format-standard","hentry","category-matlab"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p3swhs-7l","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/posts\/455","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=455"}],"version-history":[{"count":6,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/posts\/455\/revisions"}],"predecessor-version":[{"id":461,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/posts\/455\/revisions\/461"}],"wp:attachment":[{"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=455"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=455"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=455"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}