Sorry for the not enough info. the code seems to work for 10 or so variables but stops optimizing if i give it anymore than that.
#Load data Data <- read.table......csv',head=TRUE,sep=",",stringsAsFactors = FALSE) #Load goal variables. this is what i'm trying to minimize to Z<-read.table....csv',head=TRUE,sep=",",stringsAsFactors = FALSE) #set array Y<-array(0,dim=c(nrow(Data),15)) #load applicable values into array for(j in 1:15){ for(k in 1:nrow(Data)){ Y[k,j] = Data[k,3+j] } } #set constraint A <- array(0,dim=c(2+nrow(Y),nrow(Y))) B <- array(0,dim=c(2+nrow(Y),1)) # Constraint for total = 100% for(w in 1:nrow(Data)){ A[1,w] = 1 A[2,w] = -1 } #each value in x must be greater than 0 for(i in 1:nrow(Data)){ A[i+2,i] = 1 B[i+2] = -.00001 } B[1,1] = .999 B[2,1] = -1.001 #initial guess p0<- array(0,dim=c(nrow(Data))) p0[1] = .5 p0[2] = .5000001 #objective function minsquare<-function(x,Y,Z){sum((x %*% Y - Z)^2)} #Optimization with constraints constrOptim(p0,minsquare,Y=Y,Z=Z,NULL,ui=A,ci=B) here is the code. -- View this message in context: http://www.nabble.com/Stuck-using-constrOptim-tp23197912p23200221.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ 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.