I am encountering an error that says "Error using fmincon (line 289) Row dimension of A is inconsistent with length of b. Error in HW7 (line 64) [Solution C] = fmincon(@o​bj,x0,A,B,​Aeq,Beq,lb​,ub); "

9 views (last 30 days)
clear
clc
FTR1 = 0; FTR2=0; FTR3=0; FTR4=0; FTR5=0;FTR6=0;
Bij = [0 33.33 0 33.33 153.8 0 0 0;
0 0 100 0 0 0 0 0;
0 0 0 33.33 0 0 0 0;
0 0 0 0 33.33 0 0 0;
0 0 0 0 0 50 0 0;
40 0 0 0 0 0 0 0;
0 0 0 80 0 0 0 45.45;
0 0 55.55 0 0 0 0 0];
PF = 0;
P = [0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0];
delta = [0; 0; 0; 0; 0; 0; 0; 0];
x0=[50 50 50 50 50 50 0 0 0 0 0 0 0 0];
for i = 1:1:8
for j = 1:1:8
PF = Bij(i,j);
P(i,j) = PF;
end
end
A = [P(1,1) P(1,2) P(1,3) P(1,4) P(1,5) P(1,6) P(1,7) P(1,8) FTR1 FTR2 FTR3 FTR4 FTR5 FTR6;
P(2,1) P(2,2) P(2,3) P(2,4) P(2,5) P(2,6) P(2,7) P(2,8) FTR1 FTR2 FTR3 FTR4 FTR5 FTR6;
P(3,1) P(3,2) P(3,3) P(3,4) P(3,5) P(3,6) P(3,7) P(3,8) FTR1 FTR2 FTR3 FTR4 FTR5 FTR6;
P(4,1) P(4,2) P(4,3) P(4,4) P(4,5) P(4,6) P(4,7) P(4,8) FTR1 FTR2 FTR3 FTR4 FTR5 FTR6;
P(5,1) P(5,2) P(5,3) P(5,4) P(5,5) P(5,6) P(5,7) P(5,8) FTR1 FTR2 FTR3 FTR4 FTR5 FTR6;
P(6,1) P(6,2) P(6,3) P(6,4) P(6,5) P(6,6) P(6,7) P(6,8) FTR1 FTR2 FTR3 FTR4 FTR5 FTR6;
P(7,1) P(7,2) P(7,3) P(7,4) P(7,5) P(7,6) P(7,7) P(7,8) FTR1 FTR2 FTR3 FTR4 FTR5 FTR6;
P(8,1) P(8,2) P(8,3) P(8,4) P(8,5) P(8,6) P(8,7) P(8,8) FTR1 FTR2 FTR3 FTR4 FTR5 FTR6];
B=[0 150 0 140 380 0 0 0 300 300 300 300 300 300;
0 0 120 0 0 0 0 0 300 300 300 300 300 300;
0 0 0 230 0 0 0 0 300 300 300 300 300 300;
0 0 0 0 150 0 0 0 300 300 300 300 300 300;
0 0 0 0 0 300 0 0 300 300 300 300 300 300;
250 0 0 0 0 0 0 0 300 300 300 300 300 300;
0 0 0 350 0 0 0 340 300 300 300 300 300 300;
0 0 240 0 0 0 0 0 300 300 300 300 300 300];
Aeq=[0 0 -1 -1 0 0 0 0 0 0 0 0 0 0;
0 0 1 0.4 0 0 0 0 0 0 0 0 0 0;
0 0 0 0 -1 0.6 0 0 0 0 0 0 0 0;
0.5 1 0 0 0 -1 0 0 0 0 0 0 0 0;
-1 -1 0 0 0 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0 0 0 0 0;
0 0 0 0 1 0 0 0 0 0 0 0 0 0;
0.5 0 0 0 0 1 0 0 0 0 0 0 0 0];
Beq=Bij*delta - [0;0;0;100;-100;-80;80;0];
ub = [ 300 300 300 300 300 300 30 30 30 30 30 30 30 30];
lb = [ -300 -300 -300 -300 -300 -300 -30 -30 -30 -30 -30 -30 -30 -30];
[Solution C] = fmincon(@obj,x0,A,B,Aeq,Beq,lb,ub);
FTR = Solution(1:6)
Delta = SOlution(7:14)
C

Answers (1)

Walter Roberson
Walter Roberson on 2 Nov 2015
Read the documentation:
Linear inequality constraints, specified as a real vector. b is an M-element vector related to the A matrix. If you pass b as a row vector, solvers internally convert b to the column vector b(:).
Your 8 x 14 matrix for B is being converted to an (8*14) x 1 column vector, and that does not have the same number of rows as A (which has 8 rows, not 112)
The inequalities constraints is used in the form
A*x <= b
for x being a column vector and b a column vector and A effectively padded to have the same number of columns as the number of rows in x
  2 Comments
Sriram Paravastu
Sriram Paravastu on 2 Nov 2015
What would you suggest I do?
The way I fed the values they seem to have the same number of rows and columns for both A and B.
Walter Roberson
Walter Roberson on 2 Nov 2015
What do you intend it to mean to have an array of b values?
For example with an 8th row in A of
P(8,1) P(8,2) P(8,3) P(8,4) P(8,5) P(8,6) P(8,7) P(8,8) FTR1 FTR2 FTR3 FTR4 FTR5 FTR6
and an 8th row in B of
0 0 240 0 0 0 0 0 300 300 300 300 300 300
is that intended to convey the conjunction of conditions
P(8,1)<=0 & P(8,2)<=0 & P(8,3)<=240 & P(8,4)<=0 & P(8,5)=0 & P(8,6)<=0 & P(8,7)<=0 & P(8,8)<=0 & FTR1<=300 & FTR2<=300 & FTR3 <=300 & FTR4<=300 & FTR5<=300 & FTR6<=300
If so then what you have is not a linear inequality matrix: it is instead a set of upper bounds, which would be specified by the ub parameter, if only the P entries were part of the x vector.
Is the intent
P(8,1)*x(1)<=0 & P(8,2)*x(2)<=0 & P(8,3)*x(3)<=240 & P(8,4)*x(4)<=0 & P(8,5)*x(5)=0 & P(8,6)*x(6)<=0 & P(8,7)*x(7)<=0 & P(8,8)*x(8)<=0 & FTR1*x(9)<=300 & FTR2*x(10)<=300 & FTR3*x(11)<=300 & FTR4*x(12)<=300 & FTR5*x(13)<=300 & FTR6*x(14)<=300
if so then Yes, those can be done as linear inequalities, but you need to code them differently.
A = [zeros(8,0), P(:,1), zeros(8,13);
zeros(8,1), P(:,2), zeros(8,12);
zeros(8,2), P(:,3), zeros(8,11);
...
zeros(8,7), P(:,8), zeros(8,6);
zeros(8,8), FTR1, zeros(8,5);
zeros(8,9), FTR2, zeros(8,4);
zeros(8,10), FTR3, zeros(8,3);
...
zeros(8,13), FTR6, zeros(8,0)];
tB = [0 150 0 140 380 0 0 0;
0 0 120 0 0 0 0 0;
0 0 0 230 0 0 0 0;
0 0 0 0 150 0 0 0;
0 0 0 0 0 300 0 0;
250 0 0 0 0 0 0 0;
0 0 0 350 0 0 0 340;
0 0 240 0 0 0 0 0];
B = [tB(:); [300 300 300 300 300 300].'];

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!