optimizing linprog 2 variables with different dimensions

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)

 Akzeptierte Antwort

Torsten
Torsten am 17 Apr. 2019

0 Stimmen

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.

6 Kommentare

this is indeed a smart way to solve it. However when using a solution vector of V(1) V(2) V(3)
the matrix dimensions of Aeq and Beq do not match anymore. From my point of view Aeq should now be Aeq=[1 1 0;0 0 A1.'] and beq= x
Error using vertcat
Dimensions of matrices being concatenated are not consistent.
also error occurs in V = [V(1) V(2) V(3)] = [y(1) y(2) z]
The expression to the left of the equals sign is not a valid target for an assignment.
I do not understand what Matlab means with this, As I would think this is correct
As now also A1 became [1;1] instead of just 1. filling this in in the Aeq matrix causes another error. Any idea how I could fix this?
Torsten
Torsten am 18 Apr. 2019
Bearbeitet: Torsten am 18 Apr. 2019
l = 0.25;
q = 2;
s = [1;1];
A1 = [1,1];
x = [20; 25];
d = 120;
f = [-s.',(l-q).'];
Aeq = [eye(2), A1.'];
beq = x;
lb = [0, 0, 0];
ub = [Inf, Inf, d];
sol = linprog(f,[],[],Aeq,beq,lb,ub);
y = [sol(1);sol(2)]
z = sol(3)
What I meant is to write out your equations in V instead of y and z:
(l-q).'*z-s.'*y
becomes
(l-q)*V(3)-s(1)*V(1)-s(2)*V(2),
thus
f = [-s(1); -s(2); (l-q)]
y=x-A1.'*z
becomes
V(1) + A1(1)*V(3) = x(1)
V(2) + A1(2)*V(3) = x(2),
thus
[1 0 A1(1);0 1 A1(2)]*V = x
thus
Aeq = [1 0 A1(1);0 1 A1(2)]
beq = x
thankyou! this is really helpfull
Hi torsten, As I am now scaling up the problem with having two values for Z and 4 values of Y the dimensional problem becomes more difficult once again. As eye(2),eye(3)... does not work any more for adding values of Y. new Matrix A1[1 1 0 0;0 0 1 1] makes determining Aeq for me rather difficult as the transpose of A1 makes it difficult to calculate.
I tried writing the whole equation out in terms of V as you did above. But, where I am stuck is that Z(1) --> V(5) needs to be multiplied with 2 variables of A1 instead of only one variable as in the previous problem.
l =[0.25; 0.3];
q =[6;5];
s = [1;1.2;1.1;1];
A1 = [1 1 0 0; 0 0 1 1];
x =[20; 25; 28; 26];
d =[120;110];
f =[-s.',(l-q).'];
Aeq =[1 1 0 0;0 0 1 1, A1.'];
beq =x;
lb =[0, 0, 0, 0, 0, 0];
ub =[inf, inf, inf, inf, d(1), d(2)];
sol = linprog(f,[],[],Aeq,beq,lb,ub);
y = [sol(1);sol(2);sol(3);sol(4)]
z= [sol(5); sol(6)]
Hope you can help me out!
think I might have found it already with Aeq=[eye(4),A1.']

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Gefragt:

am 17 Apr. 2019

Kommentiert:

am 19 Apr. 2019

Community Treasure Hunt

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

Start Hunting!

Translated by