# Domain errors with Maximize/NMaximize

I am trying to maximize a (somewhat) complicated function over probability distribution $p$ and $q$. Here is my input:

Maximize[{(p0 q2 + p2 q0)^0.5 + (p0 q1 + p1 q0)^0.5 + (p1 q3 + p3 q1)^0.5
+ (p2 q3 + p3 q2)^0.5,
(0 <= p0 <= 1) && (0 <= p1 <= 1) && (0 <= p2 <= 1) && (0 <= p3 <= 1) &&
(0 <= q0 <= 1) && (0 <= q1 <= 1) && (0 <= q2 <= 1) && (0 <= q3 <= 1) &&
(p0 + p1 + p2 + p3 == 1) && (q0 + q1 + q2 + q3 == 1)},
{p0, p1, p2, p3, q0, q1, q2, q3}] // N


However, I get this error:

NMaximize::nrnum: "The function value -0.862277-0.353837 I is not a real number at
{ p0, p1, p2, p3, q0, q1, q2, q3} = { -0.00823803, 0.168927, 0.643765, 0.195547,
-0.0740624, 0.571036, 0.228872, 0.274154  }."


I find this odd, since I thought the constraints should disallow that.
Oddly enough, FindMaximum works fine.

• Someone better versed than me probably knows the answer, but even when I specified the intervals using {{p0, 0, 1}, {p1, 0, 1}, {p2, 0, 1}, {p3, 0, 1}, {q0, 0, 1}, {q1, 0, 1}, {q2, 0, 1}, {q3, 0, 1}} it still gave an error because it started using some negative values of the variables, so I'm not sure why it's starting the maximization in a location that's outside the specified bounds... Feb 10 '14 at 23:09
• Also, since your expression has things to the power of 0.5 (which is numeric), it's automatically calling NMaximize, rather than Maximize, so the N is not needed. Feb 10 '14 at 23:11

Here's one way to get an answer:

NMaximize[{Sqrt[Abs[p0 q2 + p2 q0]] + Sqrt[Abs[p0 q1 + p1 q0]] +
Sqrt[Abs[p1 q3 + p3 q1]] + Sqrt[Abs[p2 q3 + p3 q2]],
(0 < p0 < 1) && (0 < p1 < 1) && (0 < p2 < 1) && (0 < p3 < 1) && (0 < q0 < 1) &&
(0 < q1 < 1) && (0 < q2 < 1) && (0 < q3 < 1) && (p0 + p1 + p2 + p3 == 1) &&
(q0 + q1 + q2 + q3 == 1)}, {p0, p1, p2, p3, q0, q1, q2, q3}]

{2., {p0 -> -7.93258*10^-10, p1 -> 0.5, p2 -> 0.5, p3 -> 0.,
q0 -> 0.5, q1 -> 0., q2 -> 0., q3 -> 0.5}}


You can see that the constraint does get violated (somewhat) in the p0 term which is effectively/numerically zero, but in reality slightly negative.

• Thanks. Sorry, but since I am new to mathematica stack exchange, I don't have enough rep yet to upvote your answer. Feb 11 '14 at 16:14