MATLAB Answers


Linprog to maximise a function

Asked by Ella
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?


where qn subject to these constraints 1) every DQMin<q<DQMax 2) ADMin<sum (q1,q2,...qn)<ADMax








[x,fval,exitflag,output,lambda] = linprog(f,A,b,[],[],lb,ub);


Log in to comment.

1 Answer

Answer by 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


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.

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

Log in to comment.

Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!