简体   繁体   English

我在MATLAB代码中有一个错误,但找不到

[英]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.

相关问题 我的代码中有一个错误,我不知道在哪里!!! [MATLAB] - There is a bug in my code and I don't know where!!! [MATLAB] Matlab找不到C / C ++编译器,尽管我已经安装了它 - Matlab cannot find the C/C++ compiler although I have it installed 我在将 MATLAB 代码转换为 Python 时遇到问题 - I have problem with converting MATLAB code to Python 如何将“查找”代码从 MATLAB 转换为 R? - How can I translate "find" code from MATLAB to R? 我有用于游程编码的matlab代码,我想制作用于解码的代码 - I have matlab code for run length encoding and I want to make code for decoding 鉴于我在 MATLAB 中有输入图像和结果,我能否找到卷积核? - Can I find the kernel for convolution given that I have the input image and the result in MATLAB? 我不懂MATLAB语法 - i cannot understand MATLAB syntax 如何在 matlab 中的矩阵中找到等于向量的行? 在,特别是我想要索引 - How can I find a row equal to a vector in a matrix in matlab ? In, particular I would like to have the indexes 我无法编译matlab生成的代码,它给了我一个链接器错误,我必须遵循的正确步骤是什么? - i cant compile matlab generated code, it gives me a linker error what is the correct step i have to follow? 将Matlab代码转换为python的错误 - Bug in converting matlab code to python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM