Вы находитесь на странице: 1из 4

Printed from the Complete Wolfram Language Documentation 1

TUTORIAL Related Tutorials Functions URL

Numerical Optimization

FindMinimum f , x,x0 search for a local minimum of f , starting at x x0


FindMinimum f ,x search for a local minimum of f
FindMinimum f , x,x0 , y,y0 ,

search for a local minimum in several variables


FindMinimum f ,cons , x,x0 , y,y0 ,

search for a local minimum subject to the constraints


cons starting at x x0 , y y0 ,
FindMinimum f ,cons , x,y, search for a local minimum subject to the constraints
cons
FindMaximum f ,x , etc. search for a local maximum

Searching for local minima and maxima.

This finds the value of x which minimizes x , starting at x 2.

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


encuentra mín gamma de Euler

Out[1]= 0.885603, x 1.46163

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

In[2]:= Gamma x . Last


gamma de Eu último

Out[2]= 0.885603

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 3 x^2 x, x, 3, 2


representación gráfica

Out[3]=

1988–2018 Wolfram Research, Inc. All rights reserved. http://reference.wolfram.com/language


Printed from the Complete Wolfram Language Documentation 2

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


In[4]:= FindMinimum x ^ 4 3 x^2 x, x, 1
encuentra mínimo

Out[4]= 1.07023, x 1.1309

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


encuentra mínimo

Out[5]= 3.51391, x 1.30084

You can specify variables without initial values.

In[6]:= FindMinimum x ^ 4 3 x^2 x, x


encuentra mínimo

Out[6]= 1.07023, x 1.1309

You can specify a constraint.

In[7]:= FindMinimum x^4 3 x^2 x, x 0 ,x


encuentra mínimo

Out[7]= 3.51391, x 1.30084

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[8]:= NMinimize x ^ 4 3 x^2 x, x


minimiza aproximadamente

Out[8]= 3.51391, x 1.30084

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.

1988–2018 Wolfram Research, Inc. All rights reserved. http://reference.wolfram.com/language


Printed from the Complete Wolfram Language Documentation 3

With the constraint x 0, NMinimize will give the local minimum on the right.
In[9]:= NMinimize x^4 3 x^2 x, x 0 ,x
minimiza aproximadamente

Out[9]= 1.07023, x 1.1309

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

In[10]:= NMinimize x 2 y, x ^ 2 y^2 1 , x, y


minimiza aproximadamente

Out[10]= 2.23607, x 0.447214, y 0.894427

In this case Minimize can give an exact result.


In[11]:= Minimize x 2 y, x ^ 2 y^2 1 , x, y
minimiza
4 2
Out[11]=  5 , x 5 ,y 
5 5

But in this case it cannot.

In[12]:= Minimize Cos x 2 y , x^2 y^2 1 , x, y


minimiza coseno

Out[12]= MinimizeCos x 2 y , x2 y2 1, x, y 

This gives a numerical approximation, effectively using NMinimize .


In[13]:= N
valor numérico

Out[13]= 0.617273, x 0.447214, y 0.894427

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 x which minimizes c.x subject to the
constraints m.x b and x 0
LinearProgramming c,m,b,l use the constraints m.x b and x l

Linear programming in matrix form.

Here is a linear programming problem in equation form.

In[14]:= Minimize 2x 3 y, x 5y 10, x y 2, x 1 , x, y


minimiza
32 10 4
Out[14]=  , x ,y 
3 3 3

Here is the corresponding problem in matrix form.

In[15]:= LinearProgramming 2, 3 , 1, 5 , 1, 1 , 1, 0 , 10, 2, 1


programación lineal
10 4
Out[15]=  , 
3 3

You can specify a mixture of equality and inequality constraints by making the list b be a sequence of pairs bi , si . If si is 1, then the ith constraint
is mi .x bi . If si is 0 then it is mi .x bi , and if si is 1 then it is mi .x bi .

1988–2018 Wolfram Research, Inc. All rights reserved. http://reference.wolfram.com/language


Printed from the Complete Wolfram Language Documentation 4

This makes the first inequality use .

In[16]:= LinearProgramming 2, 3 , 1, 5 , 1, 1 , 1, 0 , 10, 1 , 2, 1 , 1, 1


programación lineal

Out[16]= 2, 0

In LinearProgramming c, m, b, l , you can make l be a list of pairs l1 , u1 , l2 , u2 , representing lower and upper bounds on the xi .

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

Related Tutorials

Numerical Operations on Functions

1988–2018 Wolfram Research, Inc. All rights reserved. http://reference.wolfram.com/language