How to Apply the integrate() Function in R (Example Code)
On this page, I’ll illustrate how to apply the integrate function to compute an integral in R.
Example: Using integrate() to Integrate Own Function in R
own_fun <- function(x) { # Define function my_output <- x / 3 + 7 * x^2 - x^3 + 2 * x^4 } |
own_fun <- function(x) { # Define function my_output <- x / 3 + 7 * x^2 - x^3 + 2 * x^4 }
integrate(own_fun, lower = - 1.96, upper = 1.96) # Using integrate() # 58.27821 with absolute error < 6.5e-13 |
integrate(own_fun, lower = - 1.96, upper = 1.96) # Using integrate() # 58.27821 with absolute error < 6.5e-13