linear optimization with changing constraints(Solved)

1 次查看(过去 30 天)
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
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.

类别

Help CenterFile Exchange 中查找有关 Solver Outputs and Iterative Display 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by