当前位置:网站首页>基于Matlab解决线性规划问题
基于Matlab解决线性规划问题
2022-07-29 05:27:00 【yc_ZZ】
目录
引入:怎样理解线性和非线性
1、线性规划
2、非线性规划
1、有约束条件
2、无约束条件
3、二次规划问题
4、笔者总结
引入:
线性与非线性,常用于区别函数y = f (x)对自变量x的依赖关系。线性函数即一次函数,其图像为一条直线。其它函数则为非线性函数,其图像不是直线
在数学上,线性关系是指自变量x与因变量yo之间可以表示成y=ax+b ,(a,b为常数),即说x与y之间成线性关系。
不能表示成y=ax+b ,(a,b为常数),即非线性关系,非线性关系可以是二次,三次等函数关系,也可能是没有关系
1、线性规划(linprog)
线性规划特征:成员变量都是一次项,并且有约束条件,求最大或者最小值
线性规划得标准形式要求目标函数最小化,约束条件取等式,变量非负,不符合条件得要转化为标准形式(最多情况是加负号),
f是x1,x2,x3求最大最小值成员变量前面的系数,如果要求最大值先要转化为标准形式,最后输出前加负号,以列向量呈现。
a是约束条件成员变量前面的系数,标准形式是小于等于,如果大于等于要转换加负号,同一个式子的系数以行向量呈现(,),不同式子是列向量(;)
b是约束条件的值,以列向量呈现
aeq,beq分别是相等情况的系数和值,如果约束条件没有用"[ ]"代替,不能省略
最后输出[x,y]=linprog(f,a,b,aeq,beq,lb,ub) lb,ub分别是上下限一般由zeros(i,j)指的是i(变量数)行j列的零矩阵代替若有具体条件具体分析
f=[2;3;-5];
a=[-2 5 -1;1 3 1];
b=[-10;12];
aeq=[1 1 1];
beq=7;
[x,y]=linprog(-f,a,b,aeq,beq,zeros(3,1));
fprintf('x1=%.4f,x2=%.4f,x3=%.4f\nz:%.4f\n',x,-y);

2、非线性规划
1、无约束条件
①fminunc函数
求无约束多变量函数的最小值
x = fminunc(fun,x0)
x = fminunc(fun,x0)从x0点开始,尝试找到fun中描述的函数的一个局部最小x。点x0可以是标量、向量或矩阵。
fmincon函数是默认从你给定的x0为中心开始搜索,直至找到函数的最小值,并返回距离x0最近的函数最小值对应的x值
这样我们在计算的时候就必须预先判定函数最小值的对应的x值的大概范围
确保我们定的初值x0在所求的x附近,以减少计算量
MATLAB实现步骤
1、定义函数,并且文件要与函数名一致
2、定义脚本,先写x0[i,j],然后再调用函数,最后看工作区的结果

![]()
对比:
fminbnd单变量函数在范围内求极小值



2、有约束条件(前提是非线性)
①fmincon函数

基本语法:[x,fval]=fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon,options)
3、二次规划问题
特征:二次规划是非线性规划的一种,若某非线性规划的目标函数为自变量x的二次函数,约束条件又全是线性的,就称之为二次规划

标准形式——
首先,向量x是很容易写出的,因为f(x)包含两个变量x1和x2,因此

其次,向量f只与两个变量x1和x2的一次项有关,所以fTx=-2x1-6x2,因此

本例中,
,这是由于x1的平方项(即x1x1)系数为1/2,所以第1行第1列的元素为1=2*(1/2),x2的平方项(即x2x2)系数为1,所以第2行第2列的元素为2=2*1,x1x2项(即x2x1)的系数为-1,所以第1行第2列和第2行第1列的元素均为-1。
总结:设矩阵H第i行第j列的元素大小为H(i,j),二次项xixj的系数为a(i,j);
注意就是x1x1,x2x2系数要乘以2

笔者总结 :
线性:
linprog 解决的是多元线性函数有约束条件下的的最大最小值问题
非线性:
除此之外共同点都是需要去定义目标函数且都是一次函数
fminunc 解决的是非线性多元无约束条件下的最大最小值问题
对比:fminbnd 解决得是非线性单元变量在给定得范围内得最大最小值
fmincon 解决的是非线性多元有约束条件下的最大最小值问题
二次规划:
quadprog 解决的是非线性且目标函数是二次,约束条件又是线性条件下的最大最小值问题
边栏推荐
- FIR filter design (1) -- using the FDATool toolbox of MATLAB to design FIR filter parameters
- Sequence list and linked list
- day04_ array
- Hongke shares | why EtherCAT is the best solution to improve the performance of the control system?
- 会话推荐中的价格偏好和兴趣偏好共同建模-论文泛读
- 解决文件大导致磁盘满的问题
- 20个hacker神器
- 一文看懂网络安全五年之巨变
- 失效的访问控制
- Several misunderstandings about DDoS
猜你喜欢

软件包设置成——>YUM源

成长为架构师途中的一些思考

Hongke shares | why EtherCAT is the best solution to improve the performance of the control system?

Circular linked list and bidirectional linked list

Hongke share | bring you a comprehensive understanding of "can bus error" (II) -- can error types

day02_基本语法

Arrays & object & System & Math & random & Packaging

MQTT服务器搭建以及使用MQTT.fx测试

day03_1_流程控制

Complex floating point division of vivado IP core floating point
随机推荐
6、 Network interconnection and Internet
After the EtherCAT master station is disconnected, how to ensure that the target system is not affected by the fault?
AbstractQueuedSynchronizer(AQS) 之共享锁源码浅读
day03_1_流程控制
NLP-分词
Hongke automation SoftPLC | Hongke kPa modk operation environment and construction steps (2) -- modk operation environment construction
Ultra low cost DDoS attacks are coming. See how WAF protects Jedi
Raw advanced socket experiment
Introduction to OSPF theory
解决分频模块modelsim下仿真输出为stx的错误
Multithreaded server programming
网络工具中的“瑞士军刀”-nc
Hongke automation SoftPLC | modk operation environment and construction steps (1) -- Introduction to operation environment
非常实用的 Shell 和 shellcheck
Embedding理解+代码
day17_ Under collection
Hongke share | let you have a comprehensive understanding of "can bus errors" (IV) -- producing and recording can errors in practice
Hongke share | bring you a comprehensive understanding of "can bus error" (I) -- can bus error and error frame
5G控制面协议之N2接口
Solve the error that the simulation output is STX under the frequency division module Modelsim





