NMinimize
✖
NMinimize

searches for a global minimum in f numerically subject to the constraints cons.
Details and Options




- NMinimize is also known as global optimization (GO).
- NMinimize always attempts to find a global minimum of f subject to the constraints given.
- NMinimize is typically used to find the smallest possible values given constraints. In different areas, this may be called the best strategy, best fit, best configuration and so on.
- NMinimize returns a list of the form {fmin,{x->xmin,y->ymin,…}}.
- If f and cons are linear or convex, the result given by NMinimize will be the global minimum, over both real and integer values; otherwise, the result may sometimes only be a local minimum.
- If NMinimize determines that the constraints cannot be satisfied, it returns {Infinity,{x->Indeterminate,…}}.
- NMinimize supports a modeling language where the objective function f and constraints cons are given in terms of expressions depending on scalar or vector variables. f and cons are typically parsed into very efficient forms, but as long as f and the terms in cons give numerical values for numerical values of the variables, NMinimize can often find a solution.
- The constraints cons can be any logical combination of:
-
lhs==rhs equations lhs>rhs, lhs≥rhs, lhs<rhs, lhs≤rhs inequalities (LessEqual, …) lhsrhs, lhsrhs, lhsrhs, lhsrhs vector inequalities (VectorLessEqual, …) {x,y,…}∈rdom region or domain specification - NMinimize[{f,cons},x∈rdom] is effectively equivalent to NMinimize[{f,cons&&x∈rdom},x].
- For x∈rdom, the different coordinates can be referred to using Indexed[x,i].
- Possible domains rdom include:
-
Reals real scalar variable Integers integer scalar variable Vectors[n,dom] vector variable in Matrices[{m,n},dom] matrix variable in ℛ vector variable restricted to the geometric region - By default, all variables are assumed to be real.
- 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.
- The methods for NMinimize fall into two classes.The first class of guaranteed methods uses properties of the problem so that, when the method converges, the minimum found is guaranteed to be global. The second class of heuristic methods uses methods that may include multiple local searches, commonly adjusted by some stochasticity, to home in on a global minimum. These methods often do find the global minimum, but are not guaranteed to do so.
- Methods that are guaranteed to give a global minimum when they converge to a solution include:
-
"Convex" use only convex methods "MOSEK" use the commercial MOSEK library for convex problems "Gurobi" use the commercial Gurobi library for convex problems "Xpress" use the commercial Xpress library for convex problems - Heuristic methods include:
-
"NelderMead" simplex method of Nelder and Mead "DifferentialEvolution" use differential evolution "SimulatedAnnealing" use simulated annealing "RandomSearch" use the best local minimum found from multiple random starting points "Couenne" use the Couenne library for non-convex mixed-integer nonlinear problems

Examples
open allclose allBasic Examples (3)Summary of the most common use cases
Find the global minimum of an unconstrained problem:

https://wolfram.com/xid/0c13vyy-259qe9

Extract the minimizing argument:

https://wolfram.com/xid/0c13vyy-z1qh05

Find the global minimum of problems with constraints:

https://wolfram.com/xid/0c13vyy-oybm7f


https://wolfram.com/xid/0c13vyy-3drma4

Minimize a function over a geometric region:

https://wolfram.com/xid/0c13vyy-ewyjra


https://wolfram.com/xid/0c13vyy-bema4a

Scope (40)Survey of the scope of standard use cases
Basic Uses (12)
Minimize subject to constraints
:

https://wolfram.com/xid/0c13vyy-edj208

Several linear inequality constraints can be expressed with VectorGreaterEqual:

https://wolfram.com/xid/0c13vyy-pjuvi

Use v>=
or \[VectorGreaterEqual] to enter the vector inequality sign :

https://wolfram.com/xid/0c13vyy-ivyhv5

An equivalent form using scalar inequalities:

https://wolfram.com/xid/0c13vyy-ib8bsr


https://wolfram.com/xid/0c13vyy-lu8fwi

The inequality may not be the same as
due to possible threading in
:

https://wolfram.com/xid/0c13vyy-wfe84


https://wolfram.com/xid/0c13vyy-cdrbb6

To avoid unintended threading in , use Inactive[Plus]:

https://wolfram.com/xid/0c13vyy-i1qbdu

Use constant parameter equations to avoid unintended threading in :

https://wolfram.com/xid/0c13vyy-dd18z3

