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
}
integrate(own_fun, lower = - 1.96, upper = 1.96)  # Using integrate()
# 58.27821 with absolute error < 6.5e-13

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed

Menu
Top