我正在尝试使用 r 为我的投资组合优化类解决二次规划问题。我想将我的答案与书中的答案进行比较。
这是问题所在:
min: t(c)%*%x + .5*t(x)%*%BigC%*%x
st: -x <=0, i=1...5
and: sum(x)=1
这是我的代码:
A = matrix( c( 1,1,1,1,1, -1,0,0,0,0, 0,-1,0,0,0, 0,0,-1,0,0, 0,0,0,-1,0, 0,0,0,0,-1), ncol=5, byrow=T)
b = matrix( c( 1,0,0,0,0,0), ncol=1)
c = matrix( c( 1,-2,3,-4,5), ncol=1)
BigC = matrix( c( 1,0,0,0,0, 0,2,0,0,0, 0,0,3,0,0, 0,0,0,4,0, 0,0,0,0,5), ncol=5, byrow=T)
x0 = matrix( c( 0.2,0.2,0.2,0.2,0.2), ncol=1)
n = 5
m = 5
q = 1
solve.QP( Dmat=BigC, dvec=t(c), Amat=t(A), bvec=t(b), meq=1)
但它会引发以下错误:
Error in solve.QP(Dmat = BigC, dvec = t(c), Amat = t(A), bvec = t(b), :
constraints are inconsistent, no solution!
任何帮助将不胜感激。谢谢!