Page 330 - MATLAB an introduction with applications
P. 330

Optimization ———  315

                   Example E5.31: Repeat problem E5.31 using Fletcher-Reeves method.
                   Solution:
                                     2
                                           2
                   Given    f (x , x ) = 7x + 5x – 8x x – 5x 1
                            1
                                               1 2
                               2
                                          2
                                     1
                   Here gradient df = [14x – 8x – 5; 10x – 8x ] T
                                           2
                                      1
                                                  2
                                                       1
                   Complete program is as follows:
                   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));


                   Functions are
                   function z=fline(s)
                   global V X
                   p1=X(1)+s*V(1);
                   p2=X(2)+s*V(2);
                   z=7*p1^2+5*p2^2–8*p1*p2–5*p1;
                   %GRADIENT FUNCTION
                   function y=df(X)
                   y=[14*X(1)–8*X(2)–5; 10*X(2)–8*X(1)];

                   The output is as follows:
                   Minimum point for this function is
                          0.657895
                          0.526316
                                                                     T
                   The actual output from MATLAB function is [0.6579  0.5263] .
   325   326   327   328   329   330   331   332   333   334   335