NMaxValue

NMaxValue[f,x]

gives the global maximum value of f with respect to x.

NMaxValue[f,{x,y,}]

gives the global maximum value of f with respect to x, y, .

NMaxValue[{f,cons},{x,y,}]

gives the global maximum value of f subject to the constraints cons.

NMaxValue[,xreg]

constrains x to be in the region reg.

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==rhsequations
    lhs>rhs, lhsrhs, lhs<rhs, lhsrhsinequalities (LessEqual, )
    lhsrhs, lhsrhs, lhsrhs, lhsrhsvector inequalities (VectorLessEqual, )
    {x,y,}rdomregion or domain specification
  • NMaxValue[{f,cons},xrdom] is effectively equivalent to NMaxValue[{f,cons&&xrdom},x].
  • For xrdom, the different coordinates can be referred to using Indexed[x,i].
  • Possible domains rdom include:
  • Realsreal scalar variable
    Integersinteger 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:
  • AccuracyGoalAutomaticnumber of digits of final accuracy sought
    EvaluationMonitor Noneexpression to evaluate whenever f is evaluated
    MaxIterationsAutomaticmaximum number of iterations to use
    Method Automaticmethod to use
    PrecisionGoalAutomaticnumber of digits of final precision sought
    StepMonitor Noneexpression to evaluate whenever a step is taken
    WorkingPrecision MachinePrecisionthe 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 all

Basic 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:

Use a vector variable :

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}:

Find the solution:

Maximize subject to the constraint :

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

Find the solution:

Maximize the function subject to the constraint :

Use Indexed to access components of a vector variable, e.g. TemplateBox[{x, 1}, IndexedDefault]:

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

Specify non-negative constraints using NonNegativeReals (TemplateBox[{}, NonNegativeReals]):

An equivalent form using vector inequality :

Specify non-positive constraints using NonPositiveReals (TemplateBox[{}, 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 non-negative integer domain constraints using NonNegativeIntegers (TemplateBox[{}, NonNegativeIntegers]):

Specify non-positive integer domain constraints using NonPositiveIntegers (TemplateBox[{}, NonPositiveIntegers]):

Region Constraints  (3)

Find the maximum value of a linear function of a vector at in with TemplateBox[{x}, Norm]<=1:

Find the maximum value over a region:

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

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:

Plot the region:

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 :

Plot the region and the maximizing point:

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:

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 :

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

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

The problem becomes infeasible when the level-set 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:

Plot the region and the minimizing point:

General Problems  (3)

Maximize a linear objective subject to nonlinear constraints:

Plot it:

Maximize a nonlinear objective subject to linear constraints:

Plot the objective and the maximizing point:

Maximize a nonlinear objective subject to nonlinear constraints:

Plot it:

Options  (7)

AccuracyGoal & PrecisionGoal  (2)

This enforces convergence criteria and :

This enforces 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  (2)

Some methods may give suboptimal results for certain problems:

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

The automatic method choice for this non-convex problem is method "Couenne":

Plot the objective function along with the global maximum value:

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

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)

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

Plot the resulting regions:

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 :

The circles must not overlap:

Collect the variables:

Find the maximum radius :

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:

Iterated Optimization  (1)

Find the value for the parameter associated with ellipse such that the maximum value of is minimized:

Show the distance as a function of :

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

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:

Get the dual solution:

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:

Use NMaxValue and NMinValue to compute the same bounds:

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).

CMS

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

BibTeX

@misc{reference.wolfram_2024_nmaxvalue, author="Wolfram Research", title="{NMaxValue}", year="2024", howpublished="\url{https://reference.wolfram.com/language/ref/NMaxValue.html}", note=[Accessed: 05-October-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_nmaxvalue, organization={Wolfram Research}, title={NMaxValue}, year={2024}, url={https://reference.wolfram.com/language/ref/NMaxValue.html}, note=[Accessed: 05-October-2024 ]}