[英]quadratic programming in R matrix form
I'm using R
software quadprog
.我正在使用
R
软件quadprog
。
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?我究竟做错了什么?
You have to:你必须:
Dmat
Dmat
dvec
dvec
Amat
Amat
bvec
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.