12.07.2015 Views

What Is Optimization Toolbox?

What Is Optimization Toolbox?

What Is Optimization Toolbox?

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

2 TutorialThe arguments that the optimization function passes to outfun are• x — The point computed by the algorithm at the current iteration.• optimValues — Structure containing data from the current iteration.The example uses the following fields of optimValues:- optimValues.iteration — Number of the current iteration- optimValues.fval — Current objective function value- optimValues.searchdirection — Current search direction• state — The current state of the algorithmFor more information about these arguments, see “Output Function” on page6-16.Creating the M-File for the ExampleTo create the M-file for the example:1 Open a new M-file in the MATLAB editor.2 Copy and paste the following code into the M-file:function [history,searchdir] = runfmincon% Set up shared variables with OUTFUNhistory.x = [];history.fval = [];searchdir = [];% call optimizationx0 = [-1 1];options = optimset('outputfcn',@outfun,'display','iter',...'largescale','off');xsol = fmincon(@objfun,x0,[],[],[],[],[],[],@confun,options);function stop = outfun(x,optimValues,state)stop = false;2-90

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

Saved successfully!

Ooh no, something went wrong!