I work in a unit square. I have some conditions under which areas within the unit square are defined. Say for simplicity that there are two conditions which define two areas. For example, if y > 1/2 or if y > ax + b , we are in area 1 and otherwise, in area 2. I have represented two possible situations in the figures (Case 1 Case 2)

I want to find a and b (which are strictly positive) such that a*(area 1) + b*(area 2) is maximized. I think this is an easy problem to solve by hand, except if you have 7 different conditions. I am wondering if there is a way to automate that in Mathematica. The problem I have is that as conditions change, the shapes of the areas also change, which makes it difficult to compute them automatically (see the figures).

I would already be very happy if I could find all possible shapes given my seven conditions.

Anyone has an idea ?

  • 3
    $\begingroup$ Welcome to MMA.SE! Please show us also what you already tried (i.e. code), Otherwise you may not attract many answers and/or the question may be closed. $\endgroup$ – Yves Klett Feb 10 '14 at 10:00
  • $\begingroup$ It is not entirely clear to me what you're trying to do, but here's a thought: this calculates the area that satisfies a a given condition, Integrate[Boole[condition[x,y]], {x, 0, 1}, {y, 0, 1}] From that, you can go on and use any optimization algorithm in the market (Maximize, for example). If you want to do it numerically, which might be easier, you can use NIntegrate, rather than Integrate. $\endgroup$ – yohbs Feb 10 '14 at 12:24
  • $\begingroup$ @YvesKlett Klett I don't have any code as I do not have any idea on how to do it. In the beginning, because I had few conditions, I simply computed the areas by hand and used mathematica to maximize. But this is very very boring to do for 7 conditions. $\endgroup$ – sehb Feb 10 '14 at 12:47
  • $\begingroup$ @yohbs That is what I thought at first but then, the Integrate will have to be written differently for each case, doesn't it ? For example, in the figures I provided, the integrals for the computation of area 1 are not the same. Hence, I would have to write two different "Integrate" based on whether I am in the first or second figure. It is possible to dos so here but with my seven conditions, I would have to write dozens of possibilities. I'm afraid I'm not very clear. $\endgroup$ – sehb Feb 10 '14 at 12:52
  • $\begingroup$ It will be much simpler if you give concrete, explicit examples, with formulas and numbers, both for the areas and for the function you wish to optimize $\endgroup$ – yohbs Feb 10 '14 at 12:56

In your comment you gave an explicit example of finding the value of $a$ which maximized $a$ times the area of the region of $x,y\in [0,1]$ such that $y\geq ax$ or $y\geq1/2$. You claim the optimum value of $a$ is 1, but this appears to be incorrect:

Integrate[a Boole[y >= a x || y >= 1/2], {x, 0, 1}, {y, 0, 1}]
Plot[%, {a, 0, 3}]

$$\begin{cases} a & a\leq 0 \\ \frac{a+4}{8} & a=1 \\ \frac{1}{8} (4 a+1) & \frac{1}{2}<a<1\lor a>1 \\ \frac{1}{2} \left(2 a-a^2\right) & \text{True} \end{cases}$$

enter image description here

RegionPlot confirms this. Are you sure you're calculating things correctly?

Also, it appears that your original question of maximizing $a A_1+b A_2$ has a trivial solution:

expr1 = Integrate[a Boole[y >= 1/2 || y >= a x + b], {x, 0, 1}, {y, 0, 1}];
expr2 = Integrate[b Boole[y < 1/2 && y < b + a x], {x, 0, 1}, {y, 0, 1}];
Simplify[expr1 + expr2 /. a -> b]
(*Out: b*)

As a result, the maximization problem is not well-defined, since the product $a A_1+b A_2$ diverges as $a\rightarrow\infty,b\rightarrow\infty$, so I'm not sure your question makes sense.

| improve this answer | |

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