1
votes

I am running on R 3.0. I have a quadratic function like:

2*x[1]*x[1] -5 * x[1] + 8 * x[2] * x[2] - 7*x[3]*x[2] -5 * x[3] * x[3]..

The function has various quadratic terms and has some linear constraints such as:

1 <= x[1] <= 7
-2 <= x[2] <= 9
0 <= x[3] <= 32

Additionally,

 x[1]+ x[2]+ x[3] = 100

Which package in R should I look at to solve this kind of an optimization problem? It is a large equation with many inequalities and I am running R 3.0.Can some thing like:

   x[1]+ x[2]+ x[3] = 100

be done with optim?

I am somehow not able to figure out how to pass parameters to constrOptim or solve.QP in quadprog.

2
Give us a reproductible example and it will be easier to answer with code on how to use solve.QP for exampledickoa

2 Answers

2
votes

Both quadprod::solve.QP or limSolve::lsei will solve QPs with linear constraints. They differ in the way the objective is formulated:

  1. min(-d^T b + 1/2 b^T D b) for solve.QP
  2. min(||Ax-b||^2) for lsei

Looking at the way you wrote your objective function, solve.QP sounds like the best choice, but note that you will have to rewrite your problem in matrix form.

Edit: I had not realized that your objective function was not convex (put differently, the matrix D above is not positive definite) which is a requirement for these solvers. So yes, you should rely on a non-linear solver like optim, but a more general one that allows for added linear constraints: constrOptim seems to be one of them.

-1
votes

Minimize[{2*x1^2 - 5*x1 + 8*x2^2 - 7*x3*x2 - 5*x3^2, 1 <= x1 <= 7 && -2 <= x2 <= 9 && 0 <= x3 <= 32}, {x1, x2, x3}] Optimal value:-51929/8 Optimal vector:(x1 -> 5/4, x2 -> 9, x3 -> 32) Then, Convex Quadratic Programming Problem is sloved by improved Simplex method.