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

Documentation / Mathematica / The Mathematica Book / A Practical Introduction to Mathematica / Numerical Mathematics /

1.6.5 Numerical Optimization

Finding global minima and maxima.

This gives the maximum value, and where it occurs.

In[1]:= NMaximize[x/(1 + Exp[x]), x]

Out[1]=

This minimizes the function within the unit circle.

In[2]:= NMinimize[{Cos[x] - Exp[x y], x^2 + y^2 < 1}, {x, y}]

Out[2]=

NMinimize and NMaximize can find the absolute minima and maxima of many functions. But in some cases it is not realistic to do this. You can search for local minima and maxima using FindMinimum and FindMaximum.

Searching for local minima and maxima.

This searches for a local minimum of , starting at .

In[3]:= FindMinimum[x Cos[x], {x, 2}]

Out[3]=

With a different starting point, you may reach a different local minimum.

In[4]:= FindMinimum[x Cos[x], {x, 10}]

Out[4]=

This finds a local minimum of .

In[5]:= FindMinimum[Sin[x y], {{x, 2}, {y, 2}}]

Out[5]=