https://wolfram.com/xid/0c13vyy-69739j

VectorGreaterEqual represents a conic inequality with respect to the "NonNegativeCone":

https://wolfram.com/xid/0c13vyy-c8jcv

To explicitly specify the dimension of the cone, use {"NonNegativeCone",n}:

https://wolfram.com/xid/0c13vyy-ej00nr


https://wolfram.com/xid/0c13vyy-bhykun

Minimize subject to the constraint
:

https://wolfram.com/xid/0c13vyy-6o2li

Specify the constraint using a conic inequality with "NormCone":

https://wolfram.com/xid/0c13vyy-n3a57


https://wolfram.com/xid/0c13vyy-jmkzci

Minimize the function subject to the constraint
:

https://wolfram.com/xid/0c13vyy-v9guvz
Use Indexed to access components of a vector variable, e.g. :

https://wolfram.com/xid/0c13vyy-p46cfv

Use Vectors[n,dom] to specify the dimension and domain of a vector variable when it is ambiguous:

https://wolfram.com/xid/0c13vyy-9kphq



https://wolfram.com/xid/0c13vyy-ev6iib

Specify non-negative constraints using NonNegativeReals ():

https://wolfram.com/xid/0c13vyy-bsy75

An equivalent form using vector inequality :

https://wolfram.com/xid/0c13vyy-uobom

Specify non-positive constraints using NonPositiveReals ():

https://wolfram.com/xid/0c13vyy-domqhv

An equivalent form using vector inequalities:

https://wolfram.com/xid/0c13vyy-bim93z

Or constraints can be specified:

https://wolfram.com/xid/0c13vyy-5d9hck

Domain Constraints (4)
Specify integer domain constraints using Integers:

https://wolfram.com/xid/0c13vyy-xi06kw

Specify integer domain constraints on vector variables using Vectors[n,Integers]:

https://wolfram.com/xid/0c13vyy-df5n5z

Specify non-negative integer domain constraints using NonNegativeIntegers ():

https://wolfram.com/xid/0c13vyy-2eforb

Specify non-positive integer domain constraints using NonPositiveIntegers ():

https://wolfram.com/xid/0c13vyy-f0btvc

Region Constraints (5)

https://wolfram.com/xid/0c13vyy-q0zuo5

https://wolfram.com/xid/0c13vyy-2td19x


https://wolfram.com/xid/0c13vyy-km0bgb

Find the minimum distance between two regions:

https://wolfram.com/xid/0c13vyy-pdj8lj

https://wolfram.com/xid/0c13vyy-s3co46


https://wolfram.com/xid/0c13vyy-84l57

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

https://wolfram.com/xid/0c13vyy-lo12o0

https://wolfram.com/xid/0c13vyy-zsebb7


https://wolfram.com/xid/0c13vyy-xab24k

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

https://wolfram.com/xid/0c13vyy-9e2uly

https://wolfram.com/xid/0c13vyy-c8m024


https://wolfram.com/xid/0c13vyy-cy01if

Using Circumsphere gives the same result directly:

https://wolfram.com/xid/0c13vyy-3up20f

Use to specify that
is a vector in
with
:

https://wolfram.com/xid/0c13vyy-gf8ag3

https://wolfram.com/xid/0c13vyy-sz8ksq

Linear Problems (5)
With linear objectives and constraints, when a minimum is found it is global:

https://wolfram.com/xid/0c13vyy-rx665t

The constraints can be equality and inequality constraints:

https://wolfram.com/xid/0c13vyy-7grjvm

Use Equal to express several equality constraints at once:

https://wolfram.com/xid/0c13vyy-dkthbi

An equivalent form using several scalar equalities:

https://wolfram.com/xid/0c13vyy-s527v9

Use VectorLessEqual to express several LessEqual inequality constraints at once:

https://wolfram.com/xid/0c13vyy-s5e3zm

Use v<=
to enter the vector inequality in a compact form:

https://wolfram.com/xid/0c13vyy-0mtyw2

An equivalent form using scalar inequalities:

https://wolfram.com/xid/0c13vyy-b9pt3y

Use Interval to specify bounds on variable:

https://wolfram.com/xid/0c13vyy-d31yau

Convex Problems (7)
Use "NonNegativeCone" to specify linear functions of the form :

https://wolfram.com/xid/0c13vyy-hazv2m

Use v>=
to enter the vector inequality in a compact form:

