What Is Optimization Toolbox?

What Is Optimization Toolbox? What Is Optimization Toolbox?

cda.psych.uiuc.edu
from cda.psych.uiuc.edu More from this publisher
12.07.2015 Views

fzerooutput-4 Complex function value wasencountered during search foran interval containing a signchange.-5 Algorithm might haveconverged to a singularpoint.Structure containing information about theoptimization. The fields of the structure arealgorithmfuncCountintervaliterationsiterationsmessageAlgorithm usedNumber of functionevaluationsNumber of iterations taken tofind an intervalNumber of zero-findingiterationsExit messageExamples Calculate by finding the zero of the sine function near 3.x = fzero(@sin,3)x =3.1416Tofindthezeroofcosinebetween1 and 2, enterx = fzero(@cos,[1 2])x =1.5708Note that cos(1) and cos(2) differ in sign.To find a zero of the function8-126

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

fzerooutput-4 Complex function value wasencountered during search foran interval containing a signchange.-5 Algorithm might haveconverged to a singularpoint.Structure containing information about theoptimization. The fields of the structure arealgorithmfuncCountintervaliterationsiterationsmessageAlgorithm usedNumber of functionevaluationsNumber of iterations taken tofind an intervalNumber of zero-findingiterationsExit messageExamples Calculate by finding the zero of the sine function near 3.x = fzero(@sin,3)x =3.1416Tofindthezeroofcosinebetween1 and 2, enterx = fzero(@cos,[1 2])x =1.5708Note that cos(1) and cos(2) differ in sign.To find a zero of the function8-126

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

Saved successfully!

Ooh no, something went wrong!