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.
| Out[1]= |  |
Applying the rule for

gives the value at the minimum.
| Out[2]= |  |
This maximizes with respect to

and

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

.
| Out[4]= |  |
This finds the maximum within the unit circle.
| Out[5]= |  |
This finds the maximum within an ellipse. The result is fairly complicated.
| Out[6]= |  |
This finds the maximum along a line.
| 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.
| 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.
| Out[9]= |  |
This finds the maximal volume of a cuboid that fits inside the unit sphere.
| 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.
| Out[11]= |  |
| 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,
Mathematica prints a warning, then returns the point on the boundary.
| Out[13]= |  |
Minimize and Maximize normally assume that all variables you give are real. But by giving a constraint such as x
Integers you can specify that a variable must in fact be an integer.
This does maximization only over integer values of

and

.
| 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.
| 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.
| 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.
| Out[17]= |  |
Use
MaxValue if you only need the maximum value.
| Out[18]= |  |
For strict polynomial inequality constraints, computing only the maximum value may be much faster.
| Out[19]= |  |
| Out[20]= |  |
ArgMax gives a position at which the maximum value is attained.
| Out[21]= |  |