I would like to maximize the following definite double integral with respect to $0
$\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.
Answer
With Integrate[...]
substituded by the result from question 202534
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 solution can be obtained numerically:
Table[NMaximize[{int[s, d, r], 0 < r < 1/2}, { r}], {d, 0,1, .1}, {s, 1, 4, .1 }]
Comments
Post a Comment