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 TutorialUsing the <strong>Optimization</strong> FunctionsThis section provides some basic information about using the optimizationfunctions.Defining the Objective FunctionMany of the optimization functions require you to create a MATLAB functionthat computes the objective function. The function should accept vectorinputs and return a scalar output of type double. Therearetwowaystocreate the objective function:• Create an anonymous function at the command line. For example, to createan anonymous function for x 2 ,entersquare = @(x) x.^2;Youthencallthe optimization function with square as the first inputargument. You can use this method if the objective function is relativelysimple and you do not need to use it again in a future MATLAB session.• Write an M-file for the function. For example, to write the function x 2 as aM-file, open a new file in the MATLAB editor and enter the following code:function y = square(x)y = x.^2;You can then call the optimization function with @square as the first inputargument. The @ sign creates a function handle for square. Use thismethod if the objective function is complicated or you plan to use it formore than one MATLAB session.Note Because the functions in <strong>Optimization</strong> <strong>Toolbox</strong> only accept inputs oftype double, user-supplied objective and nonlinear constraint functions mustreturn outputs of type double.Maximizing Versus MinimizingThe optimization functions in the toolbox minimize the objective function. Tomaximize a function f, apply an optimization function to minimize -f. The2-6

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

Saved successfully!

Ooh no, something went wrong!