0
$\begingroup$

I try to find a maximum of a function using:

FindMaximum[{Log[81 x + 19] + Log[80 y + 20] + Log[60 (1 - x - y) + 40], 
            0 < x < 1, 0 < y < 1, x + y < 1}, {x, y}]

I get an error message:

FindMaximum::nrnum: The function value -11.1219-3.14159 I is not a real number at {x,y} = {0.9,0.9}.

Sure, it is not a real number since $60(1-x-y)-40<0$. But why did FindMaximum even tried these values? They are outside the range $x+y<1$!

Is there a way to tell FindMaximum to only look inside the range?

$\endgroup$
  • $\begingroup$ As an alternative, NMaximize works with your system with no errors. Additionally, if you provide a better starting point than the one selected automatically, FindMaximum works as well: FindMaximum[{Log[81 x + 19] + Log[80 y + 20] + Log[60 (1 - x - y) + 40], 0 < x < 1, 0 < y < 1, x + y < 1}, {{x, 0.5}, {y, 0.4}}] returns {11.8731, {x -> 0.48251, y -> 0.467078}}. $\endgroup$ – MarcoB May 4 '18 at 8:35
  • 1
    $\begingroup$ @MarcoB yes, NMaximize works, but since my goal functions are convex, I think that FindMaximum should work faster. I also tried to change the initial values and it worked, but I do not understand why Mathematica tries values outside the range at all? $\endgroup$ – Erel Segal-Halevi May 4 '18 at 8:43
  • 1
    $\begingroup$ I don't know why MMA can't find a starting value, but you could provide a starting value. FindMaximum[{Log[81 x + 19] + Log[80 y + 20] + Log[60 (1 - x - y) + 40], 0 <= x <= 1, 0 <= y <= 1, x + y <= 1}, {{x, 0}, {y, 0} } ] evaluates the result without error message. $\endgroup$ – Ulrich Neumann May 4 '18 at 9:19
  • 1
    $\begingroup$ Maybe choosing the starting point for numerical optimization algorithms is too vital to leave it to a dull machine? ;) $\endgroup$ – Henrik Schumacher May 4 '18 at 9:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.