Error: non-numerical argument for binary operator

Asked

Viewed 4,316 times

3

I’m working on the following code:

temperatura<-function(t){6/pi*atan(40*t-740)+7}#temperatura em função do tempo

Ratkowski<-function(t){0.04291^2*(temperatura(t)-3.57877)^2*(1-exp(1.13744*(temperatura(t)-41.64632)))^2}#modelo dinâmico

fq<-function(t){0.1*exp(Ratkowski(t))}

funcao<-function(t){integrate(fq,0,t)}

I’m trying to build a new function defined as

funcao02<-function(t){funcao(t)/(funcao(t)+1)}

The following error is being generated:

Error in funcao + 1 : non-numerical argument for binary operator

I believe the value of funcao (resultado da integral) is not being considered as numerical. Is that right? How to solve the problem?

1 answer

3


Note that the result of funcao is not numerical:

funcao(10)
1.000333 with absolute error < 1.1e-14

It is necessary to extract the numerical value (1.000333) of this result. One way to do this is to find out where the R, inside funcao(10), store this numeric value. Do this via the command names:

names(funcao(10))
[1] "value"        "abs.error"    "subdivisions" "message"      "call" 

To extract only the numerical value generated by funcao, spin

funcao(10)$value
[1] 1.000333

So just correct the funcao02 to reflect this change:

funcao02 <- function(t){funcao(t)$value/(funcao(t)$value+1)}
funcao02(10)
[1] 0.5000831

Browser other questions tagged

You are not signed in. Login or sign up in order to post.