Identify the coefficients of each constraint separately
4 views (last 30 days)
Show older comments
I have 4 restrictions below. I would like to make an array of coefficients for each constraint separately. I did the first two, I would like to know if it is correct, first, and I would like help to do the remaining two. My ideia is used the linprog function later.

A = [Xk(1) Xk(2) Xk(3) Xk(4) zeros(1,ncolunas)
B= [0 0 0 0 Xk(1) Xk(2) Xk(3) Xk(4)]
1 Comment
Walter Roberson
on 21 Apr 2023
I suggest that you use Problem Based Optimization https://www.mathworks.com/help/optim/problem-based-approach.html
Answers (1)
Walter Roberson
on 22 Apr 2023
You want to operate over rows of Y and over colums of Y.
What you do is reshape() Y to be a row vector, and start creating row entries that correspond. For example, if Y is 3 x 5, then one row of coefficients would be like [zeros(1,0), ones(1,3), zeros(1,12)] and another would be [zeros(1,3), ones(1,3), zeros(1,9)], another would be [zeros(1,6), ones(1,3), zeros(1,6)] and so on. You are creating matrices of selectors of which coefficients are to be used in a particular summation.
Once you have the 2D array of selectors, do element-by-element multiplication against reshape(Y,1,[]) -- so each selector 1 in the temporary variable is replaced by the corresponding Yik value. The result becomes your "A" matrix. The b matrix becomes [P(:); L(:)] (at least with respect to the first two variables.)
I need to think a bit more about how to handle the third condition smoothly.
2 Comments
Walter Roberson
on 24 Apr 2023
I recommend that you use Problem Based Optimization to construct the constraint matrices. It should also be able to figure out that linprog() can be used as the solver.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!