4
$\begingroup$

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.

$\endgroup$
3
  • 3
    $\begingroup$ It appears that using machine precision numbers (e.g., 0.5) causes Maximize to invoke NMaximize. Performing NMaximize[4*(x^(1/2) + y^(1/2))^2, 5 x + 4 y == 170, {x, y}] gives the same error. $\endgroup$
    – bbgodfrey
    Oct 7, 2016 at 22:05
  • 2
    $\begingroup$ This works: 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$
    – corey979
    Oct 7, 2016 at 22:08
  • 3
    $\begingroup$ To elaborate on my earlier comment, Maximize definitely calls NMaximize, when finite-precision numbers are used. According to its documentation, Maximize excludes function arguments that lead to complex numbers, but the NMaximize 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$
    – bbgodfrey
    Oct 7, 2016 at 23:09

1 Answer 1

3
$\begingroup$

From the docs for Maximize:

  • If Maximize is given an expression containing approximate numbers, it automatically calls NMaximize.

That the functions Maximize[] and NMaximize[] have different algorithms is well-documented.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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