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 Tutorialfunction y = findzero(b, c, x0)options = optimset('Display', 'off'); % Turn off Displayy = fsolve(@poly, x0, options);function y = poly(x) % Compute the polynomial.y = x^3 + b*x + c;endendThe main function, findzero, does two things:• Invokes the function fzero to find a zero of the polynomial.• Computes the polynomial in a nested function, poly, whichiscalledbyfzero.You can call findzero with any values of the coefficients b and c, whicharethen automatically passed to poly because it is a nested function.As an example, to find a zero of the polynomial with b = 2 and c = 3.5,using the starting point x0 = 0, callfindzero as follows.x = findzero(2, 3.5, 0)This returns the zerox =-1.0945Avoiding Global Variables via Anonymous andNested FunctionsThe optimization functions in the toolbox use several types of functions thatyou define, including• The objective function• The constraint functions (for fmincon, fseminf, fgoalattain, andfminimax)2-20

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

Saved successfully!

Ooh no, something went wrong!