https://wolfram.com/xid/0c13vyy-2347tx

Minimize a convex quadratic function subject to linear constraints:

https://wolfram.com/xid/0c13vyy-16jara

Plot the region and minimizing point:

https://wolfram.com/xid/0c13vyy-psub9m

Minimize a convex quadratic function subject to a set of convex quadratic constraints:

https://wolfram.com/xid/0c13vyy-d5t5gt

Plot the region and the minimizing point:

https://wolfram.com/xid/0c13vyy-hby7uw

Find the minimum distance between two convex regions:

https://wolfram.com/xid/0c13vyy-q5zkfc

https://wolfram.com/xid/0c13vyy-pegha4


https://wolfram.com/xid/0c13vyy-12d5ff

Minimize such that
is positive semidefinite:

https://wolfram.com/xid/0c13vyy-dysqdc

Show the minimizer on a plot of the objective function:

https://wolfram.com/xid/0c13vyy-d03jbw

Minimize the convex objective function such that
is positive semidefinite and
:

https://wolfram.com/xid/0c13vyy-ml87f0

Plot the region and the minimizing point:

https://wolfram.com/xid/0c13vyy-5jo4bk

Minimize a convex objective function over a 4-norm unit disk:

https://wolfram.com/xid/0c13vyy-9j1nn4

Plot the region and the minimizing point:

https://wolfram.com/xid/0c13vyy-r37z05

Transformable to Convex (4)
Minimize the perimeter of a rectangle such that the area is 1 and the height is at most half the width:

https://wolfram.com/xid/0c13vyy-kwgi5j

This problem is log-convex and is solved by making a transformation {hExp[],wExp[ ]} and taking logarithms to get the convex problem:

https://wolfram.com/xid/0c13vyy-b0ytfy


https://wolfram.com/xid/0c13vyy-bgq1bz

Minimize the quasi-convex function subject to inequality and norm constraints. The objective is quasi-convex because it is a product of a non-negative function and a non-positive function over the domain:

https://wolfram.com/xid/0c13vyy-7xu2gh

Quasi-convex problems can be solved as a parametric convex optimization problem for the parameter :

https://wolfram.com/xid/0c13vyy-nz65dn

Plot the objective as a function of the level-set :

https://wolfram.com/xid/0c13vyy-xywf20

For a level-set value between the interval , the smallest objective is found:

https://wolfram.com/xid/0c13vyy-6qmx0s

The problem becomes infeasible when the level-set value is increased:

https://wolfram.com/xid/0c13vyy-y29e3i


Minimize subject to the constraint
. The objective is not convex but can be represented by a difference of convex function
where
and
are convex functions:

https://wolfram.com/xid/0c13vyy-ybo4h2

Plot the region and the minimizing point:

https://wolfram.com/xid/0c13vyy-f0dmil

Minimize subject to the constraints
. The constraint
is not convex but can be represented by a difference of convex constraint
where
and
are convex functions:

https://wolfram.com/xid/0c13vyy-6vzg6m

Plot the region and the minimizing point:

https://wolfram.com/xid/0c13vyy-2fcv6g

General Problems (3)
Minimize a linear objective subject to nonlinear constraints:

https://wolfram.com/xid/0c13vyy-oy13fx


https://wolfram.com/xid/0c13vyy-hipvc2

Minimize a nonlinear objective subject to linear constraints:

https://wolfram.com/xid/0c13vyy-tryoht

Plot the objective and the minimizing point:

https://wolfram.com/xid/0c13vyy-3f3e17

Minimize a nonlinear objective subject to nonlinear constraints:

https://wolfram.com/xid/0c13vyy-yuruh0


https://wolfram.com/xid/0c13vyy-t4po46

Options (10)Common values & functionality for each option
AccuracyGoal & PrecisionGoal (2)
This enforces a convergence criteria and
:

https://wolfram.com/xid/0c13vyy-05x0hq

This enforces a convergence criteria and
, which is not achievable with the default machine-precision computation:

https://wolfram.com/xid/0c13vyy-ykixh5


Setting a high WorkingPrecision makes the process convergent:

https://wolfram.com/xid/0c13vyy-xk2rz

EvaluationMonitor (1)
Method (5)
Some methods may give suboptimal results for certain problems:

https://wolfram.com/xid/0c13vyy-yj6jpj

The automatically chosen method gives the optimal solution for this problem:

https://wolfram.com/xid/0c13vyy-gtevm2

