Page 311 - MATLAB an introduction with applications
P. 311

296 ———  MATLAB: An Introduction with Applications

                   Invoke constrained optimization routine:
                   >> x0=[–1,1];  % Initial guess at the solution
                   >> options=optimset(‘LargeScale’, ‘off’);
                   >> [x,fval]=fmincon(@objfun,x0,[],[],[],[],[],[],@confun,options)
                   Optimization terminated: first-order optimality measure less
                    than options.TolFun and maximum constraint violation is less
                    than options.TolCon.
                   Active inequalities (to within options.TolCon = 1e–006):
                     lower      upper     ineqlin   ineqnonlin
                                      1
                                      2
                   x =
                          –9.5474     1.0474
                   fval =
                           0.0236
                   >> [c,ceq]=confun(x)
                   c =
                           1.0e–007 *
                          –0.9035
                           0.9035
                   ceq =
                          []
                   Example E5.17: This is a constrained optimization example: inequalities and bounds.
                                             2
                                                 2
                                    x
                   Minimize       f  () =  e  1 x  (4x + 2x + 4x x + 2x +  0.9)
                                                 2
                                            1
                                                      1 2
                                                             2
                   subject to    2 + x x  – x  – x  ≤ 0
                                     1 2
                                           1
                                               2
                                 –x x  ≤ 0
                                   1 2
                                 x  ≥ 0
                                  1
                                 x  ≥ 0
                                  2
                                  0
                   Initial values:  x  = [–1, 1].
                   Solution:
                   MATLAB Solution [Using built-in function]:
                   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);
                   function [c,ceq]=confun(x)
                   %Nonlinear inequality constraints
                   c=[2+x(1)*x(2)–x(1)–x(2);–x(1)*x(2)–10];
                   %Nonlinear inequality constraints
                   ceq=[];
   306   307   308   309   310   311   312   313   314   315   316