Professional Documents
Culture Documents
Example: What are the global maximum and minimum values of the function
f (x, y) = x2 + y 2 2x2 y 2
1 0.9
0.4.3
0.3
0.8
0.6
1
0.4
0.7
0
0.5 0.5
0.3
0.8 0.5 0.2
0.6
0.6
0.7
0.7
0.9
0.8
0.8
0.6
0.4
0
0.2
0.4
0.9
0.1
0.5
0.4
0.3
−0.5
0.5 0.5
0.2
0.30.4
0.7
0.4
0.6
1 0
0.3
0.9 .8
−1
−1 −0.5 0 0.5 1
0
0
−1
−0.5
0
0.5 −1
1
4.2. CRITICAL POINTS AND OPTIMISATION 201
The Nelder–Mead algorithm is a search method built into the Matlab function fmin-
search. One advantage of this method is that it works with non-smooth functions
as well, so it extends beyond traditional calculus methods.
The syntax is that fminsearch will try to minimise a function f that you must
store as a function in an M-file. Then you give fminsearch a starting point and let
it run.
For example, to minimise f (x, y, z) = (x 1)2 + (y 2)2 + (z 3)2 , use the following
code:
Note that x(1) corresponds to x, x(2) to y and x(3) to z. This is because fmin-
search requires that f takes a single vector as input (in this example the three-
dimensional vector x).
Now, to run the minimisation, call
fminsearch(’f’,[0,5,10])
• You should know that the local minimum or maximum is obtained when either
all the partial derivatives are zero or some of the partial derivatives are not
defined.
• You should know how to find critical points and classify them using either the
quadratic approximation, or the second derivative test.
which is a function of x alone. The critical points of F occur when F 0 (x) = 2+4x =
0, yielding x = 1/2. Since F 00 (x) = 4 > 0 it follows that F has a minimum at
x = 1/2. Therefore, f subject to the constraint x + y = 1 achieves its minimum
value at x = y = 1/2, with actual value also 1/2.
There is a much better way to solve the above problem not requiring the explicit
solution of the constraint-equation. The trick is to define a second function, say
g, such that the constraint-equation corresponds to g(x, y) = 0. In our example,
g(x, y) = x + y 1. Now graph the contour plot of f (x, y) = x2 + y 2 and add to this
graph the single contour g(x, y) = 0:
y
the circles are the contours
f = 12 , 1, 32 , 2, 52
g=0
4.3. CONSTRAINED OPTIMISATION AND LAGRANGE MULTIPLIERS 203
The minimum occurs where the contour g(x, y) = 0 touches one of the contours of
f , which means that rf and rg are parallel. Hence
rf = rg