12.07.2015 Views

What Is Optimization Toolbox?

What Is Optimization Toolbox?

What Is Optimization Toolbox?

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

2 Tutoriali=1:(n-1); g = zeros(n,1);g(i) = 2*(x(i+1).^2+1).*x(i).* ...((x(i).^2).^(x(i+1).^2))+ ...2*x(i).*((x(i+1).^2).^(x(i).^2+1)).* ...log(x(i+1).^2);g(i+1) = g(i+1) + ...2*x(i+1).*((x(i).^2).^(x(i+1).^2+1)).* ...log(x(i).^2) + ...2*(x(i).^2+1).*x(i+1).* ...((x(i+1).^2).^(x(i).^2));endTo allow efficient computation of the sparse finite-difference approximation ofthe Hessian matrix H(x), the sparsity structure of H must be predetermined.In this case assume this structure, Hstr, a sparse matrix, is available in filebrownhstr.mat. Usingthe spy command you can see that Hstr is indeedsparse (only 2998 nonzeros). Use optimset to set the HessPattern optionto Hstr. When a problem as large as this has obvious sparsity structure,not setting the HessPattern option requires a huge amount of unnecessarymemory and computation because fminunc attempts to use finite differencingon a full Hessian matrix of one million nonzero entries.You must also set the GradObj option to 'on' using optimset, sincethegradient is computed in brownfg.m. Thenexecutefminunc asshowninStep2.Step 2: Call a nonlinear minimization routine with a startingpoint xstart.fun = @brownfg;load brownhstr% Get Hstr, structure of the Hessianspy(Hstr)% View the sparsity structure of Hstrn = 1000;xstart = -ones(n,1);xstart(2:2:n,1) = 1;options = optimset('GradObj','on','HessPattern',Hstr);[x,fval,exitflag,output] = fminunc(fun,xstart,options);This 1000-variable problem is solved in eight iterations and seven conjugategradient iterations with a positive exitflag indicating convergence. Thefinal function value and measure of optimality at the solution x are both close2-54

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!