Search code examples
matlabnumerical-integrationintegral

Integration numerical with variable limits


I am trying to find a double integration numerically where the inner integral has variable limits while the outer integral scalar limits and not the other way round. As I understand integral2 allows you do the reverse of what I want i.e you can have the outer variable limits non scalar while the inner should be scalar.

fxy=@(x,y)1/x+1/y
xmin=0;
xmax=@(y)2*y;
ymin=0;
ymax=+inf;
integral2(fxy,xmin,xmax,ymin,ymax)

I get the following error Error using integral2 (line 76) XMAX must be a floating point scalar.

Please not that I cant reverse the order of the variable limits as:

integral2(fxy,ymin,ymax,xmin,xmax)

because I would be performing the integration over dx dy but with wrong limits

Any help is much appreciated.


Solution

  • The order of integration is irrelevant to your integrand, as it is symmetric in the arguments x, y.

    And I think your understanding of the behavior is backwards - you can define variable limits for the inner integral and definite limits for the outer integral, not the other way around.

    If the inner integral has definite limits, then the inner variable of integration (y, in your example) disappears after the integration, and the integral simply returns a number. The limits of the outer integral (over x) cannot depend on the variable of integration in the inner integral (y) when the inner integral is a definite integral.