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

1 回表示 (過去 30 日間)
Nikolas Spiliopoulos
Nikolas Spiliopoulos 2018 年 2 月 23 日
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 Center および File ExchangeSolver 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