minimizes f numerically with respect to x.


minimizes f numerically with respect to x, y, .


minimizes f numerically subject to the constraints cons.


constrains x to be in the region reg.

Details and Options

  • NMinimize returns a list of the form {fmin,{x->xmin,y->ymin,}}.
  • cons can contain equations, inequalities, or logical combinations of these.
  • The constraints cons can be any logical combination of:
  • lhs==rhsequations
    lhs>rhs, lhsrhs, lhs<rhs, lhsrhsinequalities
    lhsrhs, lhsrhs, lhsrhs, lhsrhsvector inequalities
    {x,y,}regregion specification
  • NMinimize[{f,cons},xreg] is effectively equivalent to NMinimize[{f,consxreg},x].
  • For xreg, the different coordinates can be referred to using Indexed[x,i].
  • 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.
  • If NMinimize determines that the constraints cannot be satisfied, it returns {Infinity,{x->Indeterminate,}}.
  • The following options can be given:
  • AccuracyGoalAutomaticnumber of digits of final accuracy sought
    EvaluationMonitorNoneexpression to evaluate whenever f is evaluated
    MaxIterationsAutomaticmaximum 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.
  • NMinimize continues until either of the goals specified by AccuracyGoal or PrecisionGoal is achieved.
  • Possible settings for the Method option include "NelderMead", "DifferentialEvolution", "SimulatedAnnealing", and "RandomSearch".


open allclose all

Basic Examples  (3)

Find the global minimum of an unconstrained problem:

Extract the minimizing argument:

Find the global minimum of problems with constraints:

Minimize a function over a geometric region:

Plot it:

Scope  (9)

Or constraints can be specified:

Use NMinimize for linear objectives and constraints:

Integer constraints can be imposed:

Minimize over a region:

Plot it:

Find the minimum distance between two regions:

Plot it:

Find the minimum such that the triangle and ellipse still intersect:

Plot it:

Find the disk of minimum radius that contains the given three points:

Plot it:

Using Circumsphere gives the same result directly:

Use to specify that is a vector in :

Find the minimum distance between two regions:

Plot it:

Options  (6)

AccuracyGoal & PrecisionGoal  (2)

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:

EvaluationMonitor  (1)

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:

Method  (1)

Specifying a non-default method could give a better solution:

StepMonitor  (1)

Steps taken by NMinimize in finding the minimum of the classic Rosenbrock function:

WorkingPrecision  (1)

With the working precision set to , by default AccuracyGoal and PrecisionGoal are set to :

Properties & Relations  (4)

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:

Use RegionDistance and RegionNearest to compute the distance and the nearest point:

Both can be computed using NMinimize:

Use RegionBounds to compute the bounding box:

Use NMaximize and NMinimize to compute the same bounds:

Possible Issues  (3)

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:

Define a function that does numerical integration for a given parameter:

Compute with a parameter value of 2:

Applying the function to a symbolic parameter generates a message from NIntegrate:

This can also lead to warnings when the function is used with other numerical functions like NMinimize:

Define a function that only evaluates when its argument is a numerical value to avoid these messages:

Compute with a numerical value:

The function does not evaluate when its argument is non-numerical:

The function can now be used with other numerical functions such as NMinimize:

Wolfram Research (2003), NMinimize, Wolfram Language function, https://reference.wolfram.com/language/ref/NMinimize.html (updated 2014).


Wolfram Research (2003), NMinimize, Wolfram Language function, https://reference.wolfram.com/language/ref/NMinimize.html (updated 2014).


@misc{reference.wolfram_2020_nminimize, author="Wolfram Research", title="{NMinimize}", year="2014", howpublished="\url{https://reference.wolfram.com/language/ref/NMinimize.html}", note=[Accessed: 12-May-2021 ]}


@online{reference.wolfram_2020_nminimize, organization={Wolfram Research}, title={NMinimize}, year={2014}, url={https://reference.wolfram.com/language/ref/NMinimize.html}, note=[Accessed: 12-May-2021 ]}


Wolfram Language. 2003. "NMinimize." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2014. https://reference.wolfram.com/language/ref/NMinimize.html.


Wolfram Language. (2003). NMinimize. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/NMinimize.html