NMaxValue
✖
NMaxValue

Details and Options




- NMaxValue is also known as global optimization (GO).
- NMaxValue always attempts to find a global maximum of f subject to the constraints given.
- NMaxValue is typically used to find the largest possible values given constraints. In different areas, this may be called the best strategy, best fit, best configuration and so on.
- If f is linear or concave and cons are linear or convex, the result given by NMaxValue will be the global maximum, over both real and integer values; otherwise, the result may sometimes only be a local maximum.
- If NMaxValue determines that the constraints cannot be satisfied, it returns -Infinity.
- NMaxValue 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, NMaxValue 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 - NMaxValue[{f,cons},x∈rdom] is effectively equivalent to NMaxValue[{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 maximum, and the value of the function at the maximum.
- NMaxValue continues until either of the goals specified by AccuracyGoal or PrecisionGoal is achieved.
- The methods for NMaxValue fall into two classes. The first class of guaranteed methods uses properties of the problem so that, when the method converges, the maximum 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 maximum. These methods often do find the global maximum, but are not guaranteed to do so.
- Methods that are guaranteed to give a global maximum 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 (5)Summary of the most common use cases
Find the global maximum value of a univariate function:

https://wolfram.com/xid/0tz4s9oa-faqf4h

Find the global maximum value of a multivariate function:

https://wolfram.com/xid/0tz4s9oa-b6nuhh

Find the global maximum value of a function subject to constraints:

https://wolfram.com/xid/0tz4s9oa-fcm1i7

Find the global maximum value of a function over a geometric region:

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

Find the global maximum value of a function over a geometric region:

https://wolfram.com/xid/0tz4s9oa-dmbkop

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

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

Several linear inequality constraints can be expressed with VectorGreaterEqual:

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

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

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

An equivalent form using scalar inequalities:

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


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

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

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


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

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

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

Use constant parameter equations to avoid unintended threading in :

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

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

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

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

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

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


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

Maximize subject to the constraint
:

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

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

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


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

Maximize the function subject to the constraint
:

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

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

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

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



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

Specify non-negative constraints using NonNegativeReals ():

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

An equivalent form using vector inequality :

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

Specify non-positive constraints using NonPositiveReals ():

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

An equivalent form using vector inequalities:

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

Or constraints can be specified:

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

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

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

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

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

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

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

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

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

Region Constraints (3)
Find the maximum value of a linear function of a vector at in
with
:

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

Find the maximum value over a region:

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

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

Find the maximum possible distance between two points constrained to be in two different regions:

https://wolfram.com/xid/0tz4s9oa-7kyfx1

https://wolfram.com/xid/0tz4s9oa-5w9xg1

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

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

The constraints can be equality and inequality constraints:

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

Use Equal to express several equality constraints at once:

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

An equivalent form using several scalar equalities:

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

Use VectorLessEqual to express several LessEqual inequality constraints at once:

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

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

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

An equivalent form using scalar inequalities:

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

Use Interval to specify bounds on a variable:

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

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

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

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

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

Find the maximum value of a concave quadratic function subject to a set of convex quadratic constraints:

https://wolfram.com/xid/0tz4s9oa-n87gig


https://wolfram.com/xid/0tz4s9oa-8arunj

Find the maximum value of such that
is positive semidefinite:

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

Show the plot of the objective function:

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

Find the maximum value of a concave objective function such that
is positive semidefinite and
:

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

Plot the region and the maximizing point:

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

Transformable to Convex (3)
Maximize the quasi-concave function subject to inequality and norm constraints. The objective is quasi-concave because it is a product of two non-negative affine functions:

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

The maximization is solved by minimizing the negative of the objective, , that is quasi-convex. Quasi-convex problems can be solved as parametric convex optimization problems for the parameter
:

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

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

https://wolfram.com/xid/0tz4s9oa-36x0u9

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

https://wolfram.com/xid/0tz4s9oa-2eal5r

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

https://wolfram.com/xid/0tz4s9oa-rlvnf0


Maximize 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/0tz4s9oa-nvvmji

Plot the region and the minimizing point:

https://wolfram.com/xid/0tz4s9oa-9ftano

Maximize 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/0tz4s9oa-nwuv6f

Plot the region and the minimizing point:

https://wolfram.com/xid/0tz4s9oa-zkbrtw

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

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


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

Maximize a nonlinear objective subject to linear constraints:

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

Plot the objective and the maximizing point:

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

Maximize a nonlinear objective subject to nonlinear constraints:

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


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

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

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

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

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


Setting a high WorkingPrecision makes the process convergent:

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

EvaluationMonitor (1)
Record all the points evaluated during the solution process of a function with a ring of minima:

https://wolfram.com/xid/0tz4s9oa-cv023g
Plot all the visited points that are close in objective function value to the final solution:

https://wolfram.com/xid/0tz4s9oa-ko8x2u

Method (2)
Some methods may give suboptimal results for certain problems:

https://wolfram.com/xid/0tz4s9oa-pjlice

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

https://wolfram.com/xid/0tz4s9oa-9f1u97

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

https://wolfram.com/xid/0tz4s9oa-ed9xz

Plot the objective function along with the global maximum value:

https://wolfram.com/xid/0tz4s9oa-lo8kgo

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

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

StepMonitor (1)
Steps taken by NMaxValue in finding the maximum of a function:

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

https://wolfram.com/xid/0tz4s9oa-0y8pmj

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

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

Applications (4)Sample problems that can be solved with this function
Geometry Problems (2)
Find the maximum such that the triangle and ellipse still intersect:

https://wolfram.com/xid/0tz4s9oa-iilmdc

https://wolfram.com/xid/0tz4s9oa-fhmgwb


https://wolfram.com/xid/0tz4s9oa-7ow90l

Find the largest radius for
non-overlapping circles and their centers that can be contained in a
square. The box constraint can be represented as
:

https://wolfram.com/xid/0tz4s9oa-il3sjf

https://wolfram.com/xid/0tz4s9oa-1aii9u

https://wolfram.com/xid/0tz4s9oa-bypa82

https://wolfram.com/xid/0tz4s9oa-2ef1ll

Investment Problems (1)
Find the maximum return on investment possible by allocating $250,000 of capital to purchase two stocks and a bond. Let be the amount to invest in the two stocks and let
be the amount to invest in the bond:

https://wolfram.com/xid/0tz4s9oa-ia6ze5
The amount invested in the utilities stock cannot be more than $40,000:

https://wolfram.com/xid/0tz4s9oa-btzmo0
The amount invested in the bond must be at least $70,000:

https://wolfram.com/xid/0tz4s9oa-b6mfj1
The total amount invested in the two stocks must be at least half the total amount invested:

https://wolfram.com/xid/0tz4s9oa-frotww
The stocks pay an annual dividend of 9% and 4%, respectively. The bond pays a dividend of 5%. The total return on investment is:

https://wolfram.com/xid/0tz4s9oa-03t3gl
The cost of executing the transactions is and must not exceed $1000:

https://wolfram.com/xid/0tz4s9oa-bdlrsq
The maximum profit attainable with the specified constraints is:

https://wolfram.com/xid/0tz4s9oa-odpebt

Iterated Optimization (1)
Find the value for the parameter associated with ellipse
such that the maximum value of
is minimized:

https://wolfram.com/xid/0tz4s9oa-bxxiii
Show the distance as a function of :

https://wolfram.com/xid/0tz4s9oa-bu8new

Find optimal parameter that minimizes the maximum value of the objective:

https://wolfram.com/xid/0tz4s9oa-ex5rbu

Properties & Relations (7)Properties of the function, and connections to other functions
NMaximize gives the maximum value and rules for the maximizing values of the variables:

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

NArgMax gives a list of the maximizing values:

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

NMaxValue gives only the maximum value:

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

Maximizing a function f is equivalent to minimizing -f:

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


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

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

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


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


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

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

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

The ParametricFunction may be evaluated for values of the parameter:

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

Define a function for the parametric problem using NMaxValue:

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

Compare the speed of the two approaches:

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

Derivatives of the ParametricFunction can also be computed:

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

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

https://wolfram.com/xid/0tz4s9oa-bv10w2

NMaxValue may find a larger maximum value for particular values of the parameters:

https://wolfram.com/xid/0tz4s9oa-cm1b9c

The maximizer that gives this value does not satisfy the constraints for all allowed values of and
:

https://wolfram.com/xid/0tz4s9oa-gvxgxo


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

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

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

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

NMaxValue can solve linear programming problems:

https://wolfram.com/xid/0tz4s9oa-mm3mtp

LinearProgramming can be used to solve the same problem given in matrix notation:

https://wolfram.com/xid/0tz4s9oa-i8n5ly

https://wolfram.com/xid/0tz4s9oa-b7q2kw

Use RegionBounds to compute the bounding box:

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


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

Use NMaxValue and NMinValue to compute the same bounds:

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


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

Wolfram Research (2008), NMaxValue, Wolfram Language function, https://reference.wolfram.com/language/ref/NMaxValue.html (updated 2024).
Text
Wolfram Research (2008), NMaxValue, Wolfram Language function, https://reference.wolfram.com/language/ref/NMaxValue.html (updated 2024).
Wolfram Research (2008), NMaxValue, Wolfram Language function, https://reference.wolfram.com/language/ref/NMaxValue.html (updated 2024).
CMS
Wolfram Language. 2008. "NMaxValue." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2024. https://reference.wolfram.com/language/ref/NMaxValue.html.
Wolfram Language. 2008. "NMaxValue." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2024. https://reference.wolfram.com/language/ref/NMaxValue.html.
APA
Wolfram Language. (2008). NMaxValue. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/NMaxValue.html
Wolfram Language. (2008). NMaxValue. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/NMaxValue.html
BibTeX
@misc{reference.wolfram_2025_nmaxvalue, author="Wolfram Research", title="{NMaxValue}", year="2024", howpublished="\url{https://reference.wolfram.com/language/ref/NMaxValue.html}", note=[Accessed: 05-June-2025
]}
BibLaTeX
@online{reference.wolfram_2025_nmaxvalue, organization={Wolfram Research}, title={NMaxValue}, year={2024}, url={https://reference.wolfram.com/language/ref/NMaxValue.html}, note=[Accessed: 05-June-2025
]}