<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Two-Dimensional Integration over a General Domain</title>
	<atom:link href="http://blogs.mathworks.com/loren/2006/04/26/two-dimensional-integration-over-a-general-domain/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.mathworks.com/loren/2006/04/26/two-dimensional-integration-over-a-general-domain/</link>
	<description>Loren Shure works on design of the MATLAB language at MathWorks. She writes here about once a week on MATLAB programming and related topics.</description>
	<lastBuildDate>Mon, 13 Feb 2012 13:24:10 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2006/04/26/two-dimensional-integration-over-a-general-domain/#comment-32244</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Sun, 08 May 2011 21:56:28 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=31#comment-32244</guid>
		<description>Mohamad,

You can&#039;t use the quad* functions in MATLAB to integrate functions of symbolic variables.  You should use the int function in Symbolic Math Toolbox for that.

If you can convert your function to a numeric one, check into the function quad2d: http://www.mathworks.com/help/techdoc/ref/quad2d.html which was added a few releases ago.  

--Loren</description>
		<content:encoded><![CDATA[<p>Mohamad,</p>
<p>You can&#8217;t use the quad* functions in MATLAB to integrate functions of symbolic variables.  You should use the int function in Symbolic Math Toolbox for that.</p>
<p>If you can convert your function to a numeric one, check into the function quad2d: <a href="http://www.mathworks.com/help/techdoc/ref/quad2d.html" rel="nofollow">http://www.mathworks.com/help/techdoc/ref/quad2d.html</a> which was added a few releases ago.  </p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mohamad</title>
		<link>http://blogs.mathworks.com/loren/2006/04/26/two-dimensional-integration-over-a-general-domain/#comment-32243</link>
		<dc:creator>Mohamad</dc:creator>
		<pubDate>Sun, 08 May 2011 13:51:29 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=31#comment-32243</guid>
		<description>I am working on my final year project but I could not benefit from your code to solve a double integral on a general domain..
the double integral is the following one:
&lt;pre&gt;

syms Xin theta;
Y(Xin) = (Xin.*log(2))./log((1241482303990085.*(2./Xin - 1).^3)./(2251799813685248.*(Xin - 2).^2) + 1);
fh=@(Xin)quadl(@(theta) Y(size(theta)),0.7,1/cos(theta));
%inner integral in function of dXin between 0.7 and 1/cos(theta)
I1=quadvec(fh,0,(pi/6));
%outer integral in function of dtheta between 0 and pi/6
&lt;/pre&gt;

I received the following errors:

??? Index exceeds matrix dimensions.

Error in ==&gt; quadl at 78
if ~isfinite(y(13))

Error in ==&gt; @(Xin)quadl(@(theta)Y(size(theta)),0,1/cos(theta))


Error in ==&gt; quadvec&gt;g at 26
          y(i) = f(X(i)); % this f refers to the argument of quadvec

Error in ==&gt; quadl at 70
y = feval(f,x,varargin{:}); y = y(:).&#039;;

Error in ==&gt; quadvec at 22
      q = quadl(@g, varargin{:}); % like quadl, but supplies g as the argument</description>
		<content:encoded><![CDATA[<p>I am working on my final year project but I could not benefit from your code to solve a double integral on a general domain..<br />
the double integral is the following one:</p>
<pre>

syms Xin theta;
Y(Xin) = (Xin.*log(2))./log((1241482303990085.*(2./Xin - 1).^3)./(2251799813685248.*(Xin - 2).^2) + 1);
fh=@(Xin)quadl(@(theta) Y(size(theta)),0.7,1/cos(theta));
%inner integral in function of dXin between 0.7 and 1/cos(theta)
I1=quadvec(fh,0,(pi/6));
%outer integral in function of dtheta between 0 and pi/6
</pre>
<p>I received the following errors:</p>
<p>??? Index exceeds matrix dimensions.</p>
<p>Error in ==&gt; quadl at 78<br />
if ~isfinite(y(13))</p>
<p>Error in ==&gt; @(Xin)quadl(@(theta)Y(size(theta)),0,1/cos(theta))</p>
<p>Error in ==&gt; quadvec&gt;g at 26<br />
          y(i) = f(X(i)); % this f refers to the argument of quadvec</p>
<p>Error in ==&gt; quadl at 70<br />
y = feval(f,x,varargin{:}); y = y(:).&#8217;;</p>
<p>Error in ==&gt; quadvec at 22<br />
      q = quadl(@g, varargin{:}); % like quadl, but supplies g as the argument</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ehsan</title>
		<link>http://blogs.mathworks.com/loren/2006/04/26/two-dimensional-integration-over-a-general-domain/#comment-31909</link>
		<dc:creator>ehsan</dc:creator>
		<pubDate>Thu, 09 Dec 2010 15:17:33 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=31#comment-31909</guid>
		<description>i want to get 2dimensional integration from images with matlab but i couldn&#039;t find any way to write it.
please help me.</description>
		<content:encoded><![CDATA[<p>i want to get 2dimensional integration from images with matlab but i couldn&#8217;t find any way to write it.<br />
please help me.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ned</title>
		<link>http://blogs.mathworks.com/loren/2006/04/26/two-dimensional-integration-over-a-general-domain/#comment-31582</link>
		<dc:creator>Ned</dc:creator>
		<pubDate>Thu, 12 Aug 2010 18:36:05 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=31#comment-31582</guid>
		<description>Using anonymous functions and losing the vector capacity of the integrand is both undesirable and unnecessary.

Instead, any type (double, triple, quadruple etc) can be achieved if 
quadv() is used inside integrands, which provides for:

*retaining the vector capacity across all (X, Y ...) integration-variables, 
i.e. ONE call to quadv() instead of 7  calls to quad() (each of which involves recursive looping);

*variable precision for each value of the upper-level integration-variable:
N.B. In quadv(), the desired tolerance is respected through a vector norm of the vector-of-integrals between iterations.
Hence (in principle) some components may be a bit more precise than others.  
 
---------
BTW, quad() &amp; the like should have been built-in-like (e.g. at least implemented as mex .dll&#039;s) rather than SLOOOW script functions.

This is something that Loren may want to change in the design of the MATLAB language ...</description>
		<content:encoded><![CDATA[<p>Using anonymous functions and losing the vector capacity of the integrand is both undesirable and unnecessary.</p>
<p>Instead, any type (double, triple, quadruple etc) can be achieved if<br />
quadv() is used inside integrands, which provides for:</p>
<p>*retaining the vector capacity across all (X, Y &#8230;) integration-variables,<br />
i.e. ONE call to quadv() instead of 7  calls to quad() (each of which involves recursive looping);</p>
<p>*variable precision for each value of the upper-level integration-variable:<br />
N.B. In quadv(), the desired tolerance is respected through a vector norm of the vector-of-integrals between iterations.<br />
Hence (in principle) some components may be a bit more precise than others.  </p>
<p>&#8212;&#8212;&#8212;<br />
BTW, quad() &amp; the like should have been built-in-like (e.g. at least implemented as mex .dll&#8217;s) rather than SLOOOW script functions.</p>
<p>This is something that Loren may want to change in the design of the MATLAB language &#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Doug</title>
		<link>http://blogs.mathworks.com/loren/2006/04/26/two-dimensional-integration-over-a-general-domain/#comment-30276</link>
		<dc:creator>Doug</dc:creator>
		<pubDate>Tue, 05 May 2009 17:00:32 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=31#comment-30276</guid>
		<description>A couple of notes:
  I have found that writing subroutines that call quad are easier to read, especially for triple/quadruple integrals.  The quad2d function referred to in the earlier post is available as of R2009a (I have older versions running).</description>
		<content:encoded><![CDATA[<p>A couple of notes:<br />
  I have found that writing subroutines that call quad are easier to read, especially for triple/quadruple integrals.  The quad2d function referred to in the earlier post is available as of R2009a (I have older versions running).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike Hosea</title>
		<link>http://blogs.mathworks.com/loren/2006/04/26/two-dimensional-integration-over-a-general-domain/#comment-30208</link>
		<dc:creator>Mike Hosea</dc:creator>
		<pubDate>Tue, 14 Apr 2009 18:14:52 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=31#comment-30208</guid>
		<description>A couple of advances in the intervening years might be good to note here.

1. QUADGK is also subject to undersampling in similar fashion, but it does help that it supports improper integrals directly:

&gt;&gt; quadgk(@(x) x.*exp(-x), 0, inf)
ans =
    1.0000

2. QUAD2D supports non-rectangular regions directly:

&gt;&gt; a = 4; b = 3;
&gt;&gt; 4*quad2d(@(x,y)ones(size(x)),0,a,0,@(x)b*sqrt(1-(x./a).^2))
ans =
   37.6991

--
Mike</description>
		<content:encoded><![CDATA[<p>A couple of advances in the intervening years might be good to note here.</p>
<p>1. QUADGK is also subject to undersampling in similar fashion, but it does help that it supports improper integrals directly:</p>
<p>&gt;&gt; quadgk(@(x) x.*exp(-x), 0, inf)<br />
ans =<br />
    1.0000</p>
<p>2. QUAD2D supports non-rectangular regions directly:</p>
<p>&gt;&gt; a = 4; b = 3;<br />
&gt;&gt; 4*quad2d(@(x,y)ones(size(x)),0,a,0,@(x)b*sqrt(1-(x./a).^2))<br />
ans =<br />
   37.6991</p>
<p>&#8211;<br />
Mike</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2006/04/26/two-dimensional-integration-over-a-general-domain/#comment-28178</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Sun, 06 Apr 2008 20:07:25 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=31#comment-28178</guid>
		<description>Vincent-

I suspect it&#039;s because the integration intervals widen when the integration limits widen, if the function is fairly flat, but might have some &quot;peaks&quot;, the peaks can be undersampled.

You might to contact technical support for more detail.  

--Loren</description>
		<content:encoded><![CDATA[<p>Vincent-</p>
<p>I suspect it&#8217;s because the integration intervals widen when the integration limits widen, if the function is fairly flat, but might have some &#8220;peaks&#8221;, the peaks can be undersampled.</p>
<p>You might to contact technical support for more detail.  </p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Vincent</title>
		<link>http://blogs.mathworks.com/loren/2006/04/26/two-dimensional-integration-over-a-general-domain/#comment-28163</link>
		<dc:creator>Vincent</dc:creator>
		<pubDate>Sat, 05 Apr 2008 11:53:05 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=31#comment-28163</guid>
		<description>Dear Loren,

I found some problems while using the quad function. For example, if I want to evaluate the expectation value of an exponential distributed variable, I approximately use the following:

&gt;&gt; quadl(@(x) x.*exp(-x), 0, 100)

ans =

    1.0000

It works fine. However, 100 is just an approximation to infinity. So I wonder if I want a more precise answer, I should increase the upper limit. So I decide to use (0,1000). The answer is quite unexpected:

&gt;&gt; quadl(@(x) x.*exp(-x), 0, 1000)

ans =

  1.9164e-036

Why does this happen?

The same thing also happens when I use dblquad function:

&gt;&gt; dblquad(@(x, y) y.*exp(-x).*exp(-y).*(y&gt;a*x), 0, 100, 0, 100)

ans =

    0.7500

&gt;&gt; dblquad(@(x, y) y.*exp(-x).*exp(-y).*(y&gt;a*x), 0, 1000, 0, 1000)

ans =

  4.5183e-025</description>
		<content:encoded><![CDATA[<p>Dear Loren,</p>
<p>I found some problems while using the quad function. For example, if I want to evaluate the expectation value of an exponential distributed variable, I approximately use the following:</p>
<p>&gt;&gt; quadl(@(x) x.*exp(-x), 0, 100)</p>
<p>ans =</p>
<p>    1.0000</p>
<p>It works fine. However, 100 is just an approximation to infinity. So I wonder if I want a more precise answer, I should increase the upper limit. So I decide to use (0,1000). The answer is quite unexpected:</p>
<p>&gt;&gt; quadl(@(x) x.*exp(-x), 0, 1000)</p>
<p>ans =</p>
<p>  1.9164e-036</p>
<p>Why does this happen?</p>
<p>The same thing also happens when I use dblquad function:</p>
<p>&gt;&gt; dblquad(@(x, y) y.*exp(-x).*exp(-y).*(y&gt;a*x), 0, 100, 0, 100)</p>
<p>ans =</p>
<p>    0.7500</p>
<p>&gt;&gt; dblquad(@(x, y) y.*exp(-x).*exp(-y).*(y&gt;a*x), 0, 1000, 0, 1000)</p>
<p>ans =</p>
<p>  4.5183e-025</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Loren</title>
		<link>http://blogs.mathworks.com/loren/2006/04/26/two-dimensional-integration-over-a-general-domain/#comment-25965</link>
		<dc:creator>Loren</dc:creator>
		<pubDate>Sat, 09 Feb 2008 02:21:04 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=31#comment-25965</guid>
		<description>Angela-

I have no idea.  You should use a debugger with your code to see if that helps.  And if you are still stuck, you might work with technical support to sort out the issue.

--Loren</description>
		<content:encoded><![CDATA[<p>Angela-</p>
<p>I have no idea.  You should use a debugger with your code to see if that helps.  And if you are still stuck, you might work with technical support to sort out the issue.</p>
<p>&#8211;Loren</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Angela</title>
		<link>http://blogs.mathworks.com/loren/2006/04/26/two-dimensional-integration-over-a-general-domain/#comment-25944</link>
		<dc:creator>Angela</dc:creator>
		<pubDate>Fri, 08 Feb 2008 11:47:14 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.mathworks.com/loren/?p=31#comment-25944</guid>
		<description>Dear Loren,
I want to numerically integrate a profit function with several integrales with the dblquad-command, therefore I ran two loops, and put the single variables from the loop as indices. The region I want to integrate is non-rectangular, that´s how I came to the quadvec-command. In the end I want to receive a big matrix of possible profits, where each element symbolizes a possible profit-outcome with the variables used from the loops. The variables from the loops are all integer and positives, but Matlab gives me the message: Subscript indices must either be real positive integers or logicals. I don´t really understand why. Therefore I tried to run my program with the quadvec-command which you posted here. But it gave the same error message. Do you have an idea, where I could have made a mistake? 
Thanks in advance
Angela</description>
		<content:encoded><![CDATA[<p>Dear Loren,<br />
I want to numerically integrate a profit function with several integrales with the dblquad-command, therefore I ran two loops, and put the single variables from the loop as indices. The region I want to integrate is non-rectangular, that´s how I came to the quadvec-command. In the end I want to receive a big matrix of possible profits, where each element symbolizes a possible profit-outcome with the variables used from the loops. The variables from the loops are all integer and positives, but Matlab gives me the message: Subscript indices must either be real positive integers or logicals. I don´t really understand why. Therefore I tried to run my program with the quadvec-command which you posted here. But it gave the same error message. Do you have an idea, where I could have made a mistake?<br />
Thanks in advance<br />
Angela</p>
]]></content:encoded>
	</item>
</channel>
</rss>

