Integrate Function in R (Example) | Using integrate() to Compute Integral

 

This tutorial illustrates how to integrate a user-defined function using integrate() in R.

Table of contents:

Let’s do this…

 

Constructing Example Function

The following manually defined function is used as basement for this R programming tutorial:

my_function <- function(x) {    # Create own function
  out <- 2 * x + x^2 + 5 * x^3
}

 

Example: Applying integrate() to User-Defined Function

This Example shows how to compute the integral of a function using the integrate() command of the R programming language. For this, we need to specify the name of our function, a lower limit, and an upper limit:

integrate(my_function,          # Apply integrate in R
          lower = 0,
          upper = 10)
# 12933.33 with absolute error < 1.4e-10

The RStudio console returns the result: 12933.33 with absolute error < 1.4e-10.

 

Video & Further Resources

I have recently published a video on my YouTube channel, which illustrates the examples of this tutorial. You can find the video below.

 

 

In addition, you might want to have a look at the other tutorials of my website. Please find some other articles below.

 

In this article you learned how to apply the integrate function in R. In case you have any further questions, don’t hesitate to let me know in the comments section.

 

Subscribe to the Statistics Globe Newsletter

Get regular updates on the latest tutorials, offers & news at Statistics Globe.
I hate spam & you may opt out anytime: Privacy Policy.


10 Comments. Leave new

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.

Top