Error: non-numeric argument for binary operator

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 function + 1: non-numeric argument for binary operator

I believe that the value of funcao (resultado da integral) is not being considered numeric. That's right? How do I solve the problem?

    
asked by anonymous 26.06.2017 / 00:34

1 answer

3

Note that the result of funcao is not numeric:

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

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

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

To extract only the numeric value generated by funcao , run

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
    
26.06.2017 / 01:32