Skip to content
Related Articles

Related Articles

Improve Article
Calculate the Root of a Equation within an interval in R Programming – uniroot() Function
  • Last Updated : 12 Jun, 2020

uniroot() function in R Language is used to calculate the root of an equation with the lower and upper range of the interval passed as arguments.

Syntax: uniroot(fun, interval, lower, upper)

Parameters:
fun: function with the equation
interval: with upper and lower range of root
lower: lower end point of the interval
upper: upper end point of the interval

Example 1:




# R program to calculate root of an equation
  
# Function with equation
fun <- function(x) {2 * x ^ 2 - 4 * x -10}
  
# Calling uniroot() function
uniroot(fun, lower = 0, upper = 4)

Output:

$root
[1] 3.449485

$f.root
[1] -4.310493e-05

$iter
[1] 5

$init.it
[1] NA

$estim.prec
[1] 6.103516e-05

Example 2:




# R program to calculate root of an equation
  
# Function with equation
fun <- function(x) {2 * x ^ 2 - 4 * x -10}
  
# Calling uniroot() function
uniroot(fun, c(0, 4))$root
uniroot(fun, lower = -4, upper = 0)$root

Output:

[1] 3.449485
[1] -1.44949
My Personal Notes arrow_drop_up
Recommended Articles
Page :