e661.m

来自「matlab算法集 matlab算法集」· M 代码 · 共 50 行

M
50
字号
%------------------------------------------------------------------
% Example 6.6.1: Davidon-Fletcher-Powell Method 
%------------------------------------------------------------------
   clc
   clear
   global a b q r
   a = 3;		% coordinates of minimum
   b = 3;
   q = 8;		% orders of objective terms
   r = 4;
   n = 2;
   m = 1000;
   p = 100;
   v = n;
   tol = 2.e-7;
   d = 6;
   x  = zeros (n,1);
   x1 = zeros (p,1);
   x2 = zeros (p,1);
   Y  = zeros (p,p); 

% Find a minimum 

   fprintf ('Example 6.6.1: Davidon-Fletcher-Powell Method\n');
   [x,ev,j] = dfp (x,tol,v,m,'funf661');
   fprintf ('\nIterations = %g',j);
   fprintf ('\nFunction evaluations = %g',ev);
   fprintf ('\nOptimal x    = [%.7f,%.7f]',x);
   fprintf ('\nf(x)         = %.7f\n',funf661(x)); 
   
% Plot the objective function 

   for i = 1 : p
      x1(i) = (i-1)*d/(p-1);
      x2(i) = (i-1)*d/(p-1);
   end
   for i = 1 : p
      for j = 1 : p
      	 x(1) = x1(i);
      	 x(2) = x2(j);
         Y(i,j) = funf661(x);
      end
   end
   plotxyz (x1,x2,Y,'','x_1','x_2','f(x)');


   


⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?