Info

This question is closed. Reopen it to edit or answer.

defining a constraint in fmincon

1 view (last 30 days)
sensation
sensation on 16 Jul 2018
Closed: MATLAB Answer Bot on 20 Aug 2021
Hi guys, I want to define linear constraints of the form: A*x <= b of my S to be like: minS <= S(t) <= maxS
% My storage function is this one:
function S=storage(init_s,inFlow,x,N)
T=totalflow(x,N);
S(1) = init_s(1) + inFlow(1)-T(1);
for ii = 2:N
S(ii) = S(ii-1) + inFlow(ii)-T(ii);
end
Tried solution see below pls, but I get S after some time steps higher than my maxS. Any clue why?
%I have tried this one but Smax is exceeded almost all the time.
c1(:,i) = init_s(:,i) + cumsum(inFlow(:,i));
b2(1:N,i) = maxS(i)-c1(1:N,i); %upper storage limit
b3(1:N,i) = -minS(i)+c1(1:N,i); %lower storage limit
b = [b;b2;b3]; %addition to previous constraint
s = -1*sparse(tril(ones(N)));
s = [s s];
A = [A;s; -s];
Any idea or tip? Thanks a lot!

Answers (0)

Community Treasure Hunt

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

Start Hunting!