How to Apply the uniroot() Function in R (Example Code)
In this article you’ll learn how to apply the uniroot function in the R programming language.
Creation of Example Data
f <- function(x) { # Create user-defined function in R y <- 2 * x^3 - 10 * x^2 + 50 * x - 20000 } |
f <- function(x) { # Create user-defined function in R y <- 2 * x^3 - 10 * x^2 + 50 * x - 20000 }
Example: Get Root (Zero) of Function Using uniroot() Command
uniroot(f, interval = c(- 200, 200))$root # Find one dimensional root # [1] 22.92958 |
uniroot(f, interval = c(- 200, 200))$root # Find one dimensional root # [1] 22.92958