Page 327 - MATLAB an introduction with applications
P. 327

312 ———  MATLAB: An Introduction with Applications


                     X=X+s*V;
                     % IDENTIFY BIGGEST DECREASE OF F
                     % AND UPDATE SEARCH DIRECTIONS
                     imax=1; dfmax=df(1);
                     for i=2:N
                       if df(i)>dfmax    imax=i; dfmax=df(i); end
                     end
                     for i=imax:N–1
                       u(1:N,i)=u(1:N,i+1);
                     end
                     u(1:N,N)=V;
                   end
                   fprintf(‘Optimum point after %d cycles is\n’,n);
                   fprintf(‘%f\n%f\n’,X(1),X(2));


                   Function is
                   function z=fline(s)
                   global X V
                   b1=V(1);
                   b2=V(2);
                   a1=X(1);a2=X(2);
                   p1=a1+s*b1;p2=a2+s*b2;
                   z=4*p1^2+3*p2^2–5*p1*p2–8*p1;
                   Optimum point after 30 cycles is
                   2.091345
                   1.739733
                   Actual output from MATLAB function fminsearch(‘fxy’, [0 0]) is
                   2.0870
                   1.7392

                                                                          2
                                                                               2
                   Example E5.29: Find the minimum value of the function f(X) = 7x + 5x –8x x –5x  starting from (0, 0)
                                                                                         1
                                                                                    1 2
                                                                         1
                                                                               2
                   using Powell’s method.
                   Solution: The following program is used
                   global  X V
                   X=[0;0];    %STARTING POINT
                   N=length(X);% number of design variables
                   df=zeros(N,1);% decreases of f stored here
                   u=eye(N);  % columns of u store search directions V
                   n=30;  % Number of cycles
                   for j=1:n
                     xold=X;
   322   323   324   325   326   327   328   329   330   331   332