Page 162 - 数学建模算法与应用
P. 162

Mathematical Modeling Algorithms and Applications
             数学建模算法与应用









                  编写 M 文件 detaf.m,定义函数 f (x) 及其梯度列向量如下
                  function [f,df]=detaf(x);
                  f=x(1)^2+25*x(2)^2;

                  df=[2*x(1)

                  50*x(2)];
                  2. 编写主程序文件 zuisu.m 如下:
                  clc

                  x=[2;2];

                  [f0,g]=detaf(x);
                  while norm(g)>0.000001

                   p=-g/norm(g);
                   t=1.0;f=detaf(x+t*p);

                   while f>f0
                   t=t/2;

                   f=detaf(x+t*p);
                   end

                  x=x+t*p;
                  [f0,g]=detaf(x);

                  end
                  x,f0

                 (二) Newton 法
                                      k
                  考虑目标函数 f 在点 x 处的二次逼近式



                  假定 Hesse 阵



             152
   157   158   159   160   161   162   163   164   165   166   167