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!