Matlab 求解线性规划问题 初步

简介

RT

code

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));
x,y=-y

解释

就是把所有的 最值问题 用 f 表示
a,b 表示 a x <= b 用矩阵表示
aeq * [x1,x2,x3]^T = beq,表示等式问题
zeros(3,1) 表示 所有的x的值大于0

结果

aeq =
1 1 1
Optimization terminated.
x =
6.4286
0.5714
0.0000
y =
14.5714

Tips

至于为啥y=-y我就不知道了,好奇怪??

Ex1. 求解下列线性规划问题

min z = 2x1 + 3x2 + x3

[ ext {s.t.}left{egin{array}{c} x_{1}+4 x_{2}+2 x_{3} geq 8 \ 3 x_{1}+2 x_{2} geq 6 \ x_{1}, x_{2}, x_{3} geq 0 end{array} ight.]

code

c=[2;3;1];
a=[1,4,2;3,2,0];
b=[8,6];
[x,y]=linprog(c, -a, -b, [], [], zeros(3,1))

answer

Optimization terminated.
x =
0.8066
1.7900
0.0166
y =
7.0000

TIPS

1.如果是小于等于 那就是对应的矩阵值,否则里面要加上符号,比如 [x,y]=linprog(c, -a, -b, [], [], zeros(3,1))
2.关于带绝对值的线性规划问题直接用lingo解即可。

Hope is a good thing,maybe the best of things,and no good thing ever dies.----------- Andy Dufresne
原文地址:https://www.cnblogs.com/eat-too-much/p/13269294.html