This is documentation for Mathematica 8, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.2)

NMinimize

NMinimize
minimizes f numerically with respect to x.
NMinimize
minimizes f numerically with respect to x, y, ....
NMinimize
minimizes f numerically subject to the constraints cons.
  • cons can contain equations, inequalities, or logical combinations of these.
  • NMinimize always attempts to find a global minimum of f subject to the constraints given.
  • By default, all variables are assumed to be real.
  • xIntegers can be used to specify that a variable can take on only integer values.
  • If f and cons are linear, NMinimize can always find global minima, over both real and integer values.
  • Otherwise, NMinimize may sometimes find only a local minimum.
  • The following options can be given:
AccuracyGoalAutomaticnumber of digits of final accuracy sought
EvaluationMonitorNoneexpression to evaluate whenever f is evaluated
MaxIterations100maximum number of iterations to use
MethodAutomaticmethod to use
PrecisionGoalAutomaticnumber of digits of final precision sought
StepMonitorNoneexpression to evaluate whenever a step is taken
WorkingPrecisionMachinePrecisionthe precision used in internal computations
  • The settings for AccuracyGoal and PrecisionGoal specify the number of digits to seek in both the value of the position of the minimum, and the value of the function at the minimum.
  • Possible settings for the Method option include , , , and .
Find the global minimum of an unconstrained problem:
Extract the minimizing argument:
Find the global minimum of problems with constraints:
Find the global minimum of an unconstrained problem:
In[1]:=
Click for copyable input
Out[1]=
Extract the minimizing argument:
In[2]:=
Click for copyable input
Out[2]=
 
Find the global minimum of problems with constraints:
In[1]:=
Click for copyable input
Out[1]=
In[2]:=
Click for copyable input
Out[2]=
Or constraints can be specified:
Use NMinimize for linear objectives and constraints:
Integer constraints can be imposed:
This enforces a convergence criteria and :
This enforces a convergence criteria and , which is not achievable with the default machine-precision computation:
Setting a high WorkingPrecision makes the process convergent:
Record all the points evaluated during the solution process of a function with a ring of minima:
Plot all the visited points that are close in objective function value to the final solution:
Specifying a non-default method could give a better solution:
Steps taken by NMinimize in finding the minimum of the classic Rosenbrock function:
With the working precision set to , by default AccuracyGoal and PrecisionGoal are set to :
NMinimize aims to find a global minimum, while FindMinimum attempts to find a local minimum:
Minimize finds a global minimum and can work in infinite precision:
FindFit can use NMinimize to find the global optimal fit. This sets up a model:
Create a function from the model and parameters, and generate sample points:
By default FindFit only finds the local optimal fit:
Using the NMinimize method finds the global optimal fit:
For nonlinear functions, NMinimize may sometimes find only a local minimum:
Specifying a starting interval can help in achieving a better local minimum:
NMinimize finds a local minimum of a two-dimensional function on a disk:
Specifying a starting interval helps in achieving the global minimum:
Solve cannot work with this system of equations because they are highly nonalgebraic:
Use NMinimize with a trivial objective function to find a solution:
New in 5 | Last modified in 6