Page 329 - MATLAB an introduction with applications
P. 329

314 ———  MATLAB: An Introduction with Applications

                   Example E5.30: Repeat problem E5.30 using Fletcher-Reeves method.
                   Solution:
                                     2
                                           2
                   Given    f(x , x ) = 4x + 3x – 5x x – 8x 1
                                               1 2
                                          2
                             1
                               2
                                     1
                   Here gradient df  = [8x – 5x – 8; 6x – 5x ] T
                                                     1
                                                 2
                                      1
                                          2
                   Complete program is given below:
                   % CONJUGATE GRADIENT METHOD
                   global X V
                   X=[0;0];
                   N=length(X);
                   g0=–feval(‘df’,X);
                   V=g0;
                   n=50;
                   for i=1:n
                     [s fmin]=fminbnd(‘fline’,–10,10);
                     X=X+s*V
                     g1=–feval(‘df’,X);
                     gamma=(norm(g1)/norm(g0))^2;
                     V=g1+gamma*V;
                     g0=g1;
                   end
                   fprintf(‘Minimum point for this function is \n’);
                   fprintf(‘%f\n%f\n’,X(1),X(2));

                   This requires the following function files
                   %LINEAR FUNCTION OF s
                   function z=fline(s)
                   global V X
                   p1=X(1)+s*V(1);
                   p2=X(2)+s*V(2);
                   z=4*p1^2+3*p2^2–5*p1*p2–8*p1;
                   %GRADIENT FUNCTION
                   function y=df(X)
                   y=[8*X(1)–5*X(2)–8;6*X(2)–5*X(1)];

                   The output is as follows:
                   Minimum point for this function is
                          2.086957
                          1.739130
                   The actual output is [2.087   1.7392] T
   324   325   326   327   328   329   330   331   332   333   334