Error non-numeric argument to mathematical function

2

Good afternoon, I have the following code in R

funcao<-function(delta) {delta}
    Intensity2AccumulationFactor<-function(delta,s,t){
    int<-function(s,t) {integrate(funcao,s,t)}
    p=int(s,t)
    b=c(p)
    a=exp(b)
    print(a)
}

Testing gives the following error:

  

Intensity2AccumulationFactor (function, 0,1) Error in exp (b): non-numeric argument to mathematical function

Can someone help me?

The goal is to calculate 1/(-integral(delta)) between s and t .

    
asked by anonymous 21.03.2015 / 16:52

1 answer

3

Some comments:

Your code indicates that a non-numeric value was passed to exp() because you did not get the output you wanted from the int() function. You should use integrate(funcao,s,t)$value to read the value of the integration, because integrate() returns a integrate object.

The line b=c(p) does not do anything too much, c() does nothing if it only receives one argument.

Are you sure that funcao<-function(delta) {delta} is right? This function does nothing, simply returns the parameter that was passed to it.

Although you may not have understood what you want with delta , you can simplify your code like this:

funcao<-function(delta) {delta}

Intensity2AccumulationFactor <- function(s,t){  
  exp(integrate(funcao,s,t)$value)    
}

Intensity2AccumulationFactor(0, 3)

The variable delta you passed Intensity2AccumulationFactor was not used, and the result in this case is the exponential integration of s to t .

    
22.03.2015 / 04:05