Wolfram ResearchPRODUCTSPURCHASEFOR USERSCOMPANYOUR SITES
THIS IS DOCUMENTATION FOR AN OBSOLETE PRODUCT.
SEE THE DOCUMENTATION CENTER FOR THE LATEST INFORMATION.
Previous section-----Next section

3.9.8 Numerical Optimization

FindMinimum[f, {x,  }] search for a local minimum in f, starting from the point x =
FindMinimum[f, {{x,  }, {y,  }, ... }]
search for a local minimum in a function of several variables
FindMaximum[f, {x,  }] search for a local maximum in f, starting from the point x =
FindMaximum[f, {{x,  }, {y,  }, ... }]
search for a local maximum in a function of several variables

Searching for minima and maxima.
This finds the value of  which minimizes  , starting from  .

In[1]:=  FindMinimum[Gamma[x], {x, 2}]

Out[1]=

The last element of the list gives the value at which the minimum is achieved.

In[2]:=  Gamma[x] /. Last[%]

Out[2]=

Like FindRoot, FindMinimum and FindMaximum work by starting from a point, then progressively searching for a minimum or maximum. But since they return a result as soon as they find anything, they may give only a local minimum or maximum of your function, not a global one.

This curve has two local minima.

In[3]:=  Plot[x^4 - 3x^2 + x, {x, -3, 2}]

Out[3]=

Starting at  , you get the local minimum on the right.

In[4]:=  FindMinimum[x^4 - 3 x^2 + x, {x, 1}]

Out[4]=

This gives the local minimum on the left, which in this case is also the global minimum.

In[5]:=  FindMinimum[x^4 - 3 x^2 + x, {x, -1}]

Out[5]=

NMinimize[f, x] try to find the global minimum of f
NMinimize[f, {x, y, ... }] try to find the global minimum over several variables
NMaximize[f, x] try to find the global maximum of f
NMaximize[f, {x, y, ... }] try to find the global maximum over several variables

Finding global minima and maxima.
This immediately finds the global minimum.

In[6]:=  NMinimize[x^4 - 3x^2 + x, x]

Out[6]=

NMinimize and NMaximize are numerical analogs of Minimize and Maximize. But unlike Minimize and Maximize they usually cannot guarantee to find absolute global minima and maxima. Nevertheless, they typically work well when the function f is fairly smooth, and has a limited number of local minima and maxima.

NMinimize[{f, cons}, {x, y, ... }] try to find the global minimum of f subject to constraints cons
NMaximize[{f, cons}, {x, y, ... }] try to find the global maximum of f subject to constraints cons

Finding global minima and maxima subject to constraints.
With the constraint x > 0, NMinimize will give the local minimum on the right.

In[7]:=  NMinimize[{x^4 - 3x^2 + x, x > 0}, x]

Out[7]=

This finds the minimum of x + 2y within the unit circle.

In[8]:=  NMinimize[{x + 2y, x^2 + y^2 LessEqual 1}, {x, y}]

Out[8]=

In this case Minimize can give an exact result.

In[9]:=  Minimize[{x + 2y, x^2 + y^2 LessEqual 1}, {x, y}]

Out[9]=

But in this case it cannot.

In[10]:=  Minimize[{Cos[x + 2y], x^2 + y^2 LessEqual 1}, {x, y}]

Out[10]=

This gives a numerical approximation, effectively using NMinimize.

In[11]:=  N[%]

Out[11]=

If both the objective function f and the constraints cons are linear in all variables, then minimization and maximization correspond to a linear programming problem. Sometimes it is convenient to state such problems not in terms of explicit equations, but instead in terms of matrices and vectors.

LinearProgramming[c, m, b] find the vector  which minimizes  subject to the constraints  and
LinearProgramming[c, m, b, l] use the constraints  and

Linear programming in matrix form.
Here is a linear programming problem in equation form.

In[12]:=  Minimize[{2x + 3y, x + 5y GreaterEqual 10, x - y GreaterEqual 2, x GreaterEqual 1}, {x, y}]

Out[12]=

Here is the corresponding problem in matrix form.

In[13]:=  LinearProgramming[{2, 3}, {{1, 5}, {1, -1}, {1, 0}},
{10, 2, 1}]

Out[13]=

You can specify a mixture of equality and inequality constraints by making the list b be a sequence of pairs { ,  }. If  is 1, then the i constraint is  . x   . If  is 0 then it is  . x Equal  , and if  is -1 then it is  . x   .

This makes the first inequality use  .

In[14]:=  LinearProgramming[{2, 3}, {{1, 5}, {1, -1}, {1, 0}},
{{10, -1}, {2, 1}, {1, 1}}]

Out[14]=

In LinearProgramming[c, m, b, l], you can make l be a list of pairs {{ ,  }, { ,  }, ... } representing lower and upper bounds on the  .

In doing large linear programming problems, it is often convenient to give the matrix m as a SparseArray object.


Any questions about topics on this page? Click here to get an individual response.Buy NowFree TrialMore Information



 © 2008 Wolfram Research, Inc.  Terms of Use  Privacy Policy |
Sign up for our newsletter: