Identify the coefficients of each constraint separately

4 Ansichten (letzte 30 Tage)
JOVANI
JOVANI am 21 Apr. 2023
Kommentiert: Walter Roberson am 24 Apr. 2023
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)]

Antworten (1)

Walter Roberson
Walter Roberson am 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 Kommentare
JOVANI
JOVANI am 24 Apr. 2023
Thanks for the reply! Walter, a few days ago I posted a complete question that involves the same constraints I put in this question. I posted it here: https://math.stackexchange.com/questions/4672610/using-linprog-function-for-a-linear-program. Based on this question, do you think the same reasoning as your answer applies?
Walter Roberson
Walter Roberson am 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.

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by