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.

Calling an Output Function IterativelyOutput FunctionYou specify the output function in the options structure as follows:options = optimset('OutputFcn', @outfun)where outfun is the name of the output function. When you call anoptimization function with options as an input, the optimization functioncalls outfun at each iteration of its algorithm.In general, outfun can be any MATLAB function, but in this example, it isa nested subfunction of the M-filedescribedin“CreatingtheM-FilefortheExample” on page 2-90. The following code defines the output function:function stop = outfun(x,optimValues,state)stop = false;switch statecase 'init'hold oncase 'iter'% Concatenate current point and objective function% value with history. x must be a row vector.history.fval = [history.fval; optimValues.fval];history.x = [history.x; x];% Concatenate current search direction with% searchdir.searchdir = [searchdir;...optimValues.searchdirection'];plot(x(1),x(2),'o');% Label points with iteration number.text(x(1)+.15,x(2),num2str(optimValues.iteration));case 'done'hold offotherwiseendendSee “Using Function Handles with Nested Functions” in the MATLABProgramming documentation for more information about nested functions.2-89

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

Saved successfully!

Ooh no, something went wrong!