Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Calling:

Minimize[{-0.4877 - 0.1190 r^2 - 0.1885 r^4 + 2.9703 z - 0.5531 z^2,
          0 <= z <= 3.5 ∧ 0 <= r <= 1.75}, {r, z}]

returns {1.00051, {r -> 1.75, z -> 3.5}}, when it's obvious that simply setting r and z to 0 yields -0.4877.

Is this an issue of numerical instability? Is there anything that can be done about it?

share|improve this question
3  
Seems like a failure of the default "NelderMead" method. If I change the RandomSeed, it works: NMinimize[{-0.4877 - 0.1190 r^2 - 0.1885 r^4 + 2.9703 z - 0.5531 z^2, 0 <= z < 3.5, 0 <= r < 1.75}, {r, z}, Method -> {"NelderMead", RandomSeed -> 1}]. Switching to "DifferentialEvolution" or "SimulatedAnnealing" gives the right answer, too. –  J. M. May 3 '13 at 3:40
    
@J.M. Also works with DifferentialEvolution. NelderMead can get stuck in local minima depending on how large the initial simplex is. Or in this case, gets stuck at the boundary condition. –  kale May 3 '13 at 3:41
2  
Minimize uses exact methods and gets confused here due to the machine-precision values. Try SetPrecision[Unevaluated[...], Infinity], which produces {-(6041450097168177621/2305843009213693952), {r -> 7/4, z -> 0}}. –  Oleksandr R. May 3 '13 at 3:42
4  
(Yes, I deliberately used NMinimize[], since Minimize[] switches to the use of NMinimize[] in the presence of inexact numbers. If you Rationalize[] your polynomial's coefficients, you might see something you'd prefer.) –  J. M. May 3 '13 at 3:42
1  
@J.M. would you mind posting an answer to that effect? This note is easy to miss (I missed it...) and the behavior is very surprising, so I think it's warranted to call attention to it. –  Oleksandr R. May 3 '13 at 10:12
show 4 more comments

1 Answer

up vote 5 down vote accepted

As noted in the docs, when given any input that contains inexact numbers, Minimize[] automagically switches to the use of NMinimize[], which, as you might surmise from its name, uses approximate methods instead of exact ones. With this, the failure you see is due to the Nelder-Mead method, which is the default method used by NMinimize[].

If you're angling for exact solutions, then you certainly should be supplying exact input (GIGO). In that regard, Rationalize[] is a rather handy thing:

Minimize[{-0.4877 - 0.1190 r^2 - 0.1885 r^4 + 2.9703 z - 0.5531 z^2,
          0 <= z <= 3.5 ∧ 0 <= r <= 1.75} // Rationalize, {r, z}]
   {-6707357/2560000, {r -> 7/4, z -> 0}}

If one is fine with an approximate solution (which is often much easier to obtain), and the default settings are not up to snuff, then one way to angle for a possibly better answer from the built-in optimization methods is to change the RandomSeed option. To wit,

NMinimize[{-0.4877 - 0.1190 r^2 - 0.1885 r^4 + 2.9703 z - 0.5531 z^2, 
           0 <= z <= 3.5 ∧ 0 <= r <= 1.75}, {r, z},
          Method -> {Automatic, RandomSeed -> 1}] // Chop
   {-2.6200613281250007, {r -> 1.75, z -> 0}}

Another route is to change the default method. For instance,

NMinimize[{-0.4877 - 0.1190 r^2 - 0.1885 r^4 + 2.9703 z - 0.5531 z^2, 
           0 <= z <= 3.5 ∧ 0 <= r <= 1.75}, {r, z},
          Method -> "SimulatedAnnealing"] // Chop
   {-2.6200613281250007, {r -> 1.75, z -> 0}}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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