[英]I have a bug in a MATLAB code and I cannot find it
I am trying to make a simple linear programming optimization, using MATLAB R2012b. 我正在尝试使用MATLAB R2012b进行简单的线性编程优化。 I came up with this code: 我想出了以下代码:
clear;
y=1663;
f=[100; 100; 100; 100; 100; 100; 100; 100];
A=[1/867.2 1/704.7 1/619.2 1/679 1/770.3 1/658.5 1/749 1/783.1
-105.2 -74.4 -94.3 -88.2 -108.9 999 -112.7 -91.4
-94.1 -71.2 -87.6 -87.8 -99.4 999 -100 -81.2
0.5 0.6 4.5 3 28 15 4.5 12.5
0.78 2.11 0.01 0.01 0.56 0.09 0.02 0.9
93.63 16.3 0.01 0.01 1.44 0.09 0.03 37.64
0.82 3.23 0.03 0.36 3.13 29.97 0.04 16.16];
b=[y/0.775; -95*y; -85*y; 10*y; 1*y; 35*y; 18*y];
Aeq=[1; 1; 1; 1; 1; 1; 1; 1];
beq=y;
lb=zeros(8,1);
hb=[550; 250; 50; 200; 50; 350; 400];
linprog(f, A, b, Aeq, beq, lb, hb);
When I try to run this source, it says that The number of rows in A must be the same as the number of elements of b. 当我尝试运行此源代码时,它说A中的行数必须与b中的元素数相同。
A has 7 rows and b has 7 elements, as it can be seen. 可以看出,A有7行,b有7个元素。 I cannot see the mistake. 我看不到错误。 Where is it? 它在哪里?
Thanks. 谢谢。
You have to redefine Aeq. 您必须重新定义Aeq。 Since you have only one equality constraint, it should be 1xn. 由于您只有一个相等约束,因此应该为1xn。 I also included x as an output of linprog. 我也将x作为linprog的输出。
Aeq=[1, 1, 1, 1, 1, 1, 1, 1];
x=linprog(f, A, b, Aeq, beq, lb, hb);
The result is 结果是
x =
200.7466
59.3486
30.1325
62.8837
35.7733
1.6669
341.6570
930.7914
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.