1

First of all, sorry if I am asking for trivial thing but I am just learning multivariable calculus and optimization toolbox in matlab--optimization as well :)

I was testing my understanding of using optimization toolbox in matlab on a simple 2D function and tried to find some local minima but, for particular points, matlab or fminunc functions gives me the exact starting points with the following comment: "Initial point is a local minimum.". I have provided both a gradient and a user-supplied Hessian. I don't know whether it is MATLAB or me. Perhaps I made mistake defining Hessian but I think all is correct.

For random starting point, the function always give a proper (the closest) minimum. However for certain points, at exact maxima, the fminunc returns exactly the same point with above statement. Should I use different optimization algorithm or it is simply the MATLAB thing I need to accept? I thought providing the Hessian would sort it out. The Hessian is always a negative-defined matrix at all problematic points and that should mean the point is a maximum!!! I tested it via returned eigenvalues by eig(hessian). It looks like fminunc does not take Hessian into account at all. What should I do to make fminunc work with hessians?

Cheers!


The points where fminunc is wrong:

x0 = [0 -1.5*pi];
x = fminunc(F,x0,options)/pi
x =
         0   -1.5000

x0 = [pi -pi/2];
x = fminunc(F,x0,options)/pi
x =
    1.0000   -0.5000

x0 = [-pi 1.5*pi];
x = fminunc(F,x0,options)/pi
x =
   -1.0000    1.5000

For instance the for the last point:

[minimum,gradient,hessian] = F([-pi 1.5*pi])
minimum =
     1
gradient =
   1.0e-15 *
   -0.1225    0.1837
hessian =
   -1.0000   -0.0000
   -0.0000   -1.0000





I used the code below:


  • To draw the figure:
    [X,Y]=meshgrid(-2*pi:4*pi/100:2*pi,-2*pi:4*pi/100:2*pi);
    FF = @(X,Y) cos(X).*sin(Y);
    surf(X,Y,FF(X,Y));
    shading interp;
    


  • The code with the function that I have been testing for local minima:
    options = optimset('GradObj','on','Hessian','user-supplied','Display','iter');
    F = @(x) deal(cos(x(1)).*sin(x(2)), [-sin(x(1)).*sin(x(2)) cos(x(1)).*cos(x(2))], [-cos(x(1)).*sin(x(2)) -sin(x(1)).*cos(x(2)); -sin(x(1)).*cos(x(2)) -cos(x(1)).*sin(x(2))]);
    x0 = [0 pi/2];
    x = fminunc(F,x0,options)
    
  • Amir
    • 10,600
    • 9
    • 48
    • 75
    Celdor
    • 2,437
    • 2
    • 23
    • 44
    • What version of Matlab are you using? Shouldn't the name-value pair be `'Hessian','on'`? – horchler Oct 12 '13 at 14:32
    • Hi. I recently switched to **MATLAB** 2013. I used to use `optimset` but now there's another command called `optimoptions` but I tried both with `'Hessian','on'` and it did not change the result. The function still finds local minimum at starting point. This is quite mysterious to me, to be frank. – Celdor Oct 12 '13 at 19:05

    0 Answers0