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

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


                  d2f=[2*x(1)^2+2*x(2)^2,4*x(1)*x(2)
                   4*x(1)*x(2),300*x(2)^2+2*x(1)^2];
                  3. 编写主程序文件 example5.m 如下:

                  clc
                  x=[2;2];
                  [f0,g1,g2]=nwfun(x);
                  while norm(g1)>0.00001

                   p=-inv(g2)*g1;
                   x=x+p;
                  -41-

                   [f0,g1,g2]=nwfun(x);
                  end
                  x, f0
                  如果目标函数是非二次函数,一般地说,用 Newton 法 法通过有限轮迭代并
             不能保证可求得其最优解。为了提高计算精度,在迭代时可以采用变步长计算上

             述问题,编写主程序文件
                  example5_2 如下:
                  clc,clear

                  x=[2;2];
                  [f0,g1,g2]=nwfun(x);
                  while norm(g1)>0.00001
                    p=-inv(g2)*g1;p=p/norm(p);
                    t=1.0;f=nwfun(x+t*p);

                    while f>f0
                    t=t/2;f=nwfun(x+t*p);
                   end

                  x=x+t*p;
                  [f0,g1,g2]=nwfun(x);
                  end
                  x,f0



             154
   159   160   161   162   163   164   165   166   167   168   169