[R] Constraints in Quadprog
Spencer Graves
spencer.graves at pdf.com
Fri Dec 2 02:44:32 CET 2005
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:
> I'm having difficulty figuring out how to implement the
> following set of constraints in Quadprog:
>
> 1). x1+x2+x3+x4=a1
> 2). x1+x2+x5+x6=a2
> 3). x1+x3+x5+x7=a3
> 4). x1+x2=b1
> 5). x1+x3=b2
> 6). x1+x5=b3
>
> for the problem: MIN (x1-c1)2+(x2-c2)2+...+(x8-c8)2.
>
> As far a I understand, "solve.QP(Dmat, dvec, Amat, bvec, meq=0,
> factorized=FALSE)" reads contraints using an element-by-element
> multiplication, i.e. Amat'*x, not using the matrix-product, i.e.
> Amat'%*%x, required for the sums on the left-hand-side of 1-6).
>
> I would very much appreciate a suggestion on this problem.
>
> Thank you,
> Serguei Kaniovski
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
--
Spencer Graves, PhD
Senior Development Engineer
PDF Solutions, Inc.
333 West San Carlos Street Suite 700
San Jose, CA 95110, USA
spencer.graves at pdf.com
www.pdf.com <http://www.pdf.com>
Tel: 408-938-4420
Fax: 408-280-7915
More information about the R-help
mailing list