NMaxValue
NMaxValue[f,x]
gives the maximum value of f with respect to x.
NMaxValue[f,{x,y,…}]
gives the maximum value of f with respect to x, y, ….
NMaxValue[{f,cons},{x,y,…}]
gives the maximum value of f subject to the constraints cons.
NMaxValue[…,x∈reg]
constrains x to be in the region reg.
Details and Options
 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  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
Examples
open allclose allBasic Examples (5)
Find the global maximum value of a univariate function:
Find the global maximum value of a multivariate function:
Find the global maximum value of a function subject to constraints:
Find the global maximum value of a function over a geometric region:
Find the global maximum value of a function over a geometric region:
Scope (34)
Basic Uses (12)
Maximize subject to constraints :
Several linear inequality constraints can be expressed with VectorGreaterEqual:
Use v>= or \[VectorGreaterEqual] to enter the vector inequality sign :
An equivalent form using scalar inequalities:
The inequality may not be the same as due to possible threading in :
To avoid unintended threading in , use Inactive[Plus]:
Use constant parameter equations to avoid unintended threading in :
VectorGreaterEqual represents a conic inequality with respect to the "NonNegativeCone":
To explicitly specify the dimension of the cone, use {"NonNegativeCone",n}:
Maximize subject to the constraint :
Specify the constraint using a conic inequality with "NormCone":
Maximize the function subject to the constraint :
Use Indexed to access components of a vector variable, e.g. :
Use Vectors[n,dom] to specify the dimension and domain of a vector variable when it is ambiguous:
Specify nonnegative constraints using NonNegativeReals ():
An equivalent form using vector inequality :
Specify nonpositive constraints using NonPositiveReals ():
An equivalent form using vector inequalities:
Or constraints can be specified:
Domain Constraints (4)
Specify integer domain constraints using Integers:
Specify integer domain constraints on vector variables using Vectors[n,Integers]:
Specify nonnegative integer domain constraints using NonNegativeIntegers ():
Specify nonpositive integer domain constraints using NonPositiveIntegers ():
Region Constraints (3)
Linear Problems (5)
With linear objectives and constraints, when a maximum is found it is global:
The constraints can be equality and inequality constraints:
Use Equal to express several equality constraints at once:
An equivalent form using several scalar equalities:
Use VectorLessEqual to express several LessEqual inequality constraints at once:
Use v<= to enter the vector inequality in a compact form:
An equivalent form using scalar inequalities:
Use Interval to specify bounds on a variable:
Convex Problems (4)
Use "NonNegativeCone" to specify linear functions of the form :
Use v>= to enter the vector inequality in a compact form:
Find the maximum value of a concave quadratic function subject to a set of convex quadratic constraints:
Find the maximum value of such that is positive semidefinite:
Show the plot of the objective function:
Find the maximum value of a concave objective function such that is positive semidefinite and :
Transformable to Convex (3)
Maximize the quasiconcave function subject to inequality and norm constraints. The objective is quasiconcave because it is a product of two nonnegative affine functions:
The maximization is solved by minimizing the negative of the objective, , that is quasiconvex. Quasiconvex problems can be solved as parametric convex optimization problems for the parameter :
Plot the objective as a function of the levelset :
For a levelset value between the interval , the smallest objective is found:
The problem becomes infeasible when the levelset value is increased:
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:
Plot the region and the minimizing point:
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:
Options (6)
AccuracyGoal & PrecisionGoal (2)
This enforces convergence criteria and :
This enforces convergence criteria and , which is not achievable with the default machineprecision computation:
Setting a high WorkingPrecision makes the process convergent:
EvaluationMonitor (1)
StepMonitor (1)
Steps taken by NMaxValue in finding the maximum of a function:
WorkingPrecision (1)
With the working precision set to , by default AccuracyGoal and PrecisionGoal are set to :
Applications (4)
Geometry Problems (2)
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:
The amount invested in the utilities stock cannot be more than $40,000:
The amount invested in the bond must be at least $70,000:
The total amount invested in the two stocks must be at least half the total amount invested:
The stocks pay an annual dividend of 9% and 4%, respectively. The bond pays a dividend of 5%. The total return on investment is:
The cost of executing the transactions is and must not exceed $1000:
The maximum profit attainable with the specified constraints is:
Properties & Relations (7)
NMaximize gives the maximum value and rules for the maximizing values of the variables:
NArgMax gives a list of the maximizing values:
NMaxValue gives only the maximum value:
Maximizing a function f is equivalent to minimizing f:
For convex problems, ConvexOptimization may be used to obtain additional solution properties:
For convex problems with parameters, using ParametricConvexOptimization gives a ParametricFunction:
The ParametricFunction may be evaluated for values of the parameter:
Define a function for the parametric problem using NMaxValue:
Compare the speed of the two approaches:
Derivatives of the ParametricFunction can also be computed:
For convex problems with parametric constraints, RobustConvexOptimization finds an optimum that works for all possible values of the parameters:
NMaxValue may find a larger maximum value for particular values of the parameters:
The maximizer that gives this value does not satisfy the constraints for all allowed values of and :
The maximum value found for particular values of the parameters is greater than or equal to the robust maximum:
NMaxValue can solve linear programming problems:
LinearProgramming can be used to solve the same problem given in matrix notation:
Use RegionBounds to compute the bounding box:
Text
Wolfram Research (2008), NMaxValue, Wolfram Language function, https://reference.wolfram.com/language/ref/NMaxValue.html (updated 2021).
CMS
Wolfram Language. 2008. "NMaxValue." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2021. 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