{"id":1110,"date":"2014-11-03T12:00:01","date_gmt":"2014-11-03T17:00:01","guid":{"rendered":"https:\/\/blogs.mathworks.com\/cleve\/?p=1110"},"modified":"2014-10-31T22:21:53","modified_gmt":"2014-11-01T03:21:53","slug":"mathworks-logo-part-three-pde-toolbox","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/cleve\/2014\/11\/03\/mathworks-logo-part-three-pde-toolbox\/","title":{"rendered":"MathWorks Logo, Part Three, PDE Toolbox"},"content":{"rendered":"<div class=\"content\"><!--introduction--><p>The Partial Differential Equation Toolbox contains tools for the analysis of PDEs in two space dimensions and time.  It is perhaps not surprising that one of the primary examples involves the L-shaped membrane.<\/p><!--\/introduction--><h3>Contents<\/h3><div><ul><li><a href=\"#f22f8d6a-2187-4bc4-b8c7-8dbb3594b474\">pdetool<\/a><\/li><li><a href=\"#966ef3b8-b78d-41a2-bc61-38466cd1ed27\">Coarse grid<\/a><\/li><li><a href=\"#a9c7d9dd-608c-494f-bb59-008b238c98a1\">Finer grid<\/a><\/li><li><a href=\"#d974928f-14e0-472f-8377-ebccb626e21f\">Gradient<\/a><\/li><li><a href=\"#230baa8d-1a3a-4ec9-941a-57afa76a7854\">Eigenvalues<\/a><\/li><li><a href=\"#b31498e9-48f7-4a1d-807d-bac0c36c6d9d\">Aitken delta-squared acceleration<\/a><\/li><\/ul><\/div><h4>pdetool<a name=\"f22f8d6a-2187-4bc4-b8c7-8dbb3594b474\"><\/a><\/h4><p>If you have the PDE toolbox installed, bring up <tt>pdetool<\/tt>.  Click on the first triangle in the toolbar.  This initializes a tool for creating a planar domain with an unstructured mesh.  The default domain is our L. The default mesh has equally spaced points on the boundary connected by an irregular grid in the interior with 150 nodes and 258 triangles.<\/p><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/cleve\/pdetool_fig1.png\" alt=\"\"> <\/p><h4>Coarse grid<a name=\"966ef3b8-b78d-41a2-bc61-38466cd1ed27\"><\/a><\/h4><p>The PDE tab allows the specification of a general elliptic operator with variable coefficients, but if we accept the defaults we have our desired Laplacian.  Here is the first eigenfunction, obtained with the coarse grid, plotted with the default <tt>cool<\/tt> colormap.  The first eigenvalue, reported in the title, is 9.9707.<\/p><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/cleve\/pdetool_fig2.png\" alt=\"\"> <\/p><h4>Finer grid<a name=\"a9c7d9dd-608c-494f-bb59-008b238c98a1\"><\/a><\/h4><p>Refine the grid three times to one with 8417 nodes and 16512 triangles, change to our new <tt>parula<\/tt> colormap, and add contour lines. The reported eigenvalue is 9.6525.<\/p><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/cleve\/pdetool_fig3.png\" alt=\"\"> <\/p><h4>Gradient<a name=\"d974928f-14e0-472f-8377-ebccb626e21f\"><\/a><\/h4><p>The <tt>pdetool<\/tt> has an option to plot the absolute value of the gradient. We see that the singularity at the origin acts like a black hole, sucking in all the color.<\/p><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/cleve\/pdetool_fig4.png\" alt=\"\"> <\/p><h4>Eigenvalues<a name=\"230baa8d-1a3a-4ec9-941a-57afa76a7854\"><\/a><\/h4><p>The mesh refinement is accomplished by adding grid points at the midpoints of the triangles, thereby quadrupling the number of triangles. It is possible to do this five times, producing a fine mesh with <tt>258 * 4^5 = 264192<\/tt> triangles.  (Actually the mesh can be refined six times to one with over a million triangles, but the subsequent eigenvalue calculation runs out of memory.)<\/p><p>Here are the results for the first eigenvalue of the L-shaped membrane obtained with successive bisections of the unstructured triangular mesh.<\/p><pre class=\"codeinput\">   format <span class=\"string\">long<\/span>\r\n   load <span class=\"string\">pdetool_results<\/span>\r\n   L\r\n<\/pre><pre class=\"codeoutput\">L =\r\n   9.970747465677787\r\n   9.745769128365856\r\n   9.675647712787020\r\n   9.652453140975609\r\n   9.644395207950412\r\n   9.641482807142362\r\n<\/pre><h4>Aitken delta-squared acceleration<a name=\"b31498e9-48f7-4a1d-807d-bac0c36c6d9d\"><\/a><\/h4><p>These values are candidates for acceleration by <a href=\"http:\/\/en.wikipedia.org\/wiki\/Aitken's_delta-squared_process\">Aitken's delta-squared process<\/a>.<\/p><p>$$ x_n - \\frac {(\\Delta x_n)^2}{\\Delta^2 x_n} $$<\/p><pre class=\"codeinput\">   d1 = diff(L,1);\r\n   L2 = L(3:end) - d1(2:end).^2.\/diff(L,2)\r\n<\/pre><pre class=\"codeoutput\">L2 =\r\n   9.643895738979518\r\n   9.640988739828559\r\n   9.640105597452624\r\n   9.639834371546435\r\n<\/pre><p>We can even use delta-squared a second time, although this is not often justified.<\/p><pre class=\"codeinput\">   t1 = diff(L2,1);\r\n   L2(3:end) - t1(2:end).^2.\/diff(L2,2)\r\n<\/pre><pre class=\"codeoutput\">ans =\r\n   9.639720224107141\r\n   9.639714153353552\r\n<\/pre><p>Compare this with the value I reported in my previous post, obtained by extrapolating from a regular square grid.<\/p><pre class=\"language-matlab\">lambda1 =\r\n   9.639723753239963\r\n<\/pre><p>We will see in my next post a much better way to compute the eigenvalue that will provide a result to nearly full double precision accuracy.<\/p><script language=\"JavaScript\"> <!-- \r\n    function grabCode_6d93ad3448ef443182862a07b61a87ba() {\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='6d93ad3448ef443182862a07b61a87ba ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 6d93ad3448ef443182862a07b61a87ba';\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 2014 The MathWorks, Inc.';\r\n\r\n        w = window.open();\r\n        d = w.document;\r\n        d.write('<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>\\n');\r\n\r\n        d.title = title + ' (MATLAB code)';\r\n        d.close();\r\n    }   \r\n     --> <\/script><p style=\"text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray\"><br><a href=\"javascript:grabCode_6d93ad3448ef443182862a07b61a87ba()\"><span style=\"font-size: x-small;        font-style: italic;\">Get \r\n      the MATLAB code <noscript>(requires JavaScript)<\/noscript><\/span><\/a><br><br>\r\n      Published with MATLAB&reg; R2014b<br><\/p><\/div><!--\r\n6d93ad3448ef443182862a07b61a87ba ##### SOURCE BEGIN #####\r\n%% MathWorks Logo, Part Three, PDE Toolbox\r\n% The Partial Differential Equation Toolbox contains tools for the analysis\r\n% of PDEs in two space dimensions and time.  It is perhaps not surprising\r\n% that one of the primary examples involves the L-shaped membrane.\r\n\r\n%% pdetool\r\n% If you have the PDE toolbox installed, bring up |pdetool|.  Click on the\r\n% first triangle in the toolbar.  This initializes a tool for creating a\r\n% planar domain with an unstructured mesh.  The default domain is our L.\r\n% The default mesh has equally spaced points on the boundary connected by\r\n% an irregular grid in the interior with 150 nodes and 258 triangles.\r\n%\r\n% <<pdetool_fig1.png>>\r\n%\r\n\r\n%% Coarse grid\r\n% The PDE tab allows the specification of a general elliptic operator with\r\n% variable coefficients, but if we accept the defaults we have our desired\r\n% Laplacian.  Here is the first eigenfunction, obtained with the coarse grid,\r\n% plotted with the default |cool| colormap.  The first eigenvalue, reported\r\n% in the title, is 9.9707.\r\n%\r\n% <<pdetool_fig2.png>>\r\n%\r\n\r\n%% Finer grid\r\n% Refine the grid three times to one with 8417 nodes and 16512 triangles,\r\n% change to our new |parula| colormap, and add contour lines.  \r\n% The reported eigenvalue is 9.6525.\r\n%\r\n% <<pdetool_fig3.png>>\r\n%\r\n\r\n%% Gradient\r\n% The |pdetool| has an option to plot the absolute value of the gradient.\r\n% We see that the singularity at the origin acts like a black hole, \r\n% sucking in all the color.\r\n%\r\n% <<pdetool_fig4.png>>\r\n%\r\n\r\n%% Eigenvalues\r\n% The mesh refinement is accomplished by adding grid points at the midpoints\r\n% of the triangles, thereby quadrupling the number of triangles.\r\n% It is possible to do this five times, producing a fine mesh with\r\n% |258 * 4^5 = 264192| triangles.  (Actually the mesh can be refined\r\n% six times to one with over a million triangles, but the subsequent\r\n% eigenvalue calculation runs out of memory.)\r\n\r\n%%\r\n% Here are the results for the first eigenvalue of the L-shaped membrane\r\n% obtained with successive bisections of the unstructured triangular mesh.\r\n\r\n   format long\r\n   load pdetool_results\r\n   L\r\n\r\n%% Aitken delta-squared acceleration\r\n% These values are candidates for acceleration by\r\n% <http:\/\/en.wikipedia.org\/wiki\/Aitken's_delta-squared_process\r\n% Aitken's delta-squared process>.\r\n%\r\n% $$ x_n - \\frac {(\\Delta x_n)^2}{\\Delta^2 x_n} $$ \r\n\r\n   d1 = diff(L,1);\r\n   L2 = L(3:end) - d1(2:end).^2.\/diff(L,2)\r\n\r\n%%\r\n% We can even use delta-squared a second time, although this is not\r\n% often justified.\r\n\r\n   t1 = diff(L2,1);\r\n   L2(3:end) - t1(2:end).^2.\/diff(L2,2)\r\n\r\n%%\r\n% Compare this with the value I reported in my previous post, obtained by\r\n% extrapolating from a regular square grid.\r\n%\r\n%   lambda1 =\r\n%      9.639723753239963\r\n\r\n%%\r\n% We will see in my next post a much better way to compute the eigenvalue\r\n% that will provide a result to nearly full double precision accuracy.\r\n\r\n##### SOURCE END ##### 6d93ad3448ef443182862a07b61a87ba\r\n-->","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"https:\/\/blogs.mathworks.com\/images\/cleve\/pdetool_fig1.png\" onError=\"this.style.display ='none';\" \/><\/div><!--introduction--><p>The Partial Differential Equation Toolbox contains tools for the analysis of PDEs in two space dimensions and time.  It is perhaps not surprising that one of the primary examples involves the L-shaped membrane.... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/cleve\/2014\/11\/03\/mathworks-logo-part-three-pde-toolbox\/\">read more >><\/a><\/p>","protected":false},"author":78,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[24,13,4,25,16],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/posts\/1110"}],"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=1110"}],"version-history":[{"count":5,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/posts\/1110\/revisions"}],"predecessor-version":[{"id":1115,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/posts\/1110\/revisions\/1115"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/media?parent=1110"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/categories?post=1110"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/tags?post=1110"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}