title: Portfolio Optimization using r and solve.QP
body: <p>I'm trying to solve a quadratic programming problem for my portfolio optimization class using r.  I would like to compare my answer to one in a book.<br>
  Here is the problem:
      <code>min: t(c)%*%x + .5*t(x)%*%BigC%*%x<br>
      st: -x &lt;=0, i=1...5<br>
      and: sum(x)=1</code></p>
  
  <p>Here is my code:</p>
  
  <pre><code>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)
  </code></pre>
  
  <p>but it throws the following error:</p>
  
  <pre><code>Error in solve.QP(Dmat = BigC, dvec = t(c), Amat = t(A), bvec = t(b),  : 
    constraints are inconsistent, no solution!
  </code></pre>
  
  <p>Any help would be greatly appreciated.  Thanks!</p>