0

I would like to integrate a function with respect to x,

FUN1 <- function(x, alpha, beta){
 x * alpha - beta
}

FUN2 <- function(alpha beta){
  integrate(FUN1(x, alpha,beta), 0,1)
}

But it does not work.

I also tried

FUN2 <- function(alpha beta){
  integrate(FUN1, 0,1)
}

It does not work either.

John
  • 15,990
  • 10
  • 70
  • 110
zhenhao
  • 33
  • 3

1 Answers1

2

Try this, and also read the docs,

f1 = function(x, a, b) x * a - b

f2 = function(a, b) integrate(f1, 0, 1, a, b) # a and b are passed to f1 through ...

f2(3, 4) 
baptiste
  • 75,767
  • 19
  • 198
  • 294