Linprog to maximise a function
1 view (last 30 days)
Show older comments
I have a function as following and try to maximise the value of V. Logic: if sn coefficient is positively largest, take max qn. if sn coefficient is negative, take min qn. if sn coefficient is between positively largest and zero, qn varies proportionally.
My code below is working but the outputs of x are equal to either DQMax or DQMi, no value is between them. How can I modify the code to derive q will vary proportionally?
V(q)=s1*q1+s2*q2+....sn*qn
where qn subject to these constraints 1) every DQMin<q<DQMax 2) ADMin<sum (q1,q2,...qn)<ADMax
f=-s(1:365);
a1=ones(1,365);
a2=-ones(1,365);
A=[a1;a2];
b=[AQMax;-AQMin];
lb=DQMin.*ones(365,1);
ub=DQMax.*ones(365,1);
[x,fval,exitflag,output,lambda] = linprog(f,A,b,[],[],lb,ub);
0 Comments
Answers (1)
Alan Weiss
on 23 Jan 2013
I'm sorry, I do not understand why you are dissatisfied with the result. If the result satisfies all the constraints, then what else do you want? The only case where the outputs would not be equal to the bounds is when the linear inequality constraints are active, so I suppose your linear constraints are far enough apart that they do not matter.
You can test what I mean by setting ADMin and ADMax very close to each other.
Alan Weiss
MATLAB mathematical toolbox documentation
2 Comments
Alan Weiss
on 15 Feb 2013
I still do not understand why you are dissatisfied with the result that linprog gives you when DQMax and DQMin are set to their normal values. What makes you think that the answer is erroneous?
One other thing. linprog tries to minimize the objective function. If you want to maximize, enter -f as the objective function vector, and take the negative of the resulting objective. See the documentation.
Alan Weiss
MATLAB mathematical toolbox documentation
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!