Maximizing vs. Minimizing
Global Optimization Toolbox optimization functions minimize the objective (or fitness) function. That is, they solve problems of the form
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
Write a function to compute
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
xmin), which is –
ans = 3.8683