Search code examples
rquadprog

Incompatible types in quadprog R


I am new to R and am trying to solve a QP problem using R. I keep getting the following error :

Amat and dvec are incompatible.

here my code:

d <- 4

Fr <- as.vector(Fr) ;
Aeq <- matrix(data=1, nrow=1, ncol=d) %*% U
Amat <- rbind(Aeq,U);
bv <- vector( mode= "integer", length = nrow(Amat))
bv[1] <- 1
neq <- 1

output_qp <- solve.QP(S, Fr, Amat, bv, neq, factorized=FALSE)

Solution

  • The ?solve.QP doc mentions

       problems of the form min(-d^T b + 1/2 b^T D b) with the constraints A^T b >= b_0.
    

    So at least you have to change this : Amat by t(Amat)

     output_qp <- solve.QP(S, Fr, t(Amat), bv, neq, factorized=FALSE)