Your constraints are non-sensical.  The only way for these constraints to be satisfied is for two of the parameters to be 0 and the other two to be 1.



Please spend time to formulate your problem correctly, before imposing on others' time.



Ravi

________________________________
From: Axel Urbiz [axel.urbiz@gmail.com]
Sent: Sunday, February 10, 2013 3:16 PM
To: R-help@r-project.org; Ravi Varadhan
Subject: Constrained Optimization in R (alabama)

Dear List,

I'm trying to solve this simple optimization problem in R. The parameters are the exponents to the matrix mm. The constraints specify that each row of the parameter matrix should sum to 1 and their product to 0. I don't understand why the constraints are not satisfied at the solution. I must be misinterpreting how to specify the constrains somehow.


library(alabama)

ff <- function (x) {
  mm <- matrix(c(10, 25, 5, 10), 2, 2)
  matx <- matrix(x, 2, 2)
  -sum(apply(mm ^ matx, 1, prod))
}


### constraints

heq <- function(x) {
  h <- rep(NA, 1)
  h[1] <- x[1] + x[3] -1
  h[2] <- x[2] + x[4] -1
  h[3] <- x[1] * x[3]
  h[4] <- x[2] * x[4]
  h
}

res <- constrOptim.nl(par = c(1, 1, 1, 1), fn = ff,
                      heq = heq)
res$convergence #why NULL?
matrix(round(res$par, 2), 2, 2)  #why constraints are not satisfied?

Axel.

	[[alternative HTML version deleted]]

