http://www.mathworks.com/matlabcentral/newsreader/view_thread/306545
MATLAB Central Newsreader  Numerically Integrating Double Integrals (but dblquad doesn't apply!)
Feed for thread: Numerically Integrating Double Integrals (but dblquad doesn't apply!)
enus
©19942015 by MathWorks, Inc.
webmaster@mathworks.com
MATLAB Central Newsreader
http://blogs.law.harvard.edu/tech/rss
60
MathWorks
http://www.mathworks.com/images/membrane_icon.gif

Wed, 20 Apr 2011 02:36:05 +0000
Numerically Integrating Double Integrals (but dblquad doesn't apply!)
http://www.mathworks.com/matlabcentral/newsreader/view_thread/306545#832054
Tim
Hi,<br>
<br>
I had a simple problem that I would like to be able to numerically integrate:<br>
<br>
int_x=4^x=5 x int_y1^y=3 x*y^2 dy dx<br>
<br>
I've tried using the quad function, but I can't figure out how to "embed" one quad function with another. Also, I've tried to use dblquad function but this is better suited for a function of the form:<br>
<br>
int int f(x,y) dx dy<br>
<br>
Notice that in my simple example there was an "x" hanging out after the inner integral.<br>
<br>
Is it possible to numerically integrate this in MATLAB?<br>
<br>
Thanks,<br>
Tim

Wed, 20 Apr 2011 03:17:06 +0000
Re: Numerically Integrating Double Integrals (but dblquad doesn't apply!)
http://www.mathworks.com/matlabcentral/newsreader/view_thread/306545#832055
Roger Stafford
"Tim" wrote in message <iolgql$17h$1@fred.mathworks.com>...<br>
> Hi,<br>
> <br>
> I had a simple problem that I would like to be able to numerically integrate:<br>
> <br>
> int_x=4^x=5 x int_y1^y=3 x*y^2 dy dx<br>
> <br>
> I've tried using the quad function, but I can't figure out how to "embed" one quad function with another. Also, I've tried to use dblquad function but this is better suited for a function of the form:<br>
> <br>
> int int f(x,y) dx dy<br>
> <br>
> Notice that in my simple example there was an "x" hanging out after the inner integral.<br>
> <br>
> Is it possible to numerically integrate this in MATLAB?<br>
> <br>
> Thanks,<br>
> Tim<br>
        <br>
If I interpret your symbols correctly, you are integrating over a rectangular area in the xy plane, the inner integral limits not depending on x. I don't see any problem in using 'dblquad' with the integrand f(x,y) = x^2*y^2 for this case.<br>
<br>
Now if you had an example in which the inner integral had one or both limits depending on the outer variable, that would be a nonrectangular area and 'dblquad' cannot be used directly on that. However 'quad2d' can handle that case. See the latter's documentation.<br>
<br>
Roger Stafford

Wed, 20 Apr 2011 11:29:26 +0000
Re: Numerically Integrating Double Integrals (but dblquad doesn't apply!)
http://www.mathworks.com/matlabcentral/newsreader/view_thread/306545#832122
Loren Shure
<br>
"Tim " <timmyrunsfast@gmail.com> wrote in message <br>
news:iolgql$17h$1@fred.mathworks.com...<br>
> Hi,<br>
><br>
> I had a simple problem that I would like to be able to numerically <br>
> integrate:<br>
><br>
> int_x=4^x=5 x int_y1^y=3 x*y^2 dy dx<br>
><br>
> I've tried using the quad function, but I can't figure out how to "embed" <br>
> one quad function with another. Also, I've tried to use dblquad function <br>
> but this is better suited for a function of the form:<br>
><br>
> int int f(x,y) dx dy<br>
><br>
> Notice that in my simple example there was an "x" hanging out after the <br>
> inner integral.<br>
><br>
> Is it possible to numerically integrate this in MATLAB?<br>
<br>
Check out quad2d: <a href="http://www.mathworks.com/help/techdoc/ref/quad2d.html">http://www.mathworks.com/help/techdoc/ref/quad2d.html</a><br>
<br>
 <br>
Loren<br>
<a href="http://blogs.mathworks.com/loren/">http://blogs.mathworks.com/loren/</a><br>
<a href="http://www.mathworks.com/matlabcentral/">http://www.mathworks.com/matlabcentral/</a>

Sun, 24 Apr 2011 20:39:57 +0000
Re: Numerically Integrating Double Integrals (but dblquad doesn't
http://www.mathworks.com/matlabcentral/newsreader/view_thread/306545#832818
Mike Hosea
Tim wrote:<br>
> Hi,<br>
><br>
> I had a simple problem that I would like to be able to numerically<br>
> integrate:<br>
><br>
> int_x=4^x=5 x int_y1^y=3 x*y^2 dy dx<br>
><br>
> I've tried using the quad function, but I can't figure out how to<br>
> "embed" one quad function with another. Also, I've tried to use dblquad<br>
> function but this is better suited for a function of the form:<br>
><br>
> int int f(x,y) dx dy<br>
><br>
> Notice that in my simple example there was an "x" hanging out after the<br>
> inner integral.<br>
><br>
> Is it possible to numerically integrate this in MATLAB?<br>
><br>
> Thanks,<br>
> Tim<br>
<br>
You can just factor the x into the inner integral and use DBLQUAD or <br>
QUAD2D.<br>
<br>
>> quad2d(@(x,y)x.^2.*y.^2,4,5,1,3)<br>
ans =<br>
176.22<br>
<br>
However, you can do it the other way<br>
<br>
>> scalarInner = @(x)quad(@(y)x.*(y.^2),1,3); % scalar in, scalar out<br>
>> vectorInner = @(x)arrayfun(scalarInner,x); % vector in, vector out<br>
>> quad(@(x)x.*vectorInner(x),4,5)<br>
ans =<br>
176.22<br>
<br>
or in one line:<br>
<br>
>> quad(@(t)t.*arrayfun(@(x)quad(@(y)x.*(y.^2),1,3),t),4,5)<br>
ans =<br>
176.22<br>
<br>
<br>
Mike