Hello;
I am trying to make a simple linear programming optimization. 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, 700];
linprog(f, A, b, Aeq, beq, lb, hb);
When I try to run it, it says that The number of rows in A must be the same as the number of elements of b.
A has 7 rows and b has 7 elements, as it can be seen. I cannot see the mistake. Where is it?

 Respuesta aceptada

Alan Weiss
Alan Weiss el 10 de Mzo. de 2014

0 votos

I believe that your Aeq matrix should be a row vector, not a column vector.
Is your A matrix a vector or a matrix? I mean, don't you need some semicolons to separate the rows?
Alan Weiss
MATLAB mathematical toolbox documentation

1 comentario

Bogdan
Bogdan el 10 de Mzo. de 2014
Yes, that was the problem. Aeq should have been a row vector. I gotta love Matlab: it shows the error in a line, but the error is in another line :))
A is a matrix and this time I don't need semicolons, because Matlab interprets it as a matrix in the form that is written. In this case, semicolons are not needed.
Thank you for your help.

Iniciar sesión para comentar.

Más respuestas (1)

Dishant Arora
Dishant Arora el 8 de Mzo. de 2014

0 votos

Read the manual properly.
doc linprog
You are missing some input argument while calling.

3 comentarios

Bogdan
Bogdan el 8 de Mzo. de 2014
Yes, I missed one input argument: the objective function. But it still doesn't solve the problem. Neither does writing "x=linprog(...)"
Dishant Arora
Dishant Arora el 8 de Mzo. de 2014
you getting some error??
Bogdan
Bogdan el 10 de Mzo. de 2014
Same error, yes :)

Iniciar sesión para comentar.

Preguntada:

el 8 de Mzo. de 2014

Comentada:

el 10 de Mzo. de 2014

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by