{"id":845,"date":"2014-02-12T10:06:44","date_gmt":"2014-02-12T15:06:44","guid":{"rendered":"https:\/\/blogs.mathworks.com\/loren\/?p=845"},"modified":"2014-01-20T16:07:28","modified_gmt":"2014-01-20T21:07:28","slug":"double-integration-in-matlab-methods-and-handling-discontinuities-singularities-and-more","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/loren\/2014\/02\/12\/double-integration-in-matlab-methods-and-handling-discontinuities-singularities-and-more\/","title":{"rendered":"Double Integration in MATLAB &#8211; Methods and Handling Discontinuities, Singularities, and More"},"content":{"rendered":"<div class=\"content\"><!--introduction--><p>In our <a href=\"https:\/\/blogs.mathworks.com\/loren\/2013\/12\/26\/double-integration-in-matlab-understanding-tolerances\/\">recent post<\/a>, Mike Hosea and I talked about adjusting both the absolute and relative tolerances for getting more accurate results when calculating a double integral. Today we'd like to talk about choosing the method of integration as well as which order to choose for the first dimension (direction) of integration.<\/p><!--\/introduction--><h3>Contents<\/h3><div><ul><li><a href=\"#de430794-d7aa-48d1-9904-35064ddd4218\">Set the Stage<\/a><\/li><li><a href=\"#e019b38c-d0c1-4f43-b56b-35f1ea6e79d8\">Changing the Order of Integration<\/a><\/li><li><a href=\"#5f899ca5-2dcd-4b73-9589-d4adafb99428\">Singularities<\/a><\/li><li><a href=\"#92ac9721-fdda-4f49-80df-7c32b46a9f4b\">Can You Take Advantage of these New Integration Routines?<\/a><\/li><\/ul><\/div><h4>Set the Stage<a name=\"de430794-d7aa-48d1-9904-35064ddd4218\"><\/a><\/h4><p><a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/integral2.html\"><tt>integral2<\/tt><\/a> has, at present, two different integration methods, <tt>'tiled'<\/tt> and <tt>'iterated'<\/tt>, not counting the <tt>'auto'<\/tt> method that chooses between them.<\/p><p>Each integration method employs a type of \"divide-and-conquer\" approach to double integration but in very different ways. The <tt>'tiled'<\/tt> method is based on <tt>quad2d<\/tt>'s approach of dividing the region into quadrants and approximating the integral over each quadrant by a 2-D quadrature rule. If the error condition on a rectangle is not met, the rectangle is divided into quadrants and so forth. The <tt>'iterated'<\/tt> method, as the name suggests, performs the integration as iterated one-dimensional integrals, so its \"divide-and-conquer\" strategy is to tackle one dimension first and then move on to the other.<\/p><p>So, why have two methods? Each has different strengths. Usually the tiled approach is the faster of the two, but it has its weaknesses. As an example of this, consider the way integrating over non-rectangular regions was formerly done in MATLAB. Because <tt>dblquad<\/tt> would only integrate over rectangles, one would \"mask\" the input function to make it zero inside of a rectangular region. For example, to integrate <tt>F<\/tt> over a triangle with the vertices (0,0),(1,0), and (1,1), you would write<\/p><pre class=\"codeinput\">F = @(x,y)exp(10*x).*tan(y)\r\nQ = dblquad(@(x,y)F(x,y).*(y &lt;= x),0,1,0,1)\r\n<\/pre><pre class=\"codeoutput\">F = \r\n    @(x,y)exp(10*x).*tan(y)\r\nQ =\r\n       1072.6\r\n<\/pre><p>Now you can instead write<\/p><pre class=\"codeinput\">Q = integral2(F,0,1,0,@(x)x)\r\n<\/pre><pre class=\"codeoutput\">Q =\r\n       1072.6\r\n<\/pre><p>This is more than a convenience. Telling the integrator where the boundary is gives it an enormous advantage. Conversely, masking the integrand has devastating effects on performance and accuracy. The underlying quadrature rule gives the best results when the integrand is smooth, and a discontinuity where the integrand drops precipitously to zero will cause the adaptive quadrature algorithm to subdivide and further subdivide in that area until the error estimates across the discontinuity are sufficiently small.<\/p><p>This is especially problematic for <tt>quad2d<\/tt> and <tt>integral2<\/tt> with the <tt>'tiled'<\/tt> method. With the <tt>'iterated'<\/tt> method, any curvilinear discontinuity is covered by a single interval in any given integration, but in two dimensions, subdividing each tile into 4 pieces, the integrator ends up covering a curvilinear path with a large number of small rectangles. Usually the limit on the number of function evaluations will be reached before it can polish them all off.<\/p><p>We can visualize this using <tt>quad2d<\/tt>'s <tt>FailurePlot<\/tt> option and use the <tt>MaxFunEvals<\/tt> option to control how much work is done before the code gives up. Suppose<\/p><pre class=\"codeinput\">F = @(x,y)sin(x.\/(y.*y + 1)).*(y &lt;=x)\r\n<\/pre><pre class=\"codeoutput\">F = \r\n    @(x,y)sin(x.\/(y.*y+1)).*(y&lt;=x)\r\n<\/pre><p>Then<\/p><pre class=\"codeinput\">Q = quad2d(F,0,1,0,1,<span class=\"string\">'MaxFunEvals'<\/span>,60,<span class=\"string\">'FailurePlot'<\/span>,true)\r\n<\/pre><pre class=\"codeoutput\">Warning: Reached the maximum number of function evaluations (60). The result\r\nfails the global error test. \r\nQ =\r\n      0.26562\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/loren\/2014\/intexXYOrder_01.png\" alt=\"\"> <p>There's nothing special about the larger rectangle on the bottom. <tt>quad2d<\/tt> preferentially attacks the rectangles with the largest error, so when a larger rectangle just barely fails the error test, it hangs around if the integrator has bigger problems elsewhere. Those bigger problems are signified by smaller rectangles. Now, if we increase the number of allowed function evaluations, we see that <tt>quad2d<\/tt> is still struggling with the boundary.<\/p><pre class=\"codeinput\"> Q = quad2d(F,0,1,0,1,<span class=\"string\">'MaxFunEvals'<\/span>,600,<span class=\"string\">'FailurePlot'<\/span>,true)\r\n<\/pre><pre class=\"codeoutput\">Warning: Reached the maximum number of function evaluations (600). The result\r\nfails the global error test. \r\nQ =\r\n      0.26518\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/loren\/2014\/intexXYOrder_02.png\" alt=\"\"> <p>Since <tt>integral2<\/tt>'s <tt>'tiled'<\/tt> method is based on <tt>quad2d<\/tt>'s algorithm, it has the same issue.<\/p><pre class=\"codeinput\">Q = integral2(F,0,1,0,1)\r\n<\/pre><pre class=\"codeoutput\">Warning: Reached the maximum number of function evaluations (10000). The result\r\nfails the global error test. \r\nQ =\r\n      0.26514\r\n<\/pre><p>Although it takes some time to do it, the <tt>'iterated'<\/tt> method can deal with the problem.<\/p><pre class=\"codeinput\">tic\r\nQ = integral2(F,0,1,0,1,<span class=\"string\">'method'<\/span>,<span class=\"string\">'iterated'<\/span>)\r\ntq = toc\r\n<\/pre><pre class=\"codeoutput\">Q =\r\n      0.26513\r\ntq =\r\n       5.0793\r\n<\/pre><p>If you find that the <tt>'iterated'<\/tt> method seems slow, consider loosening the tolerances. <tt>integral2<\/tt> uses the same tolerances for all subintegrations, and it turns out that this can be a very conservative thing to do. With the default tolerances, the previous example took over 4 seconds on the machine we publish the blog from.<\/p><pre class=\"codeinput\">tic\r\nQ = integral2(F,0,1,0,1,<span class=\"string\">'method'<\/span>,<span class=\"string\">'iterated'<\/span>,<span class=\"string\">'AbsTol'<\/span>,1e-6,<span class=\"string\">'RelTol'<\/span>,1e-3)\r\ntq(2) = toc\r\n<\/pre><pre class=\"codeoutput\">Q =\r\n      0.26514\r\ntq =\r\n       5.0793      0.14705\r\n<\/pre><p>And that took less than a tenth of second on the same machine.<\/p><h4>Changing the Order of Integration<a name=\"e019b38c-d0c1-4f43-b56b-35f1ea6e79d8\"><\/a><\/h4><p>Discontinuities may snake through the region of integration, but occasionally they might be linear and parallel to one axis or the other. In that case the order of integration matters when using the <tt>'iterated'<\/tt> method. Since every outer integration performs many inner integrations, it tends to be more useful to make the outer integrations the more efficient ones if possible, and this means letting the inner integrations take care of jump discontinuities. In this example the integrand function alternates between <tt>z = 0<\/tt> and <tt>z = y<\/tt> depending on whether <tt>floor(x)<\/tt> is even or odd.<\/p><pre class=\"codeinput\">f = @(x,y)mod(floor(x),2).*y\r\ntic\r\nintegral2(f,0,20,0,1,<span class=\"string\">'method'<\/span>,<span class=\"string\">'iterated'<\/span>)\r\ntoc\r\n<\/pre><pre class=\"codeoutput\">f = \r\n    @(x,y)mod(floor(x),2).*y\r\nans =\r\n     5\r\nElapsed time is 5.625905 seconds.\r\n<\/pre><p>That worked, but the \"inner\" integration is in the <tt>y<\/tt>-direction, and for a given <tt>x<\/tt> that means that the function is either identically zero or a straight line. Either is very easy to integrate. However, this means that the integrand for the outer integral has jump discontinuities from 0 to 0.5 depending on whether <tt>floor(x)<\/tt> is even or odd. We'd rather have the inner integrals deal with any (or at least most of) the discontinuities. Changing the order of integration is easy.<\/p><pre class=\"codeinput\">tic\r\nintegral2(@(y,x)f(x,y),0,1,0,20,<span class=\"string\">'method'<\/span>,<span class=\"string\">'iterated'<\/span>)\r\ntoc\r\n<\/pre><pre class=\"codeoutput\">ans =\r\n     5\r\nElapsed time is 0.264443 seconds.\r\n<\/pre><h4>Singularities<a name=\"5f899ca5-2dcd-4b73-9589-d4adafb99428\"><\/a><\/h4><p>Unlike <tt>dblquad<\/tt>, <tt>integral2<\/tt> can integrate singularities on the boundary if they are not too severe. If your problem has a singularity in the interior of the region of integration, you should divide the integral into pieces so that all singularities reside on the boundaries of regions of integration. For example,<\/p><pre class=\"codeinput\">f = @(x,y)1.\/sqrt(abs(x.*y))\r\n<\/pre><pre class=\"codeoutput\">f = \r\n    @(x,y)1.\/sqrt(abs(x.*y))\r\n<\/pre><p>If we integrate this over the square <tt>-1 &lt;= x &lt;= 1<\/tt>, <tt>-1 &lt;= y &lt;= 1<\/tt>, we have a problem because f is singular along both <tt>x<\/tt> and <tt>y<\/tt> axes. Obviously <tt>f<\/tt> is symmetric with respect to both axes, so we need only integrate over <tt>0 &lt;= x &lt;= 1<\/tt>, <tt>0 &lt;= y &lt;= 1<\/tt> and multiply by 4, but let's set this aside and try to do it directly.<\/p><pre class=\"codeinput\">integral2(f,-1,1,-1,1,<span class=\"string\">'RelTol'<\/span>,1e-12,<span class=\"string\">'AbsTol'<\/span>,1e-14)\r\n<\/pre><pre class=\"codeoutput\">Warning: Reached the maximum number of function evaluations (10000). The result\r\nfails the global error test. \r\nans =\r\n       15.869\r\n<\/pre><p>The <tt>'iterated'<\/tt> method doesn't bail us out this time.<\/p><pre class=\"codeinput\">integral2(f,-1,1,-1,1,<span class=\"string\">'RelTol'<\/span>,1e-12,<span class=\"string\">'AbsTol'<\/span>,1e-14,<span class=\"string\">'Method'<\/span>,<span class=\"string\">'iterated'<\/span>)\r\n<\/pre><pre class=\"codeoutput\">Warning: Reached the limit on the maximum number of intervals in use.\r\nApproximate bound on error is   9.0e-09. The integral may not exist, or it may\r\nbe difficult to approximate numerically to the requested accuracy. \r\nWarning: The integration was unsuccessful. \r\nans =\r\n   NaN\r\n<\/pre><p>However if we split the integration into four pieces, putting the singularity on the boundary, the problem is absolutely routine.<\/p><pre class=\"codeinput\">Q = 0;\r\nQ = Q + integral2(f,-1,0,-1,0,<span class=\"string\">'RelTol'<\/span>,1e-12,<span class=\"string\">'AbsTol'<\/span>,1e-14);\r\nQ = Q + integral2(f,-1,0,0,1,<span class=\"string\">'RelTol'<\/span>,1e-12,<span class=\"string\">'AbsTol'<\/span>,1e-14);\r\nQ = Q + integral2(f,0,1,-1,0,<span class=\"string\">'RelTol'<\/span>,1e-12,<span class=\"string\">'AbsTol'<\/span>,1e-14);\r\nQ = Q + integral2(f,0,1,0,1,<span class=\"string\">'RelTol'<\/span>,1e-12,<span class=\"string\">'AbsTol'<\/span>,1e-14)\r\n<\/pre><pre class=\"codeoutput\">Q =\r\n           16\r\n<\/pre><h4>Can You Take Advantage of these New Integration Routines?<a name=\"92ac9721-fdda-4f49-80df-7c32b46a9f4b\"><\/a><\/h4><p>What kinds of functions do you need to integrate?  Will the flexibility from <tt>integral2<\/tt> and it's other companions help you? Let us know <a href=\"https:\/\/blogs.mathworks.com\/loren\/?p=845#respond\">here<\/a>.<\/p><script language=\"JavaScript\"> <!-- \r\n    function grabCode_e25df211bb254d4ab0cacca52e66c977() {\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='e25df211bb254d4ab0cacca52e66c977 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' e25df211bb254d4ab0cacca52e66c977';\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_e25df211bb254d4ab0cacca52e66c977()\"><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; R2013b<br><\/p><p class=\"footer\"><br>\r\n      Published with MATLAB&reg; R2013b<br><\/p><\/div><!--\r\ne25df211bb254d4ab0cacca52e66c977 ##### SOURCE BEGIN #####\r\n%% Double Integration in MATLAB - Methods and Handling Discontinuities, Singularities, and More\r\n% In our\r\n% <https:\/\/blogs.mathworks.com\/loren\/2013\/12\/26\/double-integration-in-matlab-understanding-tolerances\/\r\n% recent post>, Mike Hosea and I talked about adjusting both the absolute\r\n% and relative tolerances for getting more accurate results when\r\n% calculating a double integral. Today we'd like to talk about choosing the\r\n% method of integration as well as which order to choose for the first\r\n% dimension (direction) of integration.\r\n%% Set the Stage\r\n% <https:\/\/www.mathworks.com\/help\/matlab\/ref\/integral2.html |integral2|>\r\n% has, at present, two different integration methods, |'tiled'| and\r\n% |'iterated'|, not counting the |'auto'| method that chooses between them.\r\n%\r\n% Each integration method employs a type of \"divide-and-conquer\" approach\r\n% to double integration but in very different ways. The |'tiled'| method is\r\n% based on |quad2d|'s approach of dividing the region into quadrants and\r\n% approximating the integral over each quadrant by a 2-D quadrature rule.\r\n% If the error condition on a rectangle is not met, the rectangle is\r\n% divided into quadrants and so forth. The |'iterated'| method, as the name\r\n% suggests, performs the integration as iterated one-dimensional integrals,\r\n% so its \"divide-and-conquer\" strategy is to tackle one dimension first and\r\n% then move on to the other.\r\n%\r\n% So, why have two methods? Each has different strengths. Usually the tiled\r\n% approach is the faster of the two, but it has its weaknesses. As an\r\n% example of this, consider the way integrating over non-rectangular\r\n% regions was formerly done in MATLAB. Because |dblquad| would only\r\n% integrate over rectangles, one would \"mask\" the input function to make it\r\n% zero inside of a rectangular region. For example, to integrate |F| over a\r\n% triangle with the vertices (0,0),(1,0), and (1,1), you would write\r\nF = @(x,y)exp(10*x).*tan(y)\r\nQ = dblquad(@(x,y)F(x,y).*(y <= x),0,1,0,1)\r\n%%\r\n% Now you can instead write\r\nQ = integral2(F,0,1,0,@(x)x)\r\n%%\r\n% This is more than a convenience. Telling the integrator where the\r\n% boundary is gives it an enormous advantage. Conversely, masking the\r\n% integrand has devastating effects on performance and accuracy. The\r\n% underlying quadrature rule gives the best results when the integrand is\r\n% smooth, and a discontinuity where the integrand drops precipitously to\r\n% zero will cause the adaptive quadrature algorithm to subdivide and\r\n% further subdivide in that area until the error estimates across the\r\n% discontinuity are sufficiently small.\r\n%\r\n% This is especially problematic for |quad2d| and |integral2| with the\r\n% |'tiled'| method. With the |'iterated'| method, any curvilinear\r\n% discontinuity is covered by a single interval in any given integration,\r\n% but in two dimensions, subdividing each tile into 4 pieces, the\r\n% integrator ends up covering a curvilinear path with a large number of\r\n% small rectangles. Usually the limit on the number of function evaluations\r\n% will be reached before it can polish them all off.\r\n%\r\n% We can visualize this using |quad2d|'s |FailurePlot| option and use the\r\n% |MaxFunEvals| option to control how much work is done before the code\r\n% gives up. Suppose\r\nF = @(x,y)sin(x.\/(y.*y + 1)).*(y <=x)\r\n%%\r\n% Then\r\nQ = quad2d(F,0,1,0,1,'MaxFunEvals',60,'FailurePlot',true)\r\n\r\n%%\r\n% There's nothing special about the larger rectangle on the bottom.\r\n% |quad2d| preferentially attacks the rectangles with the largest error, so\r\n% when a larger rectangle just barely fails the error test, it hangs around\r\n% if the integrator has bigger problems elsewhere. Those bigger problems\r\n% are signified by smaller rectangles. Now, if we increase the number of\r\n% allowed function evaluations, we see that |quad2d| is still struggling\r\n% with the boundary.\r\n Q = quad2d(F,0,1,0,1,'MaxFunEvals',600,'FailurePlot',true)\r\n\r\n%%\r\n% Since |integral2|'s |'tiled'| method is based on |quad2d|'s algorithm, it\r\n% has the same issue.\r\nQ = integral2(F,0,1,0,1)\r\n%%\r\n% Although it takes some time to do it, the |'iterated'| method can deal\r\n% with the problem.\r\ntic\r\nQ = integral2(F,0,1,0,1,'method','iterated')\r\ntq = toc\r\n%%\r\n% If you find that the |'iterated'| method seems slow, consider loosening\r\n% the tolerances. |integral2| uses the same tolerances for all\r\n% subintegrations, and it turns out that this can be a very conservative\r\n% thing to do. With the default tolerances, the previous example took over\r\n% 4 seconds on the machine we publish the blog from.\r\ntic\r\nQ = integral2(F,0,1,0,1,'method','iterated','AbsTol',1e-6,'RelTol',1e-3)\r\ntq(2) = toc\r\n%%\r\n% And that took less than a tenth of second on the same machine. \r\n\r\n%% Changing the Order of Integration\r\n% Discontinuities may snake through the region of integration, but\r\n% occasionally they might be linear and parallel to one axis or the other.\r\n% In that case the order of integration matters when using the |'iterated'|\r\n% method. Since every outer integration performs many inner integrations,\r\n% it tends to be more useful to make the outer integrations the more\r\n% efficient ones if possible, and this means letting the inner integrations\r\n% take care of jump discontinuities. In this example the integrand function\r\n% alternates between |z = 0| and |z = y| depending on whether |floor(x)| is\r\n% even or odd.\r\nf = @(x,y)mod(floor(x),2).*y\r\ntic\r\nintegral2(f,0,20,0,1,'method','iterated')\r\ntoc\r\n\r\n%%\r\n% That worked, but the \"inner\" integration is in the |y|-direction, and for\r\n% a given |x| that means that the function is either identically zero or a\r\n% straight line. Either is very easy to integrate. However, this means that\r\n% the integrand for the outer integral has jump discontinuities from 0 to\r\n% 0.5 depending on whether |floor(x)| is even or odd. We'd rather have the\r\n% inner integrals deal with any (or at least most of) the discontinuities.\r\n% Changing the order of integration is easy.\r\ntic\r\nintegral2(@(y,x)f(x,y),0,1,0,20,'method','iterated')\r\ntoc\r\n\r\n%% Singularities\r\n% Unlike |dblquad|, |integral2| can integrate singularities on the boundary\r\n% if they are not too severe. If your problem has a singularity in the\r\n% interior of the region of integration, you should divide the integral\r\n% into pieces so that all singularities reside on the boundaries of regions\r\n% of integration. For example,\r\nf = @(x,y)1.\/sqrt(abs(x.*y))\r\n\r\n%%\r\n% If we integrate this over the square |-1 <= x <= 1|, |-1 <= y <= 1|, we\r\n% have a problem because f is singular along both |x| and |y| axes.\r\n% Obviously |f| is symmetric with respect to both axes, so we need only\r\n% integrate over |0 <= x <= 1|, |0 <= y <= 1| and multiply by 4, but let's\r\n% set this aside and try to do it directly.\r\nintegral2(f,-1,1,-1,1,'RelTol',1e-12,'AbsTol',1e-14)\r\n\r\n%%\r\n% The |'iterated'| method doesn't bail us out this time. \r\nintegral2(f,-1,1,-1,1,'RelTol',1e-12,'AbsTol',1e-14,'Method','iterated')\r\n\r\n%% \r\n% However if we split the integration into four pieces, putting the\r\n% singularity on the boundary, the problem is absolutely routine.\r\nQ = 0;\r\nQ = Q + integral2(f,-1,0,-1,0,'RelTol',1e-12,'AbsTol',1e-14);\r\nQ = Q + integral2(f,-1,0,0,1,'RelTol',1e-12,'AbsTol',1e-14);\r\nQ = Q + integral2(f,0,1,-1,0,'RelTol',1e-12,'AbsTol',1e-14);\r\nQ = Q + integral2(f,0,1,0,1,'RelTol',1e-12,'AbsTol',1e-14)\r\n\r\n%% Can You Take Advantage of these New Integration Routines?\r\n% What kinds of functions do you need to integrate?  Will the flexibility\r\n% from |integral2| and it's other companions help you? Let us know\r\n% <https:\/\/blogs.mathworks.com\/loren\/?p=845#respond here>.\r\n\r\n\r\n##### SOURCE END ##### e25df211bb254d4ab0cacca52e66c977\r\n-->","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"https:\/\/blogs.mathworks.com\/images\/loren\/2014\/intexXYOrder_02.png\" onError=\"this.style.display ='none';\" \/><\/div><!--introduction--><p>In our <a href=\"https:\/\/blogs.mathworks.com\/loren\/2013\/12\/26\/double-integration-in-matlab-understanding-tolerances\/\">recent post<\/a>, Mike Hosea and I talked about adjusting both the absolute and relative tolerances for getting more accurate results when calculating a double integral. Today we'd like to talk about choosing the method of integration as well as which order to choose for the first dimension (direction) of integration.... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/loren\/2014\/02\/12\/double-integration-in-matlab-methods-and-handling-discontinuities-singularities-and-more\/\">read more >><\/a><\/p>","protected":false},"author":39,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[59],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/posts\/845"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/users\/39"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/comments?post=845"}],"version-history":[{"count":5,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/posts\/845\/revisions"}],"predecessor-version":[{"id":856,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/posts\/845\/revisions\/856"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/media?parent=845"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/categories?post=845"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/loren\/wp-json\/wp\/v2\/tags?post=845"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}