Writing equations in a matrix form

조회 수: 5 (최근 30일)
Susan
Susan 2019년 4월 19일
댓글: Susan 2019년 4월 24일
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.
Susan
Susan 2019년 4월 24일
Thanks for your reply.

댓글을 달려면 로그인하십시오.

추가 답변 (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