[R] help with optimize statement

tom wright tom at maladmin.com
Fri Feb 24 14:43:07 CET 2006


Can some help me spot what I'm doing wrong here.
I have two equations, one a michalis-menton eqn and one a straight line.
I need to work out where they cross.

I created the function:
solveEqn<-function(x,vals){
Vmax<-vals[1]
Ks<-vals[2]
m<-vals[3]
c<-vals[4]
    diff<-0
    mmVal<-exp(Vmax+x/(Ks+x))
    slVal<-x*m+c

    diff<-mmVal-slVal
    return(diff)
}
> optim(c(200,500),solveEqn,vals=c(2.4591201,-0.4015233,5.924e-5,3.437))
Error in optim(c(200, 500), solveEqn, vals = c(2.4591201, -0.4015233,  :
        objective function in optim evaluates to length 2 not 1


If i replace return(diff) with sum(diff) then the optim function runs
but returns the wrong value (which should be about 290).

Many thanks 
Tom




More information about the R-help mailing list