第三周数模选修课作业

时间:2021-08-28 07:49:07

第三周数模选修课作业

1. 题目

Rosenbrock函数\(f(x_{1},x_{2})=100(x_{2}-x_{1}^{2})^{2}+(1+x_{1})^{2}\)的最优解(极小)为\(x^{\*}=(1,1)\),极小值为\(f^{*}=0\),试用不同算法(搜索方向和步长搜索)求数值最优解。初值选为\(x_{0}=(-1.2,2)\)

2. 函数图像的输出

先输出带方格的函数的图像,matlab代码如下

[x,y]=meshgrid(-2:0.1:2,-1:0.1:3);
z=100*(y-x.^2).^2+(1-x).^2;
mesh(x,y,z)

得到图像如下:
第三周数模选修课作业

再画出等高线图如下:
第三周数模选修课作业

3. 求解

在修改步长时,Matlab报了如下的错误:

>> options=optimset('linesearchtype','quadcubic')
Error using optimset (line 209)
The LineSearchType option is no longer valid. It was only used by the Gauss-Newton algorithm, which is no
longer used in Optimization toolbox solvers.

从网上查阅资料得知,2011版之后的Matlab工具箱已经不再支持这一功能,因此无法利用此方法修改步长算法。我们暂时只对搜索方向进行实验。

搜索方向('BFGS')

程序代码如下:

>> f='100*(x(2)-x(1)^2)^2+(1-x(1))^2';
>> option1=optimset('hessupdate','bfgs');
>> [x,fval,exitflag,output]=fminunc(f,[-1.2,2],option1)

结果如下

x =

    1.0000    1.0000


fval =

   2.0352e-11


exitflag =

     1


output = 

       iterations: 39
        funcCount: 144
         stepsize: 1
    firstorderopt: 4.6220e-07
        algorithm: 'quasi-newton'
          message: 'Local minimum found.

搜索方向('dfp')

>> f='100*(x(2)-x(1)^2)^2+(1-x(1))^2';
>> option1=optimset('hessupdate','dfp');
>> [x,fval,exitflag,output]=fminunc(f,[-1.2,2],option1)

结果如下:

x =

   -0.7476    0.5334


fval =

    3.1189


exitflag =

     0


output = 

       iterations: 60
        funcCount: 201
         stepsize: 11.4698
    firstorderopt: 11.1142
        algorithm: 'quasi-newton'
          message: 'Solver stopped prematurely.

fminunc stopped because it exceeded the function evalua...'

搜索方向('steepdesc')

代码如下:

>> f='100*(x(2)-x(1)^2)^2+(1-x(1))^2';
>> option1=optimset('hessupdate','steepdesc');
>> [x,fval,exitflag,output]=fminunc(f,[-1.2,2],option1)

结果如下:

x =

    1.1169    1.2482


fval =

    0.0137


exitflag =

     0


output = 

       iterations: 17
        funcCount: 201
         stepsize: 0.0018
    firstorderopt: 0.1287
        algorithm: 'quasi-newton'
          message: 'Solver stopped prematurely.

fminunc stopped because it exceeded the function evalua...'