I have had a problem in finding the minimum of a function, the function in
cause is:
curv <- function(a,b){
date <-
read.table("bessa.csv",header=T,sep=";",dec=",")
calP <- (22000)/(1+exp(-(a*date$v+b)))
err <- (calP-date$P)^2
return(sum(err))
}
It would like to know which function that I must use to find the values of
?a? and ?b? that minimize the function curv. I Already tried with the
functions ?optim? and ?nlm?, but without success, perhaps I am not using
them correctly.
Ricardo Bessa
_________________________________________________________________
MSN Busca: f?cil, r?pido, direto ao ponto. http://search.msn.com.br
Ricardo Bessa wrote:> > I have had a problem in finding the minimum of a function, the > function in cause is: >The first, obvious, optimization step is that you are reading the whole table every time you call the function. You should read the table just once. Instead of:> curv <- function(a,b){ > date <- read.table("bessa.csv",header=T,sep=";",dec=",") > calP <- (22000)/(1+exp(-(a*date$v+b))) > err <- (calP-date$P)^2 > return(sum(err)) > }Try: date <- read.table("bessa.csv",header=T,sep=";",dec=",") curv <- function(a,b){ calP <- (22000)/(1+exp(-(a*date$v+b))) err <- (calP-date$P)^2 return(sum(err)) } Alberto Monteiro