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.

2 TutorialEquality Constrained ExampleFor routines that permit equality constraints, nonlinear equality constraintsmust be computed in the M-file with the nonlinear inequality constraints. Forlinear equalities, the coefficients of the equalities are passed in through thematrix Aeq and the right-hand-side vector beq.For example, if you have the nonlinear equality constraintnonlinear inequality constraint, rewrite them asand theand then solve the problem using the following steps.Step1: WriteanM-fileobjfun.m.function f = objfun(x)f = exp(x(1))*(4*x(1)^2+2*x(2)^2+4*x(1)*x(2)+2*x(2)+1);Step 2: Write an M-file confuneq.m for the nonlinearconstraints.function [c, ceq] = confuneq(x)% Nonlinear inequality constraintsc = -x(1)*x(2) - 10;% Nonlinear equality constraintsceq = x(1)^2 + x(2) - 1;Step 3: Invoke constrained optimization routine.x0 = [-1,1];% Make a starting guess at the solutionoptions = optimset('LargeScale','off');[x,fval] = fmincon(@objfun,x0,[],[],[],[],[],[],...@confuneq,options)[c,ceq] = confuneq(x) % Check the constraint values at xAfter 21 function evaluations, the solution produced is2-18

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

Saved successfully!

Ooh no, something went wrong!