I would like to maximize the following definite double integral with respect to $0<r<\frac{1}{2}$:
$\int _0^{\frac{d}{1-r}}\int _{\frac{d+r x-x}{r}}^s [(1-r) x+r y -d]dydx$
under the constraints: $0\leq d \leq 1$, $2d < s \leq 4$, $0 < r < \frac{1}{2}$, $0 \leq x \leq s$, $0\leq y \leq s$.
Note that the variables of integration, i.e. $x$ and $y$, are both bounded by $0$ and $s$; for this reason, I have to be careful in my code regarding the limits of integration regions.
Here is my code:
maxR = Flatten[Table[{d, s, r /. Last@Maximize[{Integrate[(1 - r)*x + r*y - d, {x, 0, Min[s, d/(1 - r)]}, {y, Max[0, Min[s, (d + r*x - x)/r]], s}], 0 <= d <= 1, 2 d < s, 0 < r < 1/2}, {r}]}, {d, 0, 1, .1}, {s, 1, 4, .1}], 1];
ListPlot3D[maxR, PlotRange -> {0, 1}, AxesLabel -> {"d", "s", "r"}]
And this is running forever. Can anyone help please?
By the way, this is an extension of Ulich's answer to this question. While the latter shows how to get the solution of the integral, my question here regards a maximization of the integral.