【matlab基础知识代码】(十八)无约束最优化问题

min下面的x称为优化向量或者是决策变量

匿名函数法

>> f=@(x)(x(1)^2-2*x(1))*exp(-x(1)^2-x(2)^2-x(1)*x(2)); x0=0; 0; x,b,c,d=fminsearch(f,x0),

x =

0.6111

-0.3056

b =

-0.6414

c =

1

d =

包含以下字段的 struct:

iterations: 72

funcCount: 137

algorithm: 'Nelder-Mead simplex direct search'

message: '优化已终止:↵ 当前的 x 满足使用 1.000000e-04 的 OPTIONS.TolX 的终止条件,↵F(X) 满足使用 1.000000e-04 的 OPTIONS.TolFun 的收敛条件↵'

使用函数fminunc():

>> x,b,c,d=fminunc(f,0;.0)

Local minimum found.

Optimization completed because the size of the gradient is less than

the value of the optimality tolerance.

<stopping criteria details>

x =

0.6110

-0.3055

b =

-0.6414

c =

1

d =

包含以下字段的 struct:

iterations: 7

funcCount: 27

stepsize: 1.8220e-04

lssteplength: 1

firstorderopt: 1.8030e-06

algorithm: 'quasi-newton'

message: '↵Local minimum found.↵↵Optimization completed because the size of the gradient is less than↵the value of the optimality tolerance.↵↵<stopping criteria details>↵↵Optimization completed: The first-order optimality measure, 6.010135e-07, is less ↵than options.OptimalityTolerance = 1.000000e-06.↵↵'

绘制三维等高线 ,获得并叠印中间结果

Matlab 复制代码
>>  [x,y]=meshgrid(-3:.1:3, -2:.1:2); z=(x.^2-2*x).*exp(-x.^2-y.^2-x.*y); contour(x,y,z,30);
 ff=optimset; 
ff.OutputFcn=@myout; x0=[2 1]; 
x=fminunc(f,x0,ff)

Local minimum found.

Optimization completed because the size of the gradient is less than
the value of the optimality tolerance.

<stopping criteria details>

x =

    0.6110   -0.3055

最优化求解函数的另一种调用方法

建立最优化问题的"结构体"模型

Matlab 复制代码
>>  problem.solver='fminunc'; problem.options=optimset; problem.objective=@(x)(x(1)^2-2*x(1))*exp(-x(1)^2-x(2)^2-x(1)*x(2)); problem.x0=[2; 1]; [x,b,c,d]=fminunc(problem)

Local minimum found.

Optimization completed because the size of the gradient is less than
the value of the optimality tolerance.

<stopping criteria details>

x =

    0.6110
   -0.3055


b =

   -0.6414


c =

     1


d = 

  包含以下字段的 struct:

       iterations: 7
        funcCount: 66
         stepsize: 1.7059e-04
     lssteplength: 1
    firstorderopt: 7.4506e-09
        algorithm: 'quasi-newton'
          message: '↵Local minimum found.↵↵Optimization completed because the size of the gradient is less than↵the value of the optimality tolerance.↵↵<stopping criteria details>↵↵Optimization completed: The first-order optimality measure, 7.437017e-09, is less ↵than options.OptimalityTolerance = 1.000000e-06.↵↵'
相关推荐
ZYJCSZKJ4 分钟前
AI数字人直播系统的技术架构与多方言交互实现方案——基于广西区域商业场景的工程实践
人工智能·架构·交互
珐恩AI-人工智能12 分钟前
大模型意图召回偏差分析:GEO如何解决“有收录却不触发问答曝光”的难题
大数据·前端·人工智能·html·流量运营·geo优化
城管不管13 分钟前
重生——第十次面试之开源中国一面挂
java·linux·开发语言·算法·面试·职场和发展·开源
Java小白笔记17 分钟前
Windows系统免软件命令激活
java·网络·人工智能·windows·ai·ai编程
王志来1379447300817 分钟前
从分散到集成:工控服务器机箱采购如何实现“一站式”破局
运维·服务器·人工智能·python
万岳科技系统开发18 分钟前
AI数字人直播系统搭建从需求分析到正式上线全流程解析
人工智能·需求分析
小O的算法实验室23 分钟前
IEEE TCDS,基于改进双神经网络三维未知环境多机器人协同区域覆盖搜索
人工智能·神经网络·机器人
无凭28 分钟前
DeepSeek Harness 为什么需要 Cordis:从 Everything is Plugin 开始看
人工智能·架构
炮哥聊AI29 分钟前
会调工具的 Agent 只值一半:真正的业务智能体,得会"记仇"
人工智能·agent
字节跳动数据库31 分钟前
火山 PostgreSQL Serverless × 飞书妙搭:把 AI 装进数据库,一句话唤醒数据智能
数据库·人工智能·后端