cmss Using the first differential

Fortunately, when a function, like \( f() \) above, is differentiable, more efficient optimization algorithms can be used. If minimize() is given the differential of the optimized function, using the "df" option, it will use a conjugate gradient method.

## Function returning partial derivatives

function dc = diffoo (x)

    x = x(:)' - 1;

    dc = sin (x) + 2*x/9;

endfunction

[x, v, n] = minimize ("foo", x0, "df", "diffoo")

This produces the output :

x =

  1.00000 1.00000 1.00000

v = -3 

n =

  108 6

The same minimum has been found, but only 108 function evaluations were needed, together with 6 evaluations of the differential. Here, diffoo() takes the same argument as foo() and returns the partial derivatives of \( f() \) with respect to the corresponding variables. It doesn't matter if it returns a row or column vector or a matrix, as long as the \( i^{\textrm{th}}\) element of diffoo(x) is the partial derivative of \( f() \) with respect to \( x_{i} \) .



Søren Hauberg 2008-04-29