3
$\begingroup$

I am integrating g over the region:

RegionPlot[ 0 <= x <= 3 && 1 - x <= y < -(2/3) x + 2, {x, 0, 3}, {y, 0, 2}]

enter image description here

The limits of integration are

$$\int _0^1\int _{1-x}^{2-\frac{2 x}{3}}g[x,y]dydx+\int _1^3\int _0^{2-\frac{2 x}{3}}g[x,y]dydx$$

The expected answer is obtained from evaluating these integrals.

g[x_, y_] := 3 x + y^2

Integrate[g[x, y], {x, 0, 1}, {y, 1 - x, -(2/3) x + 2}] + 
 Integrate[g[x, y], {x, 1, 3}, {y, 0, -(2/3) x + 2}]
(* 125/12 *)

I then had the idea that I could use the Assumptions option to restrict y and only evaluate one Integration. However, the answer is returned is the same as an unrestricted y integration.

Integrate[g[x, y], {x, 0, 3}, {y, 1 - x, -(2/3) x + 2}, 
 Assumptions -> y >= 0]
(* 103/4 *)

Integrate[g[x, y], {x, 0, 3}, {y, 1 - x, -(2/3) x + 2}]
(* 103/4 *)

Why doesn't Integrate restrict y with the Assumption option?

$\endgroup$
1
  • 2
    $\begingroup$ It appears that Assumptions is intended only to eliminate generated conditions, not to reduce the range of an integration variable. Thus, Integrate[1, {y, -1, 1}] and Integrate[1, {y, -1, 1}, Assumptions -> y > 0] produce the same answer $\endgroup$
    – bbgodfrey
    Commented Dec 5, 2015 at 18:10

3 Answers 3

6
$\begingroup$

Another clean approach to performing a single integration builds on the input to the plot in the question.

r = ImplicitRegion[0 <= x <= 3 && 0 <= y <= 2 && 1 - x <= y < -(2/3) x + 2, {x, y}]
Integrate [3 x + y^2, {x, y} ∈ r]
(* 125/12 *)
$\endgroup$
1
  • $\begingroup$ This is it! (+1) I will hold out for a while before accepting. Just in case. :-) $\endgroup$
    – Edmund
    Commented Dec 5, 2015 at 18:20
4
$\begingroup$

Here you loose the control of proper integration limits and the result is different since the region of integration is different.
In general using another variable as a limit of integration is a bad idea moreover using Assumptions to restrict integration (or summation) variables is not reasonable, you can find an analogous mistake in a different context here: Double series over primes.

If you want to get the correct result in one integral there are many different approaches. Let's provide two the most natural and reliable, both working in earlier versions of Mathematica :

Integrate[ g[x, y] Boole[1 - x <= y <= -(2/3) x + 2], {x, 0, 3}, {y, 0, 2}]
125/12

One can use also HeavisideTheta appropriately, which sometimes may appear more efficient (see e.g. this post How to plot and find the volume of a solid?), equivalent calculation with HeavisideTheta:

Integrate[ g[x, y] HeavisideTheta[y + x - 1] HeavisideTheta[-y - 2/3 x + 2],
           {x, 0, 3}, {y, 0, 2}]
$\endgroup$
6
  • $\begingroup$ The second integral is just restricting $y >= 0$ on $x ∈ [1 ,3]$. Why doesn't an Assumption -> y >= 0 achieve this in the single Integral evaluation. $\endgroup$
    – Edmund
    Commented Dec 5, 2015 at 18:09
  • 1
    $\begingroup$ Apparently your understanding of Assumptions is incorrect, you cannot limit another variable in this way, this is a common mistake. Read e.g. the second answer (by Sektor) to this question Double series over primes. Is it clear? $\endgroup$
    – Artes
    Commented Dec 5, 2015 at 18:13
  • 2
    $\begingroup$ @Edmund In Assumptions you can limit constants, not variables of integration! $\endgroup$
    – Artes
    Commented Dec 5, 2015 at 18:19
  • $\begingroup$ Yes. My understanding of Assumptions was off. Your solution works (+1) but is not the conceptual approach I am seeking. $\endgroup$
    – Edmund
    Commented Dec 5, 2015 at 18:23
  • $\begingroup$ @Edmund This had been the best approach until the version 10 of Mathematica (remember my previous remarks) and in various cases it is still the best. I remember several cases when new functionality worked incorrectly, so I'm not sure ImplicitRegion is a perfect approach. Read this answer Finding length of intersection of two surfaces paying attention to its earlier versions and comments beneath. For this reason I'm not quite convinced to ImplicitRegion. $\endgroup$
    – Artes
    Commented Dec 5, 2015 at 18:30
2
$\begingroup$

Amplifying on the answer by @bbgodfrey

rgn = ImplicitRegion[0 <= x <= 3 && 1 - x <= y < -(2/3) x + 2, {x, y}];

What you plotted was

RegionPlot[rgn, PlotRange -> {{0, 3}, {0, 2}}]

enter image description here

However, restricting the portion of the region displayed does not change the region. The region defined by the inequalities is larger than the region that you displayed.

RegionPlot[rgn]

enter image description here

g[x_, y_] := 3 x + y^2

Integrate[g[x, y], {x, y} ∈ rgn]

(*  103/4  *)

Restricting the region to that corresponding to the region displayed in the original plot

rgn2 = ImplicitRegion[
   0 <= x <= 3 && 0 <= y <= 2 && 1 - x <= y < -(2/3) x + 2, {x, y}];

Integrate[g[x, y], {x, y} ∈ rgn2]

(*  125/12  *)
$\endgroup$
1
  • $\begingroup$ Yes. I think I will change to plotting the regions without bounding the variables so I don't overlook this again. (+1) $\endgroup$
    – Edmund
    Commented Dec 5, 2015 at 18:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.