Why is there this error while trying to integrate a function in R?

Viewed 27
a <- 2
b <- 3
T <- 10
fun1 <- function(a,b,T) {
  return(a*(log(b+T)))
}
Answer1 <- integrate(fun1,
                     lower = 0,
                     upper=T)

I'm trying to find the integral of a function () = ∙ ln( + ). It does, however, return an error no matter what I do. The error is "Error in f(x, ...) : argument "b" is missing, with no default"

1 Answers

First of all, I wouldn't recommend using T as a variable name. Your function suggests that you only have one independent variable called "t", so you should only mention that variable in function(t) because "a" en "b" are constants. Here is a reproducible example:

a <- 2
b <- 3
#t <- 10
fun1 <- function(t) {
  return(a*(log(b+t)))
}
Answer1 <- integrate(fun1,
                     lower = 0,
                     upper=T)
Answer1
#> 2.498681 with absolute error < 2.8e-14

Created on 2022-09-24 with reprex v2.0.2

Related