Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Numerically Integrating Double Integrals (but dblquad doesn't apply!)

Subject: Numerically Integrating Double Integrals (but dblquad doesn't apply!)

From: Tim

Date: 20 Apr, 2011 02:36:05

Message: 1 of 4

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

Subject: Numerically Integrating Double Integrals (but dblquad doesn't apply!)

From: Roger Stafford

Date: 20 Apr, 2011 03:17:06

Message: 2 of 4

"Tim" wrote in message <iolgql$17h$1@fred.mathworks.com>...
> 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
- - - - - - - - -
  If I interpret your symbols correctly, you are integrating over a rectangular area in the x-y 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.

  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 non-rectangular area and 'dblquad' cannot be used directly on that. However 'quad2d' can handle that case. See the latter's documentation.

Roger Stafford

Subject: Numerically Integrating Double Integrals (but dblquad doesn't apply!)

From: Loren Shure

Date: 20 Apr, 2011 11:29:26

Message: 3 of 4


"Tim " <timmyrunsfast@gmail.com> wrote in message
news:iolgql$17h$1@fred.mathworks.com...
> 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?

Check out quad2d: http://www.mathworks.com/help/techdoc/ref/quad2d.html

--
Loren
http://blogs.mathworks.com/loren/
http://www.mathworks.com/matlabcentral/

Subject: Numerically Integrating Double Integrals (but dblquad doesn't

From: Mike Hosea

Date: 24 Apr, 2011 20:39:57

Message: 4 of 4

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

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us