The automatic method choice for this nonconvex problem is method "Couenne":

https://wolfram.com/xid/0c13vyy-giin73

Plot the solution along with the global minima:

https://wolfram.com/xid/0c13vyy-b2ch0

Find the global minimum of a function containing multiple local minima using method "Couenne":

https://wolfram.com/xid/0c13vyy-78qi0q

Plot the minimizing function and the global minimum solution:

https://wolfram.com/xid/0c13vyy-8nr1wn

Use method "NelderMead" for problems with many variables when speed is essential:

https://wolfram.com/xid/0c13vyy-cdle4a

Use method "Convex" or Except["Convex"] to specify if a convex method should be used or not:

https://wolfram.com/xid/0c13vyy-z6wce

Use method "Couenne" or Except["Couenne"] to choose or exclude the Couenne solver:

https://wolfram.com/xid/0c13vyy-g812rx

StepMonitor (1)
Steps taken by NMinimize in finding the minimum of the classic Rosenbrock function:

https://wolfram.com/xid/0c13vyy-znwwtn

https://wolfram.com/xid/0c13vyy-mfc57g

WorkingPrecision (1)
With the working precision set to , by default AccuracyGoal and PrecisionGoal are set to
:

https://wolfram.com/xid/0c13vyy-9rwm4o

Applications (19)Sample problems that can be solved with this function
Geometry Problems (4)
Find the minimum distance between two disks of radius 1 centered at and
. Let
be a point on disk 1. Let
be a point on disk 2. The objective is to minimize
subject to constraints
:

https://wolfram.com/xid/0c13vyy-x0rc5a

Visualize the positions of the two points:

https://wolfram.com/xid/0c13vyy-u44093

Find the radius and center
of a minimal enclosing ball that encompasses a given region:

https://wolfram.com/xid/0c13vyy-1xi3kb
Minimize the radius subject to the constraints
:

https://wolfram.com/xid/0c13vyy-fmr9yi

https://wolfram.com/xid/0c13vyy-rvv1lu


https://wolfram.com/xid/0c13vyy-uhd7v9

The minimal enclosing ball can be found efficiently using BoundingRegion:

https://wolfram.com/xid/0c13vyy-1dvvd5

Find the smallest ellipsoid parametrized as that encompasses a set of points in 3D by minimizing the volume:

https://wolfram.com/xid/0c13vyy-pjykdi
For each point , the constraint
must be satisfied:

https://wolfram.com/xid/0c13vyy-nc9kzf
Minimizing the volume is equivalent to minimizing :

https://wolfram.com/xid/0c13vyy-x3f6aq

Convert the parametrized ellipse into the explicit form :

https://wolfram.com/xid/0c13vyy-ez4q1q


https://wolfram.com/xid/0c13vyy-48kw5a

A bounding ellipsoid, not necessarily minimum volume, can also be found using BoundingRegion:

https://wolfram.com/xid/0c13vyy-7j1lcp


https://wolfram.com/xid/0c13vyy-e4z5ec

Find the smallest square that can contain circles of given radius
for
that do not overlap. Specify the number of circles and the radius of each circle:

https://wolfram.com/xid/0c13vyy-m2255i
If is the center of circle
, then the objective is to minimize
. The objective can be transformed so as to minimize
and
:

https://wolfram.com/xid/0c13vyy-t7gqfm

https://wolfram.com/xid/0c13vyy-22nk9i

https://wolfram.com/xid/0c13vyy-yemsm5

https://wolfram.com/xid/0c13vyy-fazut5

The circles are contained in the square :

https://wolfram.com/xid/0c13vyy-obfv8i

Compute the fraction of square covered by the circles:

https://wolfram.com/xid/0c13vyy-40ke7i

Data-Fitting Problems (3)
Minimize subject to the constraints
for a given matrix a and vector b:

https://wolfram.com/xid/0c13vyy-sqawoj

https://wolfram.com/xid/0c13vyy-cen26w

Fit a cubic curve to discrete data such that the first and last points of the data lie on the curve:

https://wolfram.com/xid/0c13vyy-znbwtk
Construct the matrix using DesignMatrix:

https://wolfram.com/xid/0c13vyy-7u326f
Define the constraint so that the first and last points must lie on the curve:

https://wolfram.com/xid/0c13vyy-6h1xyq
Find the coefficients by minimizing
:

