# Solving a definite integral with constraints on the limits

I have the following definite double integral.

$$\int _0^{\frac{d}{1-r}}\int _{\frac{d+r x-x}{r}}^s [(1-r) x+r y -d]dydx$$

with the constraints: $$0\leq d \leq 1$$, $$1 \leq s \leq 4$$, $$0 \leq r \leq 1$$, $$0 \leq x \leq s$$, $$0\leq y \leq s$$.

My code for solving this integration is

Integrate[(1 - r)*x + r*y - d, {x, 0, d/(1 - r)}, {y, (d + r*x - x)/r,s}]


And I got

(d^3 - 3 d^2 r s + 3 d r^2 s^2)/(6 r - 6 r^2)


But I think this is not correct because the variables $$x$$ and $$y$$ are bounded by $$0$$ and $$s$$ and therefore I think I need additional constraints on the limits, i.e.

$$\frac{d}{1-r}\leq s$$ and $$0 \leq \frac{d+rx-x}{r} \leq s$$.

And I'm wondering how to add these two constraints in solving the above integration. Can anyone help please? Thanks!

• I don't know if the constraints are supposed to limit the region of integration, but could this be right?: {Integrate[((1 - r)*x + r*y - d), {#4[[2]], #4[[1]], #4[[3]]}, {#5[[2]], #5[[1]], #5[[3]]}, Assumptions -> {0 <= d <= 1, 1 <= s <= 4, 0 <= r <= 1, #1, #2, #3}], And[#1, #2, #3]} & @@@ List @@ (Reduce[#, {d, s, r, x, y}] & /@ BooleanConvert@ Reduce[{0 < d < 1, 1 < s < 4, 0 <= r <= 1, 0 <= x <= s, 0 <= y <= s, 0 < x < d/(1 - r), (d + r*x - x)/r < y < s}, {d, s, r, x, y}]) // Piecewise // PiecewiseExpand Jul 21 '19 at 4:45

You have to modify the integration limits to {x, 0, Min[s, d/(1 - r)]}, {y, Max[0, Min[s, (d + r*x - x)/r]], s}

Because Mathematica can't solve symbolica I give a numeric solution

int[s_?NumericQ, d_?NumericQ, r_?NumericQ] :=NIntegrate[(1 - r)*x + r*y - d, {x, 0, Min[s, d/(1 - r)]}, {y,Max[0, Min[s, (d + r*x - x)/r]], s} ]


The result can be plotted for variing s in the parameterrange 0<d,r<1

Plot3D[ int[#, d, r], {d, 0, 1}, {r, 0, 1}, AxesLabel -> {d, r, None},PlotLabel -> "s== " <> ToString[#]] &[2]


• Thanks so much, Ulich! May I ask your help once more? I have a new post for a followup question here.
– ppp
Jul 26 '19 at 18:21