Function Repository Resource:

GlobalMaxima

Source Notebook

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

Contributed by: Wolfram|Alpha Math Team

ResourceFunction["GlobalMaxima"][expr,x]

computes the global maxima of expr with respect to x.

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

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

ResourceFunction["GlobalMaxima"][{expr,const},]

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

Details and Options

ResourceFunction["GlobalMaxima"] returns a list with each maximum in the form {fmax,{xxmax,yymax,}}.
The const can contain equations, inequalities or logical combinations of these.
ResourceFunction["GlobalMaxima"] only returns results when there is a bounded maximum.

Examples

Basic Examples (2) 

Compute the global maxima of a polynomial:

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

Plot them:

In[2]:=
Plot[-x^2 (x + 2) (x - 2), {x, -3, 3}, Epilog -> {
Directive[Red, 
PointSize[Large]], 
Point[{-Sqrt[2], 4}], 
Point[{
Sqrt[2], 4}]}]
Out[2]=

Scope (2) 

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

In[3]:=
ResourceFunction["GlobalMaxima"][{Sin[x], 0 < x < 4 Pi}, x]
Out[3]=

Compute the maxima of a function of two variables:

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

Possible Issues (1) 

GlobalMaxima may return duplicate results for periodic functions:

In[5]:=
ResourceFunction["GlobalMaxima"][-Sin[x], x]
Out[5]=

Publisher

Wolfram|Alpha Math Team

Version History

  • 2.0.0 – 23 March 2023
  • 1.0.0 – 18 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