https://wolfram.com/xid/0c13vyy-4jv0wc


https://wolfram.com/xid/0c13vyy-elazro

Find a fit less sensitive to outliers to nonlinear discrete data by minimizing :

https://wolfram.com/xid/0c13vyy-5edia8
Fit the data using the bases . The interpolating function will be
:

https://wolfram.com/xid/0c13vyy-0el18p

https://wolfram.com/xid/0c13vyy-b64kk9


https://wolfram.com/xid/0c13vyy-smzt60

Compare the interpolating function with the reference function:

https://wolfram.com/xid/0c13vyy-c1na99

Classification Problems (5)
Find a line that separates two groups of points
and
:

https://wolfram.com/xid/0c13vyy-mq8mpw
For separation, set 1 must satisfy and set 2 must satisfy
:

https://wolfram.com/xid/0c13vyy-wz5f21
The objective is to minimize , which gives twice the thickness between
and
:

https://wolfram.com/xid/0c13vyy-huxo4m


https://wolfram.com/xid/0c13vyy-mm9axc


https://wolfram.com/xid/0c13vyy-qddxuk

Find a quadratic polynomial that separates two groups of 3D points and
:

https://wolfram.com/xid/0c13vyy-0kz712

Construct the quadratic polynomial data matrices for the two sets using DesignMatrix:

https://wolfram.com/xid/0c13vyy-r437k9
For separation, set 1 must satisfy and set 2 must satisfy
:

https://wolfram.com/xid/0c13vyy-602x47
Find the separating polynomial by minimizing :

https://wolfram.com/xid/0c13vyy-5mvu05

The polynomial separating the two groups of points is:

https://wolfram.com/xid/0c13vyy-1vrepp

Plot the polynomial separating the two datasets:

https://wolfram.com/xid/0c13vyy-v2nioo

Separate a given set of points into different groups. This is done by finding the centers
for each group by minimizing
, where
is a given local kernel and
is a given penalty parameter:

https://wolfram.com/xid/0c13vyy-faena0
The kernel is a
-nearest neighbor (
) function such that
, else
. For this problem,
nearest neighbors are selected:

https://wolfram.com/xid/0c13vyy-g2rd9z

https://wolfram.com/xid/0c13vyy-he6ucu

https://wolfram.com/xid/0c13vyy-kcaa0u
For each data point, there exists a corresponding center. Data belonging to the same group will have the same center value:

https://wolfram.com/xid/0c13vyy-dl9y86

Extract and plot the grouped points:

https://wolfram.com/xid/0c13vyy-feehz1

Given a list of positive integers, partition the list into two non-overlapping subsets such that the difference between the sums of the two subsets is minimized. Define the list:

https://wolfram.com/xid/0c13vyy-cuxkte

Define a binary variable that takes the values –1 or 1. If an element from the list belongs to subset 1, then the binary variable associated with it is given a value of –1. For subset 2, the associated binary variable is 1:

https://wolfram.com/xid/0c13vyy-i2ixqt
The objective is to minimize the difference of sums of the two subsets:

https://wolfram.com/xid/0c13vyy-ixro3a

https://wolfram.com/xid/0c13vyy-bjn86a

Given a collection of objects with different weights and two bags, find the objects with a maximum combined weight that can go into the two bags without exceeding the weight capacity of the bags. Define the number of objects and weights:

https://wolfram.com/xid/0c13vyy-es8213

Use binary variables to decide if an object goes into bag 1 or 2, or neither:

https://wolfram.com/xid/0c13vyy-rs5gk6
The weight capacity of each bag is 5000:

https://wolfram.com/xid/0c13vyy-4a9hz1
The objective is to maximize the weights of the objects in the two bags:

https://wolfram.com/xid/0c13vyy-r66m38

https://wolfram.com/xid/0c13vyy-3dqios

The binary variable is associated with the objects that go into bag 1. The variable
is the complement of
. The weights in the bags are:

https://wolfram.com/xid/0c13vyy-wqv4ez

Image Processing (1)
Recover a corrupted image by finding an image that is closest under the total variation norm:

https://wolfram.com/xid/0c13vyy-0szo9

Create a corrupted image by randomly deleting 40% of the data points.

https://wolfram.com/xid/0c13vyy-b3v1nu

The objective is to minimize , where
is the image data:

https://wolfram.com/xid/0c13vyy-bmz6mt
Assume that any nonzero data points are uncorrupted. For these positions, set
:

