Main Content

Maximizing vs. Minimizing

Global Optimization Toolbox optimization functions minimize the objective (or fitness) function. That is, they solve problems of the form

minxf(x).

If you want to maximize f(x), minimize –f(x), because the point at which the minimum of –f(x) occurs is the same as the point at which the maximum of f(x) occurs.

For example, suppose you want to maximize the function

f(x)=exp((x12+x22))(x122x1x2+6x1+4x223x2).

Write a function to compute

g(x)=f(x)=exp((x12+x22))(x122x1x2+6x1+4x223x2),

and then minimize g(x). Start from the point x0 = [0 0].

f = @(x)exp(-(x(1)^2 + x(2)^2))*(x(1)^2 - 2*x(1)*x(2) + 6*x(1) + 4*x(2)^2 - 3*x(2));
g = @(x)-f(x);
x0 = [0 0];
[xmin,gmin] = fminsearch(g,x0)
xmin =

    0.5550   -0.5919


gmin =

   -3.8683

The maximum of f is the value of f(xmin), which is –gmin.

f(xmin)
ans =

    3.8683

Related Topics