# maximize with assumptions on the parameters

I am trying to maximize a function of two endogenous variables (Lf and Lo), where I have two exogenous parameters (T and p), which are positive. All variables should be real. I do it as following:

maxFo = Maximize[{Sqrt[24 - Lf - Lo] + Lo +  Sqrt[Lf] p Sqrt[T],
{Lf >= 0, Lf + Lo <= 24, 0 <= Lo <= 5,  T> 0, p > 0}},
{Lf, Lo},
Reals];


I have a difficulties understanding several points:

1. Maximize[] returns a piecewise function that contains assumptions like p>0, but I've already specified this was indeed the case in Maximize[..., {..., p>0},...]. Why then does it still contain assumptions like p>0?

I then use the FullSimplify function to re-enter my constraints:

FullSimplify[maxFo, {T > 0, p > 0,
Element[p, Reals], Element[T, Reals], Element[Lf, Reals]}]


And then, I face the issue:

1. The answer for Lf seems to contain a complex number (...2 i p...)? Why? I thought I specified both in Maximize and in FullSimplify I wanted real numbers? Is it wrong how I specify this in FullSimplify?

Thanks!

1) Piecewise functions are always on the form {{val1, cond1}, {val2, cond2}, ...} where the last cond is often True when the Piecewise is generated by a Mathematica built-in function such as Maximize. When Mathematica is the one generating the conditions, it will give necessary conditions for the expressions to be correct, such that the Piecewise function can be used as-is in further calculations. Just because you told Maximize that p > 0 does not mean you cannot do e.g. maxFo[] /. {p -> -5, T -> 10} at a later time, and the result of this would be wrong if Mathematica did not keep the condition p > 0.
2) Inspecting the solution after FullSimplify reveals that the True condition in the last line in Lf is actually equivalent to T == 95/p^2. Inserting this we find
Simplify[(95 + 2 I p Sqrt[T] + p^2 T)^2/(16 (I + p Sqrt[T])^2) /. T -> 95/p^2]

So Lf is in fact real here. I'm not sure why Mathematica does not simplify to this on its own, but I think it has something to do with the order in which it simplifies the parts of the Piecewise. Since the last condition is just True even before simplification, maybe it's hard for Mathematica to recognize that the True actually corresponds to T == 95/p^2.
• Great, thanks for the answer! answer to 1) totally clarified, the one to 2) almost did, although it introduced a new confusion: while your code with Simplify[... /.T->...] gives a real, the same with Simplify[... , T==...] gives a complex number... what's happening? What's the difference (maybe I should ask on another post?). See: Simplify[(95 + 2 I p Sqrt[T] + p^2 T)^2/(16 (I + p Sqrt[T])^2), T == 95/p^2] – Matifou Nov 26 '16 at 19:38