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.

lsqcurvefitfunThe function you want to fit. fun is a function that takesavectorx and returns a vector F, the objective functionsevaluated at x. The function fun can be specified as afunction handle for an M-file functionx = lsqcurvefit(@myfun,x0,xdata,ydata)where myfun is a MATLAB function such asfunction F = myfun(x,xdata)F = ...% Compute function values at xfun can also be a function handle for an anonymousfunction.f = @(x,xdata)x(1)*xdata.^2+x(2)*sin(xdata),...'x','xdata';x = lsqcurvefit(f,x0,xdata,ydata);If the user-defined values for x and F are matrices, they areconverted to a vector using linear indexing.Note fun should return fun(x,xdata), and not thesum-of-squares sum((fun(x,xdata)-ydata).^2).The algorithm implicitly squares and sumsfun(x,xdata)-ydata.If the Jacobian can also be computed and the Jacobianoption is 'on', setbyoptions = optimset('Jacobian','on')then the function fun must return, in a second outputargument, the Jacobian value J, amatrix,atx. Notethatby checking the value of nargout the function can avoidcomputing J when fun is called with only one outputargument (in the case where the optimization algorithmonly needs the value of F but not J).function [F,J] = myfun(x,xdata)F = ...% objective function values at xif nargout > 1 % two output argumentsJ = ... % Jacobian of the function evaluated at xend8-143

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

Saved successfully!

Ooh no, something went wrong!