Matlab fmincon函数
文章目录
- 函数功能
- 函数表达及用法
- ==**trust-region-reflective算法的说明 (梯度)**==
- **==Hessian矩阵应用说明==**
- 返回值
函数功能
获取约束的非线性多变量函数的最小值
样式:
其中,c(x), ceq(x) 分别表示非线性的约束条件,而A, Aeq表示的是线性约束。
函数表达及用法
x = fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon,options)
- fun
minimizes fun - 初始值
starts at x0,x0 can be a scalar, vector, or matrix. - 线性约束
attempts to find a minimizer x of the function described in fun subject to the linear inequalities Ax ≤ b,Aeqx = beq,and the range lb ≤ x ≤ ub - 非线性约束
the nonlinear inequalities c(x) or equalities ceq(x) defined in nonlcon
For example,x = fmincon(@myfun,x0,A,b,Aeq,beq,lb,ub,@mycon) where mycon is a MATLAB function such as function [c,ceq] = mycon(x) c = ... % Compute nonlinear inequalities at x. ceq = ... % Compute nonlinear equalities at x.
- 选项
Optimization options, specified as the output of optimoptions or a structure such as optimset returns
trust-region-reflective算法的说明 (梯度)
针对SpecialObjectiveGradient 将梯度计算加入目标函数中,以实现更快或更可靠的计算。将梯度计算作为条件化输出包含在目标函数文件中
function [f,g] = rosenbrockwithgrad(x)
% Calculate objective f
f = 100*(x(2) - x(1)^2)^2 + (1-x(1))^2;if nargout > 1 % gradient requiredg = [-400*(x(2)-x(1)^2)*x(1)-2*(1-x(1));200*(x(2)-x(1)^2)];
end
注:
1.目标函数(标量)作为第一个输出,梯度(向量)作为第二个输出(应该是默认的)
2.使用 optimoptions 将 SpecifyObjectiveGradient 选项设置为 true。如果有的化,也将 SpecifyConstraintGradient 选项设置为 true。
fun = @rosenbrockwithgrad;
x0 = [-1,2];
A = [];
b = [];
Aeq = [];
beq = [];
lb = [-2,-2];
ub = [2,2];
nonlcon = [];
x = fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon,options)
调用
options = optimoptions('fmincon','SpecifyObjectiveGradient',true);输出结果
Local minimum found that satisfies the constraints.Optimization completed because the objective function is non-decreasing in
feasible directions, to within the value of the optimality tolerance,
and constraints are satisfied to within the value of the constraint tolerance.x =1.0000 1.0000
Hessian矩阵应用说明
上例代码修改为
function [f, g, H] = rosenboth(x)
% Calculate objective f
f = 100*(x(2) - x(1)^2)^2 + (1-x(1))^2;if nargout > 1 % gradient requiredg = [-400*(x(2)-x(1)^2)*x(1)-2*(1-x(1));200*(x(2)-x(1)^2)];if nargout > 2 % Hessian requiredH = [1200*x(1)^2-400*x(2)+2, -400*x(1);-400*x(1), 200]; endend
注:
1.使用 fmincon ‘trust-region-reflective’ 和 ‘interior-point’ 算法以及 fminunc ‘trust-region’ 算法来包含二阶导数。根据信息的类型和算法,可通过几种方法来包括 Hessian 矩阵信息。
2. 您还必须包含梯度(将 SpecifyObjectiveGradient 设置为 true,如果适用,还必须将 SpecifyConstraintGradient 设置为 true)以便包含 Hessian 矩阵
调用:
options = optimoptions('fminunc','Algorithm','trust-region',...'SpecifyObjectiveGradient',true,'HessianFcn','objective');
适用于 fmincon 内点算法的 Hessian 矩阵. 该 Hessian 矩阵是拉格朗日函数的 Hessian 矩阵,其中 L(x,λ) 是
g 和 h 是向量函数,分别表示所有不等式和等式约束(指有界、线性和非线性约束),因此最小化问题的公式为
拉格朗日方程的 Hessian 矩阵公式为:
ssian 是 n×n 矩阵(稀疏或稠密),其中 n 是变量的数目。如果 hessian 很大并且非零项相对较少,请将 hessian 表示为稀疏矩阵,以节省运行时间和内存。lambda 是具有与非线性约束相关联的拉格朗日乘数向量的结构体:
lambda.ineqnonlin
lambda.eqnonlin
fmincon 计算结构体 lambda,并将其传递给您的 Hessian 函数。hessianfcn 必须计算上式中的总和。通过设置以下选项表明您提供了 Hessian 函数:
ptions = optimoptions('fmincon','Algorithm','interior-point',...'SpecifyObjectiveGradient',true,'SpecifyConstraintGradient',true,...'HessianFcn',@hessianfcn);
function Hout = hessianfcn(x,lambda)
% Hessian of objective
H = [1200*x(1)^2-400*x(2)+2, -400*x(1);-400*x(1), 200];
% Hessian of nonlinear inequality constraint
Hg = 2*eye(2);
Hout = H + lambda.ineqnonlin*Hg;
将 hessianfcn 保存到 MATLAB 路径。为了完成此示例,包含梯度的约束函数为
function [c,ceq,gc,gceq] = unitdisk2(x)
c = x(1)^2 + x(2)^2 - 1;
ceq = [ ];if nargout > 2gc = [2*x(1);2*x(2)];gceq = [];
end
调用:
fun = @rosenboth;
nonlcon = @unitdisk2;
x0 = [-1;2];
options = optimoptions('fmincon','Algorithm','interior-point',...'SpecifyObjectiveGradient',true,'SpecifyConstraintGradient',true,...'HessianFcn',@hessianfcn);
[x,fval,exitflag,output] = fmincon(fun,x0,[],[],[],[],[],[],@unitdisk2,options);
- Algorithm
返回值
[x,fval,exitflag,output,lambda,grad,hessian] = fmincon(___) additionally returns:
x— variable
fval— the value of the objective function fun
exitflag— describes the exit condition of fmincon,
output— a structure output with information about the optimization process.
lambda — Structure with fields containing the Lagrange multipliers at the solution x.
grad — Gradient of fun at the solution x.
hessian — Hessian of fun at the solution x. See fmincon Hessian.
有关拉格朗日算子到底是啥,可参考:如何理解拉格朗日乘子法?
梯度和海森矩阵请参考:牛顿法与拟牛顿法学习笔记
- exitflag
- output
- lambda
- Hessian
Matlab fmincon函数相关推荐
- [转载]Matlab fmincon函数用法
原文地址:Matlab fmincon函数用法作者:长笛人倚楼Gloria 这个函数在之前优化工具箱一文中已经介绍过,由于其应用广泛,所以这里通过实例单独整理一下其用法. 一.基本介绍 求解问题的标准 ...
- Matlab fmincon函数用法
这个函数在之前优化工具箱一文中已经介绍过,由于其应用广泛,所以这里通过实例单独整理一下其用法. 一.基本介绍 求解问题的标准型为 min F(X) s.t AX <= b AeqX = beq ...
- MATLAB fmincon函数 进阶资料(磕盐记录)
说明: 阅读本文前,请先阅读 参考网址1-基础使用 中的案例,本文适用于运行过 fmincon函数 案例的读者!!! 一.fmincon函数:算法介绍 fmincon函数中,可以调用五种算法(具体每种 ...
- 多参量最优化matlab,fmincon函数优化多个参数
本帖最后由 sangzhenyu 于 2020-10-30 13:57 编辑 function G=MiuCal(X) %参数:Miu:生长速率:MiuMax:生长速率最大值:Ks:底物饱和常数: % ...
- matlab fmincon函数格式,求matlab中fmincon函数格式的中文解释?谢谢!!
fmincon是Matlab优化工具箱(OptimizationToolbox)中的一个命令,用来求有限制条件(约束)的非线性目标函数的极小化问题.x=fmincon(fun,x0,A,b),用于求解 ...
- matlab fmincon函数格式,求助 fmincon 函数调用格式说明
function KineticsEst clear all clc k0 = [0.5 0.5 0.5 0.5 0.5]; % 参数初值 lb = [0 0 0 0 ...
- matlab fmincon函数 用法,matlab中fmincon函数的用法?
我建立一个myfunction.m文件function f=myfuncion(x) M=[2,-1;-1,2]; B=[3;-3]; f=1/2*x'*M*x+B'*x;然后在matlab窗口中输入 ...
- Matlab fmincon函数实例 及 其句柄形式之参数传递
% min F(X) % s.t % AX <= b % AeqX = beq % G(x) <= 0 % Ceq(X) = 0 % VLB <= X <= VUBclear ...
- matlab fmincon 函数
对于大型任务,可以用并行运算 https://ww2.mathworks.cn/help/optim/ug/parallel-computing-example-optim-global.html 局 ...
最新文章
- github checkout 使用
- centos mysql压缩文件直接恢复_Centos下mysql数据库备份与恢复的方法
- .NET MVC对接POLYV——HTML5播放器播放加密视频
- 《Adobe Illustrator大师班:经典作品与完美技巧赏析》—Bree Léman
- [资料]有关MS SQL 2000安全问题
- python免费入门_python入门 2018最新最全学习资料免费获取啦
- 编译实验(一)词法分析
- view.post不执行的坑点
- java 动态单元格涂色_如何编写自定义DefaultTableCellRenderer来着色特定单元格并“保留”其他单元格的颜色,Java...
- 基础知识(十二)Opengl回顾记录
- 专业英语笔记:Spring框架
- Atitit 提升可读性的艺术 目录 1. 几大原则	2 1.1. 直接原则,无脑原则。。。	2 2. 本地化命名法	2 2.1. 可以使用管理命名法 多个api 比如old api,new ap
- 定位相关MATLAB仿真代码与在线MATLAB仿真平台
- nrf52840合成4合1烧录文件
- 【唯美日出win7热门主题】
- Excel2010创建包含数据有效性的xls文件,再打开时有效性变无效
- 关于Android studio Translation插件提示“更新 TKK 失败,请检查网络连接”问题
- 手机本地文档文件不能扫描出来的问题
- 开源直播美颜SDK工具算法分析
- nginx服务器缓存文件清理,清除nginx缓存文件并不总是有效
热门文章
- inherits java_Java 继承(Inherits)
- 谷歌为什么从WebKit中建立一个Blink分支
- Ubuntu18.04与Win10共享文件
- 所有中文字符的Unicode字符范围——charCodeAt()方法
- POI进阶操作插入本地图片/增加超链接/筛选/增加下拉选项/画图形/画线
- 产业数字化爆发,松山湖开发者村打通数实融合“最后一公里”
- Pipeline组项目Postmortem
- 熟练背诵的Babel7知识(新手建议熟练背诵)
- 学系统集成项目管理工程师(中项)系列26_新兴信息技术
- 上海这些交通类的博物馆,你都去过吗?