Minimization and Maximization

Minimize[expr,{x1,x2,}]minimize expr
Minimize[{expr,cons},{x1,x2,}]minimize expr subject to the constraints cons
Maximize[expr,{x1,x2,}]maximize expr
Maximize[{expr,cons},{x1,x2,}]maximize expr subject to the constraints cons

Minimization and maximization.

Minimize and Maximize yield lists giving the value attained at the minimum or maximum, together with rules specifying where the minimum or maximum occurs.

This finds the minimum of a quadratic function.
In[1]:=
Click for copyable input
Out[1]=
Applying the rule for gives the value at the minimum.
In[2]:=
Click for copyable input
Out[2]=
This maximizes with respect to and .
In[3]:=
Click for copyable input
Out[3]=

Minimize[expr,x] minimizes expr allowing x to range over all possible values from to . Minimize[{expr,cons},x] minimizes expr subject to the constraints cons being satisfied. The constraints can consist of any combination of equations and inequalities.

This finds the minimum subject to the constraint .
In[4]:=
Click for copyable input
Out[4]=
This finds the maximum within the unit circle.
In[5]:=
Click for copyable input
Out[5]=
This finds the maximum within an ellipse. The result is fairly complicated.
In[6]:=
Click for copyable input
Out[6]=
This finds the maximum along a line.
In[7]:=
Click for copyable input
Out[7]=

Minimize and Maximize can solve any linear programming problem in which both the objective function expr and the constraints cons involve the variables only linearly.

Here is a typical linear programming problem.
In[8]:=
Click for copyable input
Out[8]=

They can also in principle solve any polynomial programming problem in which the objective function and the constraints involve arbitrary polynomial functions of the variables. There are many important geometrical and other problems that can be formulated in this way.

This solves the simple geometrical problem of maximizing the area of a rectangle with fixed perimeter.
In[9]:=
Click for copyable input
Out[9]=
This finds the maximal volume of a cuboid that fits inside the unit sphere.
In[10]:=
Click for copyable input
Out[10]=

An important feature of Minimize and Maximize is that they always find global minima and maxima. Often functions will have various local minima and maxima at which derivatives vanish. But Minimize and Maximize use global methods to find absolute minima or maxima, not just local extrema.

Here is a function with many local maxima and minima.
In[11]:=
Click for copyable input
Out[11]=
Maximize finds the global maximum.
In[12]:=
Click for copyable input
Out[12]=

If you give functions that are unbounded, Minimize and Maximize will return and as the minima and maxima. And if you give constraints that can never be satisfied, they will return and as the minima and maxima, and Indeterminate as the values of variables.

One subtle issue is that Minimize and Maximize allow both nonstrict inequalities of the form , and strict ones of the form . With nonstrict inequalities there is no problem with a minimum or maximum lying exactly on the boundary . But with strict inequalities, a minimum or maximum must in principle be at least infinitesimally inside the boundary.

With a strict inequality, the Wolfram Language prints a warning, then returns the point on the boundary.
In[13]:=
Click for copyable input
Out[13]=

Minimize and Maximize normally assume that all variables you give are real. But by giving a constraint such as xIntegers you can specify that a variable must in fact be an integer.

This does maximization only over integer values of and .
In[14]:=
Click for copyable input
Out[14]=

Minimize and Maximize can compute maxima and minima of linear functions over the integers in bounded polyhedra. This is known as integer linear programming.

This does maximization over integer values of and in a triangle.
In[15]:=
Click for copyable input
Out[15]=

Minimize and Maximize can produce exact symbolic results for polynomial optimization problems with parameters.

This finds the minimum of a general quadratic polynomial.
In[16]:=
Click for copyable input
Out[16]=
MinValue[{f,cons},{x,y,}]give the minimum value of f subject to the constraints cons
MaxValue[{f,cons},{x,y,}]give the maximum value of f subject to the constraints cons
ArgMin[{f,cons},{x,y,}]give a position at which f is minimized subject to the constraints cons
ArgMax[{f,cons},{x,y,}]give a position at which f is maximized subject to the constraints cons

Computing values and positions of minima and maxima.

Maximize gives both the value and the position of a maximum.
In[17]:=
Click for copyable input
Out[17]=
Use MaxValue if you only need the maximum value.
In[18]:=
Click for copyable input
Out[18]=
For strict polynomial inequality constraints, computing only the maximum value may be much faster.
In[19]:=
Click for copyable input
Out[19]=
In[20]:=
Click for copyable input
Out[20]=
ArgMax gives a position at which the maximum value is attained.
In[21]:=
Click for copyable input
Out[21]=