linear optimization with changing constraints(Solved)
1 view (last 30 days)
Show older comments
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
0 Comments
Answers (1)
Madhav Thakker
on 18 Aug 2020
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.
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!