# NMaximize

NMaximize[f,x]

maximizes f numerically with respect to x.

NMaximize[f,{x,y,}]

maximizes f numerically with respect to x, y, .

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

maximizes f numerically subject to the constraints cons.

NMaximize[,xreg]

constrains x to be in the region reg.

# Details and Options  • NMaximize returns a list of the form {fmax,{x->xmax,y->ymax,}}.
• cons can contain equations, inequalities or logical combinations of these.
• The constraints cons can be any logical combination of:
•  lhs==rhs equations lhs>rhs or lhs>=rhs inequalities {x,y,…}∈reg region specification
• NMaximize[{f,cons},xreg] is effectively equivalent to NMaximize[{f,consxreg},x].
• For xreg, the different coordinates can be referred to using Indexed[x,i].
• NMaximize always attempts to find a global maximum of f subject to the constraints given.
• By default, all variables are assumed to be real.
• xIntegers can be used to specify that a variable can take on only integer values.
• If f and cons are linear, NMaximize can always find global maxima, over both real and integer values.
• Otherwise, NMaximize may sometimes find only a local maximum.
• If NMaximize 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 maximum, and the value of the function at the maximum.
• NMaximize 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 all

## Basic Examples(3)

Find the global maximum of an unconstrained problem:

Extract the maximizing argument:

Find the global maximum of problems with constraints:

Maximize a function over a geometric region:

Plot it:

## Scope(9)

Or constraints can be specified:

Use NMaximize for linear objective and constraints:

Integer constraints can be imposed:

Maximize over a region:

Plot it:

Find the maximum distance between points in two regions:

Plot it:

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

Plot it:

Find the maximum for which contains the given three points:

Plot it:

Use to specify that is a vector in :

Find the maximum distance between points in two regions:

Plot it:

## Options(6)

### 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(1)

Specifying a non-default method could give a better solution:

### StepMonitor(1)

Steps taken by NMaximize in finding the maximum of a function:

### WorkingPrecision(1)

With the working precision set to , by default AccuracyGoal and PrecisionGoal are set to :

## Properties & Relations(1)

NMaximize aims to find a global maximum, while FindMaximum attempts to find a local maximum:

Maximize finds a global maximum and can work in infinite precision:

## Possible Issues(4)

For nonlinear functions, NMaximize may sometimes find only a local maximum:

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

NMaximize finds a local maximum of a two-dimensional function on a disk:

Specifying a starting interval helps in achieving the global maximum:

Use RegionBounds to compute the bounding box:

Use NMaximize and NMinimize to compute the same bounds:

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

This function can now be used with other numerical functions such as NMaximize:

Introduced in 2003
(5.0)
|
Updated in 2007
(6.0)
2014
(10.0)