mm... I also noticed the function you wrote didn't use parenthesis, mixed b and c and used different names for K. Your code is a great exercise in debugging (no offense intended :) )
Try using: bird<-bird.density[0] # I assume this exists eqn<- function(K1, b1 = 1.22, c1 = .55) { b<-1.22 c<-0.55 bird <- c1*bird + b1*bird*(1-b1*bird)*bird/K1 return(bird) } k1<-optim(c(0,10),eqn) ----------------Contact Details:------------------------------------------------------- Contact me: tal.gal...@gmail.com | 972-52-7275845 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | www.r-statistics.com (English) ---------------------------------------------------------------------------------------------- On Mon, Apr 26, 2010 at 11:08 AM, Tal Galili <tal.gal...@gmail.com> wrote: > Hi Charlotte , > > I can't reproduce your code, but skimming through it - > It would appear that: > 1) in > eqn1<- function(K1, bird) > you didn't define "bird" (you did define it before the function, so I'd > suggest just removing it from the function call like this: > eqn1<- function(K1) > > 2) you didn't "return" and value at the end of the function. > > 3) you use different name in optim then in the function you made. > > 4) I see no point for you to use the for loop. > > > > Consider trying the following code: > > b<-1.22 > c<-0.55 > bird<-bird.density[0] # I assume this exists > eqn<- function(K1, bird) { > > b<-1.22 > c<-0.55 > bird <- 0.55*bird + b*bird*1-b*bird*bird/K > return(bird) > } > > k1<-optim(c(0,10),eqn) > > > > ----------------Contact > Details:------------------------------------------------------- > Contact me: tal.gal...@gmail.com | 972-52-7275845 > Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | > www.r-statistics.com (English) > > ---------------------------------------------------------------------------------------------- > > > > > On Mon, Apr 26, 2010 at 9:00 AM, Charlotte Chang <c.h.w.ch...@gmail.com>wrote: > >> optim > > > [[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.