https://wolfram.com/xid/0c13vyy-ga5ygg
Find the solution and show the restored image:

https://wolfram.com/xid/0c13vyy-nn9ycy

https://wolfram.com/xid/0c13vyy-kchhxt

Facility Location Problems (1)
Find the positions of various cell towers and the range
needed to serve clients located at
:

https://wolfram.com/xid/0c13vyy-432sb2
Each cell tower consumes power proportional to its range, which is given by . The objective is to minimize the power consumption:

https://wolfram.com/xid/0c13vyy-qnmsp6
Let be a decision variable indicating that
if client
is covered by cell tower
:

https://wolfram.com/xid/0c13vyy-yup7tp
Each cell tower must be located such that its range covers some of the clients:

https://wolfram.com/xid/0c13vyy-nw7y9g
Each cell tower can cover multiple clients:

https://wolfram.com/xid/0c13vyy-nb1u4e
Each cell tower has a minimum and maximum coverage:

https://wolfram.com/xid/0c13vyy-lbqs1t

https://wolfram.com/xid/0c13vyy-kz0tgg
Find the cell tower positions and their ranges:

https://wolfram.com/xid/0c13vyy-kftuk6

Extract cell tower position and range:

https://wolfram.com/xid/0c13vyy-yangc4
Visualize the positions and ranges of the towers with respect to client locations:

https://wolfram.com/xid/0c13vyy-7bdoho

Portfolio Optimization (1)
Find the distribution of capital to invest in six stocks to maximize return while minimizing risk:

https://wolfram.com/xid/0c13vyy-kut0cq
The return is given by , where
is a vector of expected return value of each individual stock:

https://wolfram.com/xid/0c13vyy-2z1lpt
The risk is given by ;
is a risk-aversion parameter and
:

https://wolfram.com/xid/0c13vyy-get9k6
The objective is to maximize return while minimizing risk for a specified risk-aversion parameter:

https://wolfram.com/xid/0c13vyy-61n2dz
The effect on market prices of stocks due to the buying and selling of stocks is modeled by :

https://wolfram.com/xid/0c13vyy-1k0oif
The weights must all be greater than 0 and the weights plus market impact costs must add to 1:

https://wolfram.com/xid/0c13vyy-vgdxhc
Compute the returns and corresponding risk for a range of risk-aversion parameters:

https://wolfram.com/xid/0c13vyy-4zi5kn
The optimal over a range of
gives an upper-bound envelope on the tradeoff between return and risk:

https://wolfram.com/xid/0c13vyy-3deaei

Compute the weights for a specified number of risk-aversion parameters:

https://wolfram.com/xid/0c13vyy-scqccb
By accounting for the market costs, a diversified portfolio can be obtained for low risk aversion, but when the risk aversion is high, the market impact cost dominates, due to purchasing a less diversified stock:

https://wolfram.com/xid/0c13vyy-18xvc1

Trajectory Optimization (1)
Find a path through circular obstacles such that the distance between the start and end points is minimized:

https://wolfram.com/xid/0c13vyy-b7tj3j

The path is discretized into different points with distance of
between points, where
is the trajectory length being minimized:

https://wolfram.com/xid/0c13vyy-518i2b
The points cannot be inside the circular objects:

https://wolfram.com/xid/0c13vyy-509nls
The start and end points are known:

https://wolfram.com/xid/0c13vyy-7yhvw9

https://wolfram.com/xid/0c13vyy-wofkjz
Minimize the length subject to the constraints:

https://wolfram.com/xid/0c13vyy-7o04by


https://wolfram.com/xid/0c13vyy-8fgbp9

Manufacturing Problems (3)
Find the number of teeth needed in the gears
, respectively, to produce a specified gear ratio:

Each gear can have between and
teeth:

https://wolfram.com/xid/0c13vyy-btivu3
For the given gear train configuration, the gear ratio is given by :

https://wolfram.com/xid/0c13vyy-xqtjwz
Find the number of teeth in each gear to achieve the gear ratio of :

https://wolfram.com/xid/0c13vyy-qpgemw

Minimize the manufacturing cost of a pressure vessel. The vessel is a cylindrical shell of length and radius
with a hemisphere cap at each end of the tube:

The volume constraint of the vessel is:

https://wolfram.com/xid/0c13vyy-nrwa4c
The shell has a thickness and the sphere cap has a thickness
. The shell and cap thicknesses have specified upper and lower limits and must be greater than a fraction of the radius:

