QCQP error of fmincon: Row dimension of A is inconsistent with length of b.
3 views (last 30 days)
Show older comments
I have the following problem and I need to minimize the cost C with these constraints:
% Minimize C(dp)
% Decision variable = dp
% subject to:
% R(dp) >= C(dp)
% w >= 0
% pmin*l <= (po*l + dp) <= pmax*l % not needed
% l*dp <= 0 % not needed
I got the following error:
Error using fmincon (line 307)
Row dimension of A is inconsistent with length of b.
Please, help!
% po is constant price dollars per cubic feet $/CF
po = 3;
% is a vector of price for each hour
p = zeros(1,24);
% dp is a vector of price change from the default price po
dp = zeros(1,24); % Decision variable
% l is vector with all components one
l = ones(1,24);
% J is the price elasticity matrix (PEM)
J = zeros(24);
J = [-6 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3;
3 -6 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3;
3 3 -6 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3;
3 3 3 -6 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3;
3 3 3 3 -6 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3;
3 3 3 3 3 -6 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3;
3 3 3 3 3 3 -6 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3;
3 3 3 3 3 3 3 -6 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3;
3 3 3 3 3 3 3 3 -6 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3;
3 3 3 3 3 3 3 3 3 -6 3 3 3 3 3 3 3 3 3 3 3 3 3 3;
3 3 3 3 3 3 3 3 3 3 -6 3 3 3 3 3 3 3 3 3 3 3 3 3;
3 3 3 3 3 3 3 3 3 3 3 -6 3 3 3 3 3 3 3 3 3 3 3 3;
3 3 3 3 3 3 3 3 3 3 3 3 -6 3 3 3 3 3 3 3 3 3 3 3;
3 3 3 3 3 3 3 3 3 3 3 3 3 -6 3 3 3 3 3 3 3 3 3 3;
3 3 3 3 3 3 3 3 3 3 3 3 3 3 -6 3 3 3 3 3 3 3 3 3;
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 -6 3 3 3 3 3 3 3 3;
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 -6 3 3 3 3 3 3 3;
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 -6 3 3 3 3 3 3;
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 -6 3 3 3 3 3;
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 -6 3 3 3 3;
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 -6 3 3 3;
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 -6 3 3;
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 -6 3;
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 -6];
% f is a vector of the day-ahead demand forecast (for now, actual demand will be used)
% f = zeros(1,24);
% use D (actual demand) as f, for testing
D = [235.20 126.32 73.16 242.16 257.36 553.27 436.89 652.46 457.64 300.99 312.12 340.37 251.22 259.53 187.42 252.68 340.34 424.82 279.40 330.57 362.92 484.82 229.90 231.88];
f = D;
% Definde p & w
p = po .* l + dp;
% w is the water use profile
w = f + J .* dp;
%% Utility parameters
% Cost coefficients
b = 1000;
c = zeros(1,24);
c = 2.2*l;
d = 1;
wt = 140;
pmin = 1;
pmax = 5;
o = zeros(1,24);
% Revenue R
% Cost C
R = p.' .* w;
C = b + c.' .* w + d .* max(w - w.'.*l, o).' * max(w - w.'.*l, o); % Objective function
%% Optimization
% Minimize C(dp)
% Decision variable = dp
% subject to:
% R(dp) >= C(dp)
% w >= 0
% pmin*l <= (po*l + dp) <= pmax*l % not needed
% l*dp <= 0 % not needed
A = C;
b = R;
dp0 = ones(1,24);
func = @C;
fmincon(func,dp0,A,b)
0 Comments
Answers (1)
Guru Mohanty
on 13 May 2020
Hi, I Understand you are trying to minimize C with the discission variable dp. To use fmincon function ie min(f) the condition is
" A*dp => b". In your case 'A' is a 24x24 matrix and 'dp' 1x24 matrix. 'B' should be a 24x1 matrix, but in your scenario, it is a 24x24 matrix. This leads to Dimension Inconsistency Error. After changing dimension the code should work.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!