MATHEMATICA TUTORIAL

Comparison of Constrained Optimization Functions

NMinimize, NMaximize, Minimize, and Maximize employ global optimization algorithms, and are thus suitable when a global optimum is needed.

Minimize and Maximize can find exact global optima for a class of optimization problems containing arbitrary polynomial problems. However, the algorithms used have a very high asymptotic complexity and therefore are suitable only for problems with a small number of variables.

Maximize always finds a global maximum, even in cases that are numerically unstable. The left-hand side of the constraint here is .
In[1]:=
Click for copyable input
Out[1]=
This input differs from the previous one only in the twenty-first decimal digit, but the answer is quite different, especially the location of the maximum point. For an algorithm using 16 digits of precision both problems look the same, hence it cannot possibly solve them both correctly.
In[2]:=
Click for copyable input
Out[2]=
NMaximize, which by default uses machine-precision numbers, is not able to solve either of the problems.
In[3]:=
Click for copyable input
Out[3]=
In[4]:=
Click for copyable input
Out[4]=

FindMinimum only attempts to find a local minimum, therefore is suitable when a local optimum is needed, or when it is known in advance that the problem has only one optimum or only a few optima that can be discovered using different starting points.

Even for local optimization, it may still be worth using NMinimize for small problems. NMinimize uses one of the four direct search algorithms (Nelder-Mead, differential evolution, simulated annealing, and random search), then fine-tunes the solution by using a combination of KKT solution, the interior point, and a penalty method. So if efficiency is not an issue, NMinimize should be more robust than FindMinimum, in addition to being a global optimizer.

This shows the default behavior of NMinimize on a problem with four variables.

In[5]:=
Click for copyable input
Out[9]=

This shows that two of the post-processors, KKT and FindMinimum, do not give the default result. Notice that for historical reasons, the name FindMinimum, when used as an option value of , stands for the process where a penalty method is used to convert the constrained optimization problem into unconstrained optimization methods and then solved using (unconstrained) FindMinimum.

In[10]:=
Click for copyable input
Out[10]=
In[11]:=
Click for copyable input
Out[11]=

However, if efficiency is important, FindMinimum can be used if you just need a local minimum, or you can provide a good starting point, or you know the problem has only one minimum (e.g., convex), or your problem is large/expensive. This uses FindMinimum and NMinimize to solve the same problem with seven variables. The constraints are relatively expensive to compute. Clearly FindMinimum in this case is much faster than NMinimize.

In[12]:=
Click for copyable input
In[14]:=
Click for copyable input
Out[14]=
In[15]:=
Click for copyable input
Out[15]=
New to Mathematica? Find your learning path »
Have a question? Ask support »