LP error the number of rows of A must be the same with b

Hi again,
I am trying to run and LP optimization.
However, I am getting the following error
"The number of rows in A must be the same as the number of elements of b."
The problem is that the size of my matrices are: A [8X8] and b[8x1], so I don't really get where the error is
can you help?
thanks
Nikolas

4 commentaires

MATLAB doesnt't seem to agree that A[8x8] and b[8x1].
So we will have to see your code in order to clarify things.
Jan
Jan le 23 Fév 2018
No. Without knowing any details and seeing the code, it is impossible to help.
Please edit the question and insert the required details. We need the relevant part of the code and a copy of the complete error message.
if
clc;
clear;
close all;
N=2;
%equality constraint => x1+x2+y1+y2=[100; 50;70; 40;60] %x1=SoC1, x2=SoC2,
%y1=I1, y2=I2;
Initial_array=[100; 50;70; 40;60];
Soc1=eye(N);
Soc2=eye(N);
I1=eye(N);
I2=eye(N);
M1=[Soc1,2*Soc2,3*I1,I2];
M2=zeros(1,size(M1,2));
M2(1)=1;
M3=zeros(1,size(M1,2));
M3(N+1)=1;
M4=zeros(1,size(M1,2));
M4(2*N+1)=1;
M5=zeros(1,size(M1,2));
M5(3*N+1)=1;
Aeq=[M1;M2;M3;M4;M5];
beq=[zeros(N,1);12;15;5;10];
%Inequality constaints: 0<x1,x2<100, 0<y1,y2<45
A=eye(4*N);
b=[100*ones(2*N,1); 45*ones(2*N,1)];
lb=zeros(4*N,1);
%LP -> Objective function -> 3*x1+2*x2-5y1-3y2=0
options = optimoptions('linprog','Algorithm','interior-point');
ee=ones(1,N);
f=[3*ee,-2*ee,-5*ee,-3*ee ];
x=zeros(4*N,1);
x0=x;
[x,fval]=linprog(f,x0,A,b,Aeq,beq,lb,[],options);
end
Error using linprog (line 232) The number of rows in A must be the same as the number of elements of b.
Error in LP_example (line 56) [x,fval]=linprog(f,x0,A,b,Aeq,beq,lb,[],options);

Connectez-vous pour commenter.

Réponses (1)

The calling sequence is (see doc linprog)
[x,fval] = linprog(f,A,b,Aeq,beq,lb,ub,options)
Your code:
[x,fval] = linprog(f,x0,A,b,Aeq,beq,lb,[],options)
What is x0? It seems to be misplaced here and linprog compare the sizes of x0 and A instead of A and b.

3 commentaires

Thanks for the answer,
yeah my mistake it's from a previous non-linear optimization. So I erase x0 and I get the following error:
"LINPROG requires the following inputs to be of data type double: 'X0'."
I'm really confused
Thanks!
Jan
Jan le 23 Fév 2018
Modifié(e) : Jan le 23 Fév 2018
When I run it, I get: "The problem is infeasible. Linprog stopped because no point satisfies the constraints." Which Matlab version are you using?
I'm confused also. In doc linprog I find:
[x,fval,exitflag,output,lambda] = linprog(f,A,b,Aeq,beq,lb,ub,options)
In the source of linprog.m it is:
[x,fval,exitflag,output,lambda] = linprog(f,A,B,Aeq,Beq,lb,ub,x0,options)
^^ ???
So try this (dangerous: PURE GUESSING!)
[x,fval]=linprog(f,x0,A,b,Aeq,beq,lb,[],[],options);
Sorry, I suggest a gunshot programming method.
ok I"ll give it a try
thanks anyway!

Connectez-vous pour commenter.

Catégories

En savoir plus sur Linear Programming and Mixed-Integer Linear Programming dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by