Writing equations in a matrix form

10 次查看(过去 30 天)
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 个评论
Walter Roberson
Walter Roberson 2019-4-19
编辑:Walter Roberson 2019-4-19
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 2019-4-19
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.

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2019-4-19
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 个评论
Walter Roberson
Walter Roberson 2019-4-23
Yes, 'vars', {c} should work for that.

请先登录,再进行评论。

更多回答(1 个)

Susan
Susan 2019-4-22
@ 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 个评论
Walter Roberson
Walter Roberson 2019-4-22
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 2019-4-22
Great! Thanks for all your help. Appreciate that.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Surrogate Optimization 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by