I am trying to optimize a simple function, but I want to optimize it for values of k between 0 and 1.
I read the help file for constrOptim function but it is always giving me the error > constrOptim((0.4),simulation,NULL,ui=rbind(c(0,0),c(1,1))) "Error in ui %*% theta : non-conformable arguments" My starting value is 0.4...i also tried c(0.4). simulation is the function name pasted below (It returns a scalar, as per the requirements of the constrOptim call). ui is the bound (0,0) to (1,1) What am I doing wrong? Thanks in advance! > simulation function(k) { sum = 0 firstnum<-runif(1) if(firstnum > k) { sum<-sum + firstnum } else { sum<-sum + firstnum+runif(1) } if(sum>1) { sum<-0 } return (sum) } ______________________________________________ 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.