How to Apply the optimize() Function in R (Example Code)

In this R tutorial you’ll learn how to apply the optimize function.

Example: Using optimize() to Perform One Dimensional Optimization in R

the_fun <- function(x) {                   # Creating own function
  7 * x - 3 * x^2 + x^5
}
optimize(the_fun, interval = c(- 5, 5))    # Applying optimize() function
# $minimum
# [1] -4.999944
# 
# $objective
# [1] -3234.824

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