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.

Optimizing Anonymous Functions Instead of M-FilesThe second output argument, searchdir, contains the search directions forfmincon at each iteration. The search direction is a vector pointing from thepointcomputedatthecurrentiterationtothepointcomputedatthenextiteration.searchdirsearchdir =-0.3679 0.2500-4.2029 2.21990.7708 -1.1947-3.8108 -2.0268-1.3625 -0.2432-0.9552 0.0346-0.5241 -0.0061-0.0003 0.0003Optimizing Anonymous Functions Instead of M-FilesThe routines in <strong>Optimization</strong> <strong>Toolbox</strong> also perform optimization on anonymousfunctions, as well as functions defined by M-files.To represent a mathematical function at the command line, create ananonymous function from a string expression. For example, you can createan anonymous version of the humps function (use the command type humpsto see the M-file function humps.m):fh = @(x)1./((x-0.3).^2 + 0.01) + 1./((x-0.9).^2 + 0.04)-6;The constructor for an anonymous function returns a function handle, shownas fh above, that you can use in calling the function. Use the usual MATLABfunction calling syntax to call a function by means of its function handle.Evaluate the anonymous function at 2.0:fh(2.0)ans =-4.8552You can also pass handle fh to an optimization routinetominimizeit:2-95

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

Saved successfully!

Ooh no, something went wrong!