R linprog delivers incorrect solution

Viewed 41

I am solving the following simple linear program with pracma::linprog in R:

library(pracma)

cc=c(1)
A=as.matrix(-1)
b=c(1)

linprog(cc,A,b,maximize=FALSE)

The solution returned is x=0.

However, this solution is incorrect: a lower value of the linear program can clearly be obtained at x=-1.

I find that both Wolfram Alpha and Matlab return the correct solution.

Why does linprog return the wrong solution? Is there any way to correct this problem?

1 Answers

From ?linprog

This is a first version that will be unstable at times. For real linear programming problems use package lpSolve

Which gives the same answer

lpSolve::lp(direction='min', cc,A,"<=",b)
Success: the objective function is 0 

And from ?lp

Note that every variable is assumed to be >= 0!
Related