12.07.2015 Views

What Is Optimization Toolbox?

What Is Optimization Toolbox?

What Is Optimization Toolbox?

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.

fminuncx0 = [1,1];[x,fval] = fminunc(@myfun,x0)After a couple of iterations, the solution, x, and the value of the functionat x, fval, are returned.x =1.0e-006 *0.2541 -0.2029fval =1.3173e-013To minimize this function with the gradient provided, modify the M-filemyfun.m so the gradient is the second output argumentfunction [f,g] = myfun(x)f = 3*x(1)^2 + 2*x(1)*x(2) + x(2)^2;if nargout > 1g(1) = 6*x(1)+2*x(2);g(2) = 2*x(1)+2*x(2);end% Cost functionand indicate that the gradient value is available by creating anoptimization options structure with the GradObj option set to 'on'using optimset.options = optimset('GradObj','on');x0 = [1,1];[x,fval] = fminunc(@myfun,x0,options)After several iterations the solution, x, andfval, the value of thefunction at x, are returned.8-87

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

Saved successfully!

Ooh no, something went wrong!