Page 314 - MATLAB an introduction with applications
P. 314

Optimization ———  299

                   Solution:
                   MATLAB Solution [Using built-in function]:
                   The objective function nd its gradient re-defined in the m-file objfun.m as follows:

                   function f=objfun(x)
                   f=exp(x(1))*(4*x(1)^2+2*x(2)^2+4*x(1)*x(2)+2*x(2)+0.9);
                   The m-file confuneq.m contains the equality and inequality constraints:
                   function [c,ceq]=confuneq(x)
                   c=–x(1)*x(2)–10;
                   ceq=x(1)^2+x(2)–1;
                   Define a guess at the solution:
                   >> x0=[–1,1];
                   We will use the option as below:
                   >> options=optimset(‘LargeScale’, ‘off’);
                   Call the optimization algorithm:
                   >> [x,fval,exitflag,output]=fmincon(@objfun,x0,[],[],[],[],[],[],@confuneq,
                   options);
                   Optimization terminated: first-order optimality measure less than options.
                   TolFun
                    and maximum constraint violation is less than options.TolCon.
                   No active inequalities.
                   >> x
                   x =
                          –0.7488     0.4393
                   The function value at the solution is
                   >> fval
                   fval =
                           1.4621

                   The constraint values at the solution are
                   >> [c,ceq]=confuneq(x)

                   c =
                          –9.6710
                   ceq =
                           6.4376e–009
                   The total number of function evaluations was
                   >> output.funcCount
                   ans =
                          21
                   Changing the default termination tolerances
   309   310   311   312   313   314   315   316   317   318   319