Skip to content

Constraints in Quadprog

1 message · Spencer Graves

#
If I understand correctly, you are asking how solve.QP interprets the 
arguments.  I clarified this by constructing a problem I could work 
manually but that was sophisticated enough to seemingly answer your 
question:  minimize (x1^2+x2^2) subject to (x1+x2)=1.  I computed 
manually that the answer should be x1=x2=0.5.  (I used Lagrange 
multipliers, because that's the first thing that entered my head. 
However, I also could have substituted (1-x1) for x2 or used the 
"solver" in MS Excel.)

	  After reading the documentation and trying something that gave an 
error message, I got the following:

 > (QP1 <- solve.QP(Dmat=diag(2), dvec=rep(0,2),
+   Amat=matrix(rep(1,2), c(2,1)), bvec=1, meq=1))
$solution
[1] 0.5 0.5

$value
[1] 0.25

$unconstrainted.solution
[1] 0 0

$iterations
[1] 2 0

$iact
[1] 1

	  If this does not answer your question, have you studied the example 
with "?solve.QP"?  If this is still not adequate, PLEASE do read the 
posting guide! http://www.R-project.org/posting-guide.html and submit 
another post;  I believe that people who follow that guide generally get 
more useful replies quicker.

	  hope this helps.
	  spencer graves
Serguei Kaniovski wrote: