Please read the help page carefully, the very first line that describes the function says, "Minimise a function subject to linear inequality constraints". OP has a problem with equality constraints: sum(x) = 1.
Furthermore, if you want to solve a QP problem then it is better to use a dedicated QP algorithm than to use a general-purpose nonlinear optimization algorithm. Ravi. ____________________________________________________________________ Ravi Varadhan, Ph.D. Assistant Professor, Division of Geriatric Medicine and Gerontology School of Medicine Johns Hopkins University Ph. (410) 502-2619 email: rvarad...@jhmi.edu ----- Original Message ----- From: "Peng, C" <cpeng....@gmail.com> Date: Tuesday, September 28, 2010 7:58 pm Subject: Re: [R] constrained optimization -which package? To: r-help@r-project.org > constrOptim() can do linear and quadratic programming problems! See > the > following example from the help document. > > ## Solves linear and quadratic programming problems > ## but needs a feasible starting value > # > # from example(solve.QP) in 'quadprog' > # no derivative > fQP <- function(b) {-sum(c(0,5,0)*b)+0.5*sum(b*b)} > Amat <- matrix(c(-4,-3,0,2,1,0,0,-2,1),3,3) > bvec <- c(-8,2,0) > constrOptim(c(2,-1,-1), fQP, NULL, ui=t(Amat),ci=bvec) > # derivative > gQP <- function(b) {-c(0,5,0)+b} > constrOptim(c(2,-1,-1), fQP, gQP, ui=t(Amat), ci=bvec) > > ## Now with maximisation instead of minimisation > hQP <- function(b) {sum(c(0,5,0)*b)-0.5*sum(b*b)} > constrOptim(c(2,-1,-1), hQP, NULL, ui=t(Amat), ci=bvec, > control=list(fnscale=-1)) > > -- > View this message in context: > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help@r-project.org mailing list > > PLEASE do read the posting guide > and provide commented, minimal, self-contained, reproducible code. ______________________________________________ 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.