optimizing linprog 2 variables with different dimensions
3 次查看(过去 30 天)
显示 更早的评论
Hi community,
my function to optimize is min (l-q).'*z-s.'*y in which .' indicates the transpose.
the constraints for this fucntion are y=x-A1.'*z 0<z<d , y>0 z&y are the decision variables
The given data to use in the function is given below. The difficulty that arises is that the variables of Z & Y do not have the same dimensions as z=[Z] and y=[Y1;Y2] when trying to solve this function. An error pops up: Error using linprog (line 222)
The number of rows in Aeq must be the same as the number of elements of beq. This is because x has 2 rows in my case and Aeq only 1. I cannot find a propper definition for Aeq so that my function works.
does anyone have an idea how I can fix this? Or best handle optimizing 2 variables with different dimensions?
Thank you
l = 0.25;
q = 2;
s = 1;
A1 = [1, 1];
x = [20;25];
d = 120;
f= [-s.', l-q.'];
Aeq = [1, A1];
beq = x;
lb = [0, 0];
ub = [Inf, d];
sol = linprog(f,[],[],Aeq,beq,lb,ub);
y = sol(1)
z = sol(2)
0 个评论
采纳的回答
Torsten
2019-4-17
Set
V = [V(1) V(2) V(3)] = [z y(1) y(2)]
as "combined" solution vector and write all your equations in V instead of z and y.
Then you'll easily see how to set f, Aeq, beq, lb and ub.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!