## Linprog to maximise a function

### Ella (view profile)

on 22 Jan 2013

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);

## Products

### Alan Weiss (view profile)

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

Ella

### Ella (view profile)

on 15 Feb 2013

Hi Alan,

I did test on setting DQMax and DQMin close to each other . The matlab gives warining message as follows:

Exiting: One or more of the residuals, duality gap, or total relative error has grown 100000 times greater than its minimum value so far: the primal appears to be infeasible (and the dual unbounded). (The dual residual < TolFun=1.00e-08.)_

Any possible way I can tackle it. I have tried optimet to increae the tolerable error, but still fail to sovle. Appreciate your advice.

Alan Weiss

### Alan Weiss (view profile)

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