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

조회 수: 2 (최근 30일)
Nikolas Spiliopoulos
Nikolas Spiliopoulos 2018년 2월 23일
댓글: Nikolas Spiliopoulos 2018년 2월 26일
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
Nikolas Spiliopoulos
Nikolas Spiliopoulos 2018년 2월 23일
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 2018년 2월 23일
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);

댓글을 달려면 로그인하십시오.

답변 (1개)

Jan
Jan 2018년 2월 23일
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
Jan
Jan 2018년 2월 23일
편집: Jan 2018년 2월 23일
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.
Nikolas Spiliopoulos
Nikolas Spiliopoulos 2018년 2월 26일
ok I"ll give it a try
thanks anyway!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by