https://wolfram.com/xid/0c13vyy-eqe8c6
The thickness of the shell and cap have additional constraints:

https://wolfram.com/xid/0c13vyy-yl0dif
The vessel dimension constraints are:

https://wolfram.com/xid/0c13vyy-xexq0n
The shell and cap material has density . The material cost is:

https://wolfram.com/xid/0c13vyy-z5wdea
The cost to weld the shell and cap is:

https://wolfram.com/xid/0c13vyy-h5okfw
The total manufacturing cost is a total of welding and material costs:

https://wolfram.com/xid/0c13vyy-121gan

https://wolfram.com/xid/0c13vyy-no3fpl

Find the dimensions of the vessel that minimize the manufacturing cost:

https://wolfram.com/xid/0c13vyy-146mu8

Design a minimum-volume helical compression spring of winding diameter , spring wire diameter
and number of spring coils
subjected to an axial load:


https://wolfram.com/xid/0c13vyy-lhgp0y
The shear stress on the spring is dependent on the maximum allowable axial load and must be below the maximum allowable stress
:

https://wolfram.com/xid/0c13vyy-xi9ndv
The deflection of the spring is defined as:

https://wolfram.com/xid/0c13vyy-ycvlr4
The spring free length must be less than the maximum allowable length :

https://wolfram.com/xid/0c13vyy-11vco4
The wire diameter must not exceed the specified minimum diameter:

https://wolfram.com/xid/0c13vyy-rm2g3y
The outside diameter of the spring must be less than the maximum specified diameter :

https://wolfram.com/xid/0c13vyy-u19k41
The winding diameter must be at least three times the wire diameter
to avoid tightly wound springs:

https://wolfram.com/xid/0c13vyy-hh8q94
The deflection under pre-load must be between a specified and
:

https://wolfram.com/xid/0c13vyy-3zp08n
The load induced from the deflection and pre-load must not exceed the maximum load
:

https://wolfram.com/xid/0c13vyy-3lv89p
The coil spring is to be manufactured from music wire spring steel ASTM A228 and the wire diameter must be chosen from a set of predetermined diameters:

https://wolfram.com/xid/0c13vyy-6x2scb
The wire diameter is chosen from the predetermined set using binary variables:

https://wolfram.com/xid/0c13vyy-2clmee

https://wolfram.com/xid/0c13vyy-6sjavk

https://wolfram.com/xid/0c13vyy-7n9eit

https://wolfram.com/xid/0c13vyy-g029w1

Properties & Relations (9)Properties of the function, and connections to other functions
NMinimize gives the minimum value and rules for the minimizing values of the variables:

https://wolfram.com/xid/0c13vyy-cq0ogw

NArgMin gives a list of the minimizing values:

https://wolfram.com/xid/0c13vyy-dggssc

NMinValue gives only the minimum value:

https://wolfram.com/xid/0c13vyy-bsp96p

Maximizing a function f is equivalent to minimizing -f:

https://wolfram.com/xid/0c13vyy-cszj9i


https://wolfram.com/xid/0c13vyy-0l7ax

For convex problems, ConvexOptimization may be used to obtain additional solution properties:

https://wolfram.com/xid/0c13vyy-dxo13c


https://wolfram.com/xid/0c13vyy-mlkbfu


https://wolfram.com/xid/0c13vyy-bpwocb

For convex problems with parameters, using ParametricConvexOptimization gives a ParametricFunction:

https://wolfram.com/xid/0c13vyy-omnnb3

The ParametricFunction may be evaluated for values of the parameter:

https://wolfram.com/xid/0c13vyy-hfii5a

Define a function for the parametric problem using NMinimize:

https://wolfram.com/xid/0c13vyy-ek8e0c

Compare the speed of the two approaches:

https://wolfram.com/xid/0c13vyy-hck5xu

Derivatives of the ParametricFunction can also be computed:

https://wolfram.com/xid/0c13vyy-fewdju

For convex problems with parametric constraints, RobustConvexOptimization finds an optimum that works for all possible values of the parameters:

https://wolfram.com/xid/0c13vyy-dgv79

NMinimize may find a smaller value for particular values of the parameters:

https://wolfram.com/xid/0c13vyy-lnhy72

This minimizer does not satisfy the constraints for all allowed values of α and β:

https://wolfram.com/xid/0c13vyy-dlad5x

The minimum value found for particular values of the parameters is less than or equal to the robust minimum:

https://wolfram.com/xid/0c13vyy-b0rws

https://wolfram.com/xid/0c13vyy-e1wtev

NMinimize aims to find a global minimum, while FindMinimum attempts to find a local minimum:

https://wolfram.com/xid/0c13vyy-ny4nl7


https://wolfram.com/xid/0c13vyy-8v0aqv


https://wolfram.com/xid/0c13vyy-dlfdes

FindFit can use NMinimize to find the global optimal fit. This sets up a model:

https://wolfram.com/xid/0c13vyy-lldowm
Create a function from the model and parameters, and generate sample points:

https://wolfram.com/xid/0c13vyy-3wjot7
By default, FindFit only finds the local optimal fit:

https://wolfram.com/xid/0c13vyy-zfpcs7

Using the NMinimize method finds the global optimal fit:

https://wolfram.com/xid/0c13vyy-6ty06g

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

https://wolfram.com/xid/0c13vyy-f4g5uc

https://wolfram.com/xid/0c13vyy-lbd2cp


https://wolfram.com/xid/0c13vyy-m854ft

Both can be computed using NMinimize:

https://wolfram.com/xid/0c13vyy-eb1ko5


https://wolfram.com/xid/0c13vyy-if73ua

Use RegionBounds to compute the bounding box:

https://wolfram.com/xid/0c13vyy-eqkvxp


https://wolfram.com/xid/0c13vyy-jf4d0

Use NMaximize and NMinimize to compute the same bounds:

https://wolfram.com/xid/0c13vyy-gkt1lb


https://wolfram.com/xid/0c13vyy-ckoox0

Possible Issues (3)Common pitfalls and unexpected behavior
For nonlinear functions, NMinimize may sometimes find only a local minimum for certain methods:

https://wolfram.com/xid/0c13vyy-bhw1tn

Plot the solution along with the local minima:

https://wolfram.com/xid/0c13vyy-m37nzb

Specifying a starting interval can help in achieving a better local minimum:

https://wolfram.com/xid/0c13vyy-e5a7tm

Automatic method gives a better solution:

https://wolfram.com/xid/0c13vyy-cem0cj

NMinimize finds a local minimum of a two-dimensional function on a disk for certain methods:

https://wolfram.com/xid/0c13vyy-1f0028

Specifying a starting interval helps in achieving the global minimum:

https://wolfram.com/xid/0c13vyy-ji4d0x


https://wolfram.com/xid/0c13vyy-ddlqow

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

https://wolfram.com/xid/0c13vyy-yh8x2k
Compute with a parameter value of 2:

https://wolfram.com/xid/0c13vyy-pyvnky

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

https://wolfram.com/xid/0c13vyy-dwtidm


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

https://wolfram.com/xid/0c13vyy-0f5xam





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

https://wolfram.com/xid/0c13vyy-6jf9w8
Compute with a numerical value:

https://wolfram.com/xid/0c13vyy-hsiq55

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

https://wolfram.com/xid/0c13vyy-1jhsx

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

https://wolfram.com/xid/0c13vyy-5ia6m7

Wolfram Research (2003), NMinimize, Wolfram Language function, https://reference.wolfram.com/language/ref/NMinimize.html (updated 2024).
Text
Wolfram Research (2003), NMinimize, Wolfram Language function, https://reference.wolfram.com/language/ref/NMinimize.html (updated 2024).
Wolfram Research (2003), NMinimize, Wolfram Language function, https://reference.wolfram.com/language/ref/NMinimize.html (updated 2024).
CMS
Wolfram Language. 2003. "NMinimize." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2024. https://reference.wolfram.com/language/ref/NMinimize.html.
Wolfram Language. 2003. "NMinimize." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2024. 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
Wolfram Language. (2003). NMinimize. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/NMinimize.html
BibTeX
@misc{reference.wolfram_2025_nminimize, author="Wolfram Research", title="{NMinimize}", year="2024", howpublished="\url{https://reference.wolfram.com/language/ref/NMinimize.html}", note=[Accessed: 01-June-2025
]}
BibLaTeX
@online{reference.wolfram_2025_nminimize, organization={Wolfram Research}, title={NMinimize}, year={2024}, url={https://reference.wolfram.com/language/ref/NMinimize.html}, note=[Accessed: 01-June-2025
]}