Page 295 - MATLAB an introduction with applications
P. 295

280 ———  MATLAB: An Introduction with Applications


                   end
                   V = X – xOld;
                   [a,b] = goldBracket(@fLine,0.0,h);
                   [s,fMin] = goldSearch(@fLine,a,b);
                   X = X + s*V;
                   % convergence criterion
                   if sqrt(dot(X–xOld,X–xOld)/n) < tol
                   xMin = X; nCyc = j; return
                   end
                   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
                   error(‘No converge’)

                   function z = fLine(s)
                   global X FUNC V
                   z = feval(FUNC,X+s*V);

                   Example E5.7: Use Fletcher-Reeves method to locate the minimum of function

                                          2
                                              2
                                 F(x) = 10x + 3 − 10 , x + 2x .
                                                  x
                                                   1
                                          1
                                              2
                                                     2
                                                          1
                                   T
                   Start with [0    0.05] .
                   Solution:
                   Global X FUNC DFUNC V
                   >> FUNC=@fex3_19;DFUNC=@dfex3_19;X=[0,0.5];
                   >> [xMin,fMin,nCyc]=fletcherReeves
                   xMin =
                          –0.6000
                          –1.0000
                   fMin =
                          –0.6000
                   nCyc =
                          3
   290   291   292   293   294   295   296   297   298   299   300