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]]

______________________________________________
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.

Reply via email to