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.

Examples That Use Standard Algorithms• The Hessian and Jacobian multiply functions, HessMult and JacobMultrespectively, for the large-scale fmincon, fminunc, lsqnonlin, lsqcurvefitand fsolve• An output functionSometimes these functions might require some additional parameters besidestheindependentvariable. Therearetwowaystoprovidetheseadditionalparameters to the function:• Parameterize your function and then create a function handle to ananonymous function that calls your function. This is explained in“Parameterizing Your Function Using an Anonymous Function” on page2-21.• Write your function as a nested function within an outer function thatcalls the solver. This method has the additional advantage that you canshare variables between your functions, as explained in “ParameterizingYour Function as a Nested Function” on page 2-19.Parameterizing Your Function Using an Anonymous FunctionAs an example, suppose you want to find the zeros of the function ellipj usingfsolve. fsolve expects the objective function to take one input argument, butthe ellipj function takes two, u and m. You can see this function by typingtype ellipjYou are solving for the variable u, whiledm is simply a second parameterto specify which Jacobi elliptic function. To look for a zero near u0 = 3 form = 0.5, you can create a function handle to an anonymous function thatcaptures the current value of m from the workspace. Then, when the solverfsolve calls this function handle, the parameter m exists and ellipj will becalled with two arguments. You pass this function handle to fsolve with thefollowing commands:u0 = 3;m = 0.5;options = optimset('Display','off'); % Turn off Displayx = fsolve(@(u) ellipj(u,m), u0, options)x =2-21

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

Saved successfully!

Ooh no, something went wrong!