14.01.2013 Views

Global Optimization Toolbox User's Guide - MathWorks

Global Optimization Toolbox User's Guide - MathWorks

Global Optimization Toolbox User's Guide - MathWorks

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

3 Using <strong>Global</strong>Search and MultiStart<br />

3-84<br />

Create 200 data points and responses. Use the values a =–3,b =1/4,c =1/2,<br />

and d = 1. Include random noise in the response.<br />

rng default % for reproducibility<br />

N = 200; % number of data points<br />

preal = [-3,1/4,1/2,1]; % real coefficients<br />

xdata = 5*rand(N,2); % data points<br />

ydata = fitfcn(preal,xdata) + 0.1*randn(N,1); % response data with noise<br />

Step 3. Set bounds and initial point.<br />

Set bounds for lsqcurvefit. There is no reason for d to exceed π in absolute<br />

value, because the sine function takes values in its full range over any<br />

interval of width 2π. Assume that the coefficient c must be smaller than 20 in<br />

absolute value, because allowing a very high frequency can cause unstable<br />

responses or spurious convergence.<br />

lb = [-Inf,-Inf,-20,-pi];<br />

ub = [Inf,Inf,20,pi];<br />

Set the initial point arbitrarily to (5,5,5,0).<br />

p0 = 5*ones(1,4); % Arbitrary initial point<br />

p0(4) = 0; % so the initial point satisfies the bounds<br />

Step 4. Find the best local fit.<br />

Fit the parameters to the data, starting at p0.<br />

[xfitted,errorfitted] = lsqcurvefit(fitfcn,p0,xdata,ydata,lb,ub)<br />

Local minimum possible.<br />

lsqcurvefit stopped because the final change in the sum of squares relative<br />

its initial value is less than the default value of the function tolerance.<br />

xfitted =<br />

-2.6149 -0.0238 6.0191 -1.6998<br />

errorfitted =<br />

28.2524

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

Saved successfully!

Ooh no, something went wrong!