linear optimization with changing constraints(Solved)

Hey everyone, I have a problem with the inequality constraints.
in my problem, the b is changing accoring to the previous b's value, so I wrote a for structure but no idea if it's the right way.
here is my code:
price=randi([-10,50],24,1);
x=ones(24,1);
k=0.2;
T=[15 25];
A=k*ones(24);
C=20*ones(24,1);
A=[A;-A];
for i=1:24
C(i+1)=C(i)+k*x(i);
B(i)=T(2)-C(i);
D(i)=C(i)-T(1);
end
c=D.';
b=B.';
b=[b;c];
lb=0*ones(24,1);
ub=20*ones(24,1);
x=linprog(-price,A,b,[],[],lb,ub);
everytime I run it, my x array is full of 0 with only one random value '2'
would you kindly tell me what's going wrong? does the inequality constraints function properly? many thanks!
Thank you very much for your help! the problem is solved now

답변 (1개)

Madhav Thakker
Madhav Thakker 2020년 8월 18일

0 개 추천

Hi
As per your code, the equality constraints are working fine with different[MT1] values of ub, b, price. To get a deeper understanding, refer this documentation of linprog . So basically, the code is minimizing price'*x such that A.x <= b and lb <= x <= ub. The 'random' value 2 is always associated with the index where priceis largest because we are trying to minimize price'*x and the argument passed in linprog is -price.
Another thing you can do to verify the correctness of the function, is by trying to set ub = 1.2 or by increasing b. You'll see non-zero values in index corresponding to next price value.
Hope this helps.

댓글 수: 1

thank you very much I've solved it, I think that problem in a wrong way, lol

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

카테고리

제품

질문:

2020년 8월 12일

편집:

2020년 8월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by