I'm doing a constrained optimization function, where I maximize a function with two arguments subject to a simple constraint:
Maximize[4*(x^(1/2) + y^(1/2))^2, 5 x + 4 y == 170, {x, y}]
This successfully returns
{306, {x -> 136/9, y -> 425/18}}
This is great. No problem here. But, when I simply replace the power (1/2) with (0.5), as follows,
Maximize[4*(x^(0.5) + y^(0.5))^2, 5 x + 4 y == 170, {x, y}]
I get the following errors:
NMaximize::nrnum: The function value -33.8342-10.7215 I is not a real number at {x,y} = {34.6632,-0.829053}. >>
NMaximize::nrnum: The function value -33.8342-10.7215 I is not a real number at {x,y} = {34.6632,-0.829053}. >>
NMaximize::nrnum: The function value -33.8342-10.7215 I is not a real number at {x,y} = {34.6632,-0.829053}. >>
Further output of NMaximize::nrnum will be suppressed during this calculation. >>
What's the matter here? I'm very new to mathematica and I don't understand if this is a syntax error or a mathematical error. Any ideas most appreciated.
Maximize
to invokeNMaximize
. PerformingNMaximize[4*(x^(1/2) + y^(1/2))^2, 5 x + 4 y == 170, {x, y}]
gives the same error. $\endgroup$Maximize[4*(x^(0.5) + y^(0.5))^2, 5 x + 4 y == 170 && x > 0 && y > 0, {x, y}]
, although I find it peculiar. $\endgroup$Maximize
definitely callsNMaximize
, when finite-precision numbers are used. According to its documentation,Maximize
excludes function arguments that lead to complex numbers, but theNMaximize
documentation is silent on this point. Evidently,NMaximize
does not exclude arguments that lead to complex numbers, and so it fails when they occur. $\endgroup$