防灾数学分享 http://blog.sciencenet.cn/u/fzmath 防灾科技学院数学教研室

博文

MATLAB中的两个常用数值优化函数fminsearch()和fminunc()

已有 17228 次阅读 2017-9-8 23:10 |个人分类:教学辅导|系统分类:科研笔记


MATLAB中提供了两个命令:fminsearch(),fminunc(),

x = fminsearch(Fun,x0)

[x,fval,flag,out] = fminsearch(Fun,x0,opt,p1,p1,...)

fminunc 与 fminsearch 用法相同。

测试版本 MATLAB 2016b.

例1 已知 $z = f(x,y) = (x^2-x)\text{e}^{-x^2-y^2-xy}$ ,求其最小值并显示求解过程。


>> f = @(x)(x(1)^2-x(1))*exp(-x(1)^2-x(2)^2-x(1)*x(2));x0 = [2;1];

>> [x,b,c,d] = fminsearch(f,x0)

x =

  28.8538

   3.3448

b =


    0

c =

    1

d =

 包含以下字段的 struct:


   iterations: 30

    funcCount: 94

    algorithm: 'Nelder-Mead simplex direct search'

      message: '优化已终止:…'

>>  [x,b,c,d] = fminunc(f,x0)

警告: Gradient must be provided for trust-region algorithm; using quasi-newton

algorithm instead.

> In fminunc (line 395)


Local minimum found.

Optimization completed because the size of the gradient is less than

the default value of the optimality tolerance.

<stopping criteria details>



x =

   2.9047

   1.9353

b =

  1.0247e-07

c =

    1

d =

 包含以下字段的 struct:


      iterations: 13

       funcCount: 45

        stepsize: 0.0769

    lssteplength: 1

   firstorderopt: 7.0454e-07

       algorithm: 'quasi-newton'

         message: 'Local minimum found.…'




https://blog.sciencenet.cn/blog-292361-1074987.html

上一篇:无约束最优化问题求解
下一篇:MATLAB优化工具箱遗传算法函数ga()用法示例
收藏 IP: 124.238.135.*| 热度|

1 杨正瓴

该博文允许注册用户评论 请点击登录 评论 (4 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-4-27 10:33

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部