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

1 view (last 30 days)
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 Comments
Nikolas Spiliopoulos
Nikolas Spiliopoulos on 23 Feb 2018
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
Nikolas Spiliopoulos
Nikolas Spiliopoulos on 23 Feb 2018
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);

Sign in to comment.

Answers (1)

Jan
Jan on 23 Feb 2018
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 Comments
Jan
Jan on 23 Feb 2018
Edited: Jan on 23 Feb 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.

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!