Writing equations in a matrix form

5 visualizzazioni (ultimi 30 giorni)
Susan
Susan il 19 Apr 2019
Commentato: Susan il 24 Apr 2019
Hi MATLAB experts,
Could any one please help me to write-down the following equations into a matrix form? the initial value of c = zeros(I, L, K, M)
0<= c(i, j, k, m) <= 1 for all k= {1, 2, ...., K} and m = {1, 2, ..., M} and i = {1,...., I} and j = {1,..., L}
0<=sum_{j} sum_{i} c(i,j,k,m) <= 1 for all k= {1, 2, ...., K} and m = {1, 2, ..., M}
  4 Commenti
Walter Roberson
Walter Roberson il 19 Apr 2019
Modificato: Walter Roberson il 19 Apr 2019
Yes, those should be okay lb and ub.
Which release are you using? Which optimizer are you using?
Your task might be easier to express with Problem Based Optimization.
Do not use nonlinear constraints for those sum constraints: you only need linear constraints for those. It is just a nuisance to write out the matrices.
Susan
Susan il 19 Apr 2019
Thanks for your reply.
I am using R2016b and trying to use fmincom.
I am not familiar with Problem Based Optimization. But I will take a look to see how I can use that.
Do you know how I should write the second constraint? Thanks
sum(sum(c(:, :, k,m))) <= 1 for all k and m.

Accedi per commentare.

Risposta accettata

Walter Roberson
Walter Roberson il 19 Apr 2019
For any one particular scalar k and scalar m, you can express sum_{j} sum_{i} c(i,j,k,m) in range 0 to 1 as a linear constraint. The portion relevant to that k and m would be in the A matrix like
A(something,:) = [zeros(1, SOMETHING), ones(1, I*J), zeros(1,SOMETHINGELSE)];
b(something) = 1;
A(something+1,:) = [zeros(1, SOMETHING), -ones(1,I*J), zeros(1,SOMETHINGELSE)];
b(something) = 0;
You would have to walk this through K by M iterations, increasing the value of SOMETHING by I*J each time, and decreasing the value of SOMETHINGELSE by the same value.
An easier way of generating this would be something like:
blk = repmat({[ones(1, I*J); -ones(1, I*J)]}, 1, K*M);
A = blkdiag(blk{:});
b = zeros(size(A,1));
b(1:2:end) = 1;
  21 Commenti
Walter Roberson
Walter Roberson il 23 Apr 2019
Yes, 'vars', {c} should work for that.
Susan
Susan il 24 Apr 2019
Thanks for your reply.

Accedi per commentare.

Più risposte (1)

Susan
Susan il 22 Apr 2019
@ Walter, I am trying to write-down the following linear constraint according to the way you taught me above.
sum_{m} sum_{i} p(i, j,j,k,m) <=P_{k, j} for all k = 1: K and j = 1 : J
m = 1: M and i = 1 : I and P_{k, j} is given and fixed for each specific k and j
I wrote this constraint in the format of
A(something,:) = [zeros(1, SOMETHING), ones(1, I), zeros(1,SOMETHINGELSE)];
b(something) = P_{k,j};
However, I wasn't able to find a specific relationship between the rows of A.
What I found is sth like
A(1, :) = [ones(1, I) zeros(1, (J*J*K -1)*I) ones(1, I) zeros(1, (J*J*K -1)*I) ]
A(2, :) = [zeros(1,K) ones(1, I) zeros(1,(J*J*K -1)*I) ones(1, I) zeros(1,(J*J*K -1)*I) zeros(1,(J*J*K -1)*I -K)]
the pattern "ones(1, I) zeros(1, (J*J*K -1)*I) ones(1, I) zeros(1, (J*J*K -1)*I) " is repeated in all rows but I wasn't able to figure out what is the formulation of the begining zeros(1, SOMETHING), and correspondingly the zeros(1,SOMETHINGELSE) in order to write matrix A.
Could you please let me know what would be the format of A? Thank you so much in advance.
  2 Commenti
Walter Roberson
Walter Roberson il 22 Apr 2019
Use the blkdiag() method I posted as "easier way of generating this". It generates the entire A and b matrix in a small number of lines.
Susan
Susan il 22 Apr 2019
Great! Thanks for all your help. Appreciate that.

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by