2

I am trying to optimize the following simple objective function using the quadprog program in R:

max_{x} x'Ax

Most optimization problems I see use minimization, but if I simply use -A instead of A, I get an error that A is no longer positive definite. I am very new to this kind of thing. Does anyone know how to solve a simple quadratic maximization problem?

Here is sample code to reproduce the error:

if (!require(quadprog)) install.packages('quadprog')
library(quadprog)
set.seed(144)
mat <- abs(cor(matrix(rnorm(25),5,5)))
solve.QP(Dmat = -mat, dvec = rep(0,5), Amat = diag(5), bvec = rep(0,5), meq=0, factorized=FALSE)

Here is the resulting error:

Error in solve.QP(Dmat = -mat, dvec = rep(0, 5), Amat = diag(5), bvec = rep(0, : matrix D in quadratic function is not positive definite!

josliber
  • 43,891
  • 12
  • 98
  • 133
  • 1
    `quadprog` requires a positive definite matrix in the objective, so you can't use `quadprog` for your problem. R [has many general purpose continuous solvers](https://cran.r-project.org/web/views/Optimization.html); one of these would be better. Right now your example is probably a little too simple. It is `max b'Db/2 s.t. b >= 0`; given that `D` is positive definite, this is unbounded. If you shared more details about your problem structure, we could give more guidance. – josliber Feb 04 '20 at 15:46
  • 1
    `quadpro` requires the matrix to be positive definite as otherwise `x'Ax` does not have a finite minimum. To be able to maximize a quadratic form it needs to be negative definite. Then you can apply `quadprog` to `-A` to find a minimum which is meant as a maximum. – Hans W. Feb 06 '20 at 18:23

0 Answers0