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.

fzerowrite an M-file called f.m.function y = f(x)y = x.^3-2*x-5;Tofindthezeronear2, enterz = fzero(@f,2)z =2.0946Since this function is a polynomial, the statement roots([1 0 -2 -5])finds the same real zero, and a complex conjugate pair of zeros.2.0946-1.0473 + 1.1359i-1.0473 - 1.1359iIf fun is parameterized, you can use anonymous functions to capture theproblem-dependent parameters. For example, suppose you want to findazeroofthefunctionmyfun defined by the following M-file function.function f = myfun(x,a)f = cos(a*x);Note that myfun has an extra parameter a, soyoucannotpassitdirectlyto fzero. To optimize for a specific value of a, suchasa = 2.1 Assign the value to a.a = 2; % define parameter first2 Call fzero with a one-argument anonymous function that capturesthat value of a and calls myfun with two arguments:x = fzero(@(x) myfun(x,a),0.1)8-127

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

Saved successfully!

Ooh no, something went wrong!