Tim wrote:
> Hi,
>
> I had a simple problem that I would like to be able to numerically
> integrate:
>
> int_x=4^x=5 x int_y1^y=3 x*y^2 dy dx
>
> 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:
>
> int int f(x,y) dx dy
>
> Notice that in my simple example there was an "x" hanging out after the
> inner integral.
>
> Is it possible to numerically integrate this in MATLAB?
>
> Thanks,
> Tim
You can just factor the x into the inner integral and use DBLQUAD or
QUAD2D.
>> quad2d(@(x,y)x.^2.*y.^2,4,5,1,3)
ans =
176.22
However, you can do it the other way
>> scalarInner = @(x)quad(@(y)x.*(y.^2),1,3); % scalar in, scalar out
>> vectorInner = @(x)arrayfun(scalarInner,x); % vector in, vector out
>> quad(@(x)x.*vectorInner(x),4,5)
ans =
176.22
or in one line:
>> quad(@(t)t.*arrayfun(@(x)quad(@(y)x.*(y.^2),1,3),t),4,5)
ans =
176.22

Mike
