Why does the [x,fval,exitflag,output,lambda] = linprog(f,A,b,Aeq,beq,lb,ub) function return only integer numbers?
Show older comments
Hi, I'm doing an optimization problem where I use the [x,fval,exitflag,output,lambda] = linprog(f,A,b,Aeq,beq,lb,ub) funtion. However, the results I get give me only integer numbers. For example, I'm expecting a result like 1.710, but I get 2.0. When I expect a value of 0.855, I get 1.0
How can I get the rational numbers with decimals, instead of only integer numbers?
8 Comments
Torsten
on 27 Oct 2022
Does your "expected result" give a smaller value for f than the "integer result" linprog returns ?
Romeo Tahal
on 27 Oct 2022
Steven Lord
on 27 Oct 2022
Does your non-integer solution satisfy the constraints represented by the A, b, Aeq, and beq matrices?
Does it satisfy the bounds represented by the lb and ub vectors?
If the answer to either of those questions is no, then your non-integer "solution" is not a solution.
Torsten
on 27 Oct 2022
My f was defined as [10 12]'. The result of the linprog returns the 10 perfectly, which is the LMP at bus 1. For LMP at bus 2 I should get 12, but instead the linprog returns a value higher than 12.
You should not get f as solution from linprog, but an x that minimizes f'*x under your constraints.
So again the question: is [10 12]*result_linprog or [10 12]*(your result) smaller ?
Does your result satisfy the constraints ?
Does it satisfy the bounds ?
Romeo Tahal
on 27 Oct 2022
Torsten
on 27 Oct 2022
And what about the third question:
is [10 12]*result_linprog or [10 12]*(your result) smaller ?
Romeo Tahal
on 28 Oct 2022
Torsten
on 28 Oct 2022
If you know a solution you can live with, you don't need an optimizer, do you ?
Answers (1)
Sarthak
on 11 Sep 2023
Hi Romeo,
I understand that you want to set the precision of the output variable.
You can use the format function to set the precision of the output.
format long
x,fval,exitflag,output,lambda = linprog(f,A,b,Aeq,beq,lb,ub);
To know more information about the “format” function, you can visit the documentation page of format.
I hope this solves your query.
Categories
Find more on Linear Programming and Mixed-Integer Linear Programming in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!