Documentation

## Maximizing vs. Minimizing

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

$\underset{x}{\mathrm{min}}f\left(x\right).$

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\left(x\right)=\mathrm{exp}\left(-\left({x}_{1}^{2}+{x}_{2}^{2}\right)\right)\left({x}_{1}^{2}-2{x}_{1}{x}_{2}+6{x}_{1}+4{x}_{2}^{2}-3{x}_{2}\right).$

Write a function to compute

$g\left(x\right)=-f\left(x\right)=-\mathrm{exp}\left(-\left({x}_{1}^{2}+{x}_{2}^{2}\right)\right)\left({x}_{1}^{2}-2{x}_{1}{x}_{2}+6{x}_{1}+4{x}_{2}^{2}-3{x}_{2}\right),$

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

Watch now