1

I'm using R software quadprog. enter image description here

to solve the following optimization:

Dmat <- matrix(c(1,1.5,1.5,5),nrow=2,ncol=2)
dvec <- c(0.5,0)
Amat <- -matrix(c(3,15,2,-3),nrow=2,ncol=2)
bvec <- matrix(c(-2,1),nrow=2,ncol=1)

solve.QP(Dmat,dvec,Amat,bvec)

the solution that I get from solving the above problem is:

$`solution`
[1] -0.2307692  0.1794872

$value
[1] 0.1604208

The correct solution is

$`par`
[1] -0.8064516  0.2096774

$value
[1] -0.04032258

What am I doing wrong?

forecaster
  • 1,084
  • 1
  • 14
  • 35

1 Answers1

1

You have to:

  • double Dmat
  • negate dvec
  • transpose Amat
  • negate bvec

That is:

Dmat <- matrix(c(2,3,3,10),nrow=2,ncol=2)
dvec <- c(-0.5,0)
Amat <- -matrix(c(3,15,2,-3),nrow=2,ncol=2,byrow=TRUE)
bvec <- -matrix(c(-2,1),nrow=2,ncol=1)

> solve.QP(Dmat,dvec,Amat,bvec)
$solution
[1] -0.8064516  0.2096774

$value
[1] -0.04032258
Stéphane Laurent
  • 75,186
  • 15
  • 119
  • 225