Hi Jiting, On Fri, 15 Mar 2013, Jiting Xu <jiting...@gmail.com> writes:
> Hi list: > > This is my first time to post my question on the list. Thanks for your > help. > > I am solving a quadratic programming using R. Here is my question: > > w = arg min 0.5*w'Mw - w'N > s. t. sum(w) = 1; > w>0 > > note: w is weight vector, each w_i must >=0, and the sum of w =1. > > Here is my R code: > > A <-matrix(c(2.26,1.26,1.12,1.12,2.27,1.13,1.12,1.13,2.2),3,3); shouldn't that be a symmetric matrix? > B <- c(0.007459281,0.007448885,0.007447850); > M <-nrow(A); > Amat <- cbind(rep(1,M), diag(M)); > bvec <- c(1,rep(0,M)) ; > meq <- 1; > > min <- solve.QP(Dmat=A,dvec=B,Amat=Amat,bvec=bvec,meq=meq) > > init_prior.weig <-min$solution; > > cat("weight = ",init_prior.weig,"\n" ) > > > > My question is: When I tried "big" matrix A and B, I get some negative > weights. I think I already put the constraints(w>0). I want all weights > > 0; > Could you post an example in which you get negative weights? Before you do: how large, in absolute terms, are these negative values? If they are like -1e-15, then they are simply "numeric noise". (And you have specified the constraint w>=0. If you really want w>0 in a meaningful sense, you will have to be more specific: you will have to set w > eps, in which eps is the minimal weight that would be sufficiently greater than zero in your application.) > Do I put the right constraints ? > > Could you help figure out it. Thanks in advance. > > Jiting > Regards, Enrico -- Enrico Schumann Lucerne, Switzerland http://enricoschumann.net ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.