NMinimize
NMinimize[f,x]
minimizes f numerically with respect to x.
NMinimize[f,{x,y,…}]
minimizes f numerically with respect to x, y, ….
NMinimize[{f,cons},{x,y,…}]
minimizes f numerically subject to the constraints cons.
NMinimize[…,x∈reg]
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==rhs equations lhs>rhs, lhs≥rhs, lhs<rhs, lhs≤rhs inequalities lhsrhs, lhsrhs, lhsrhs, lhsrhs vector inequalities {x,y,…}∈reg region specification - NMinimize[{f,cons},x∈reg] is effectively equivalent to NMinimize[{f,cons∧x∈reg},x].
- For x∈reg, 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.
- x∈Integers 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:
-
AccuracyGoal Automatic number of digits of final accuracy sought EvaluationMonitor None expression to evaluate whenever f is evaluated MaxIterations Automatic maximum number of iterations to use Method Automatic method to use PrecisionGoal Automatic number of digits of final precision sought StepMonitor None expression to evaluate whenever a step is taken WorkingPrecision MachinePrecision the 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".
Examples
open allclose allBasic Examples (3)
Scope (9)
Or constraints can be specified:
Use NMinimize for linear objectives and constraints:
Integer constraints can be imposed:
Find the minimum distance between two regions:
Find the minimum such that the triangle and ellipse still intersect:
Find the disk of minimum radius that contains the given three points:
Using Circumsphere gives the same result directly:
Use to specify that
is a vector in
:
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)
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:
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:
Text
Wolfram Research (2003), NMinimize, Wolfram Language function, https://reference.wolfram.com/language/ref/NMinimize.html (updated 2014).
BibTeX
BibLaTeX
CMS
Wolfram Language. 2003. "NMinimize." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2014. https://reference.wolfram.com/language/ref/NMinimize.html.
APA
Wolfram Language. (2003). NMinimize. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/NMinimize.html