Wolfram Research

Function Repository Resource:

GlobalExtrema (1.0.0) current version: 2.0.0 »

Source Notebook

Compute the global extrema of an expression with respect to the given variables

Contributed by: Wolfram|Alpha Math Team

ResourceFunction["GlobalExtrema"][expr,x]

computes the global maxima and minima of expr with respect to x.

ResourceFunction["GlobalExtrema"][expr,{x,y,}]

computes the global maxima and minima of expr with respect to multiple variables.

ResourceFunction["GlobalExtrema"][{expr,const},{x,y,}]

computes the global maxima and minima of expr subject to the constraint const.

Details and Options

ResourceFunction["GlobalExtrema"] returns an association of the form <|"Maxima"{fmax,{xxmax,yymax,}},"Minima"{fmin,{xxmin,yymin,}}|>.
The const can contain equations, inequalities or logical combinations of these.
ResourceFunction["GlobalExtrema"] only returns results when there is a bounded extremum.

Examples

Basic Examples (2) 

Compute the global extrema of a curve:

In[1]:=
ResourceFunction["GlobalExtrema"][E^(-(x + 1)^2) - E^(-(x - 1)^2), x]
Out[1]=

Plot the result:

In[2]:=
Plot[E^(-(x + 1)^2) - E^(-(x - 1)^2), {x, -5, 5}, Epilog -> {
Style[
Point[{
Root[{-1 + E^(4 #) (-1 + #) - #& , 1.032669069487352}], (-E^(-(
           1 + Root[{-1 + E^(4 #) (-1 + #) - #& , 1.032669069487352}])^2)) (-1 + E^(
         4 Root[{-1 + E^(4 #) (-1 + #) - #& , 1.032669069487352}]))}], 
AbsolutePointSize[10], Red], 
Style[
Point[-{
Root[{-1 + E^(4 #) (-1 + #) - #& , 1.032669069487352}], (-E^(-(
            1 + Root[{-1 + E^(4 #) (-1 + #) - #& , 1.032669069487352}])^2)) (-1 + E^(
          4 Root[{-1 + E^(4 #) (-1 + #) - #& , 1.032669069487352}]))}], 
AbsolutePointSize[10], Red]}]
Out[2]=

Use a constraint in order to reduce the domain upon which extrema can be found:

In[3]:=
ResourceFunction["GlobalExtrema", ResourceVersion->"1.0.0"][{E^(-(x + 1)^2) - E^(-(x - 1)^2), 0 < x < 2}, x]
Out[3]=

Scope (2) 

Compute the extrema of a function of two variables:

In[4]:=
ResourceFunction["GlobalExtrema"][(4 - x^2 - y^2)^2, {x, y}]
Out[4]=

Compute the extrema of a piecewise function:

In[5]:=
ResourceFunction["GlobalExtrema"][
 Piecewise[{{x, x <= 0}, {-x - 5, x > 0}}], x]
Out[5]=

Plot the result:

In[6]:=
Plot[Piecewise[{{x, x <= 0}, {-5 - x, x > 0}}], {x, -1, 1}, Epilog -> {
Style[
Point[{0, 0}], 
AbsolutePointSize[10], Red]}]
Out[6]=

Possible Issues (1) 

GlobalExtrema may return duplicate results for periodic functions:

In[7]:=
ResourceFunction["GlobalExtrema"][Sin[x], x]
Out[7]=

Publisher

Wolfram|Alpha Math Team

Version History

  • 2.0.0 – 23 March 2023
  • 1.0.0 – 22 September 2020

Related Resources

Author Notes

To view the full source code for GlobalMaxima, run the following code:

In[1]:=
FileNameJoin[
  ReplacePart[
   FileNameSplit[FindFile["ResourceFunctionHelpers`"]], -1 -> "FindExtrema.wl"]] // SystemOpen

License Information