This is documentation for Mathematica 8, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.2)

NMaximize

NMaximize
maximizes f numerically with respect to x.
NMaximize
maximizes f numerically with respect to x, y, ....
NMaximize
maximizes f numerically subject to the constraints cons.
  • cons can contain equations, inequalities or logical combinations of these.
  • 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.
  • The following options can be given:
AccuracyGoalAutomaticnumber of digits of final accuracy sought
EvaluationMonitorNoneexpression to evaluate whenever f is evaluated
MaxIterations100maximum number of iterations to use
MethodAutomaticmethod to use
PrecisionGoalAutomaticnumber of digits of final precision sought
StepMonitorNoneexpression to evaluate whenever a step is taken
WorkingPrecisionMachinePrecisionthe 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.
  • Possible settings for the Method option include , , , and .
Find the global maximum of an unconstrained problem:
Extract the maximizing argument:
Find the global maximum of problems with constraints:
Find the global maximum of an unconstrained problem:
In[1]:=
Click for copyable input
Out[1]=
Extract the maximizing argument:
In[2]:=
Click for copyable input
Out[2]=
 
Find the global maximum of problems with constraints:
In[1]:=
Click for copyable input
Out[1]=
In[2]:=
Click for copyable input
Out[2]=
Or constraints can be specified:
Use NMaximize for linear objective and constraints:
Integer constraints can be imposed:
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:
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:
Specifying a non-default method could give a better solution:
Steps taken by NMaximize in finding the maximum of a function:
With the working precision set to , by default AccuracyGoal and PrecisionGoal are set to :
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:
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:
Solve cannot work with this system of equations because they are highly nonalgebraic:
Use NMaximize with a trivial objective function to find a solution:
New in 5 | Last modified in 6