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:
fun < - function(x) { 2 * x ^ 2 - 4 * x - 10 }
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:
fun < - function(x) { 2 * x ^ 2 - 4 * x - 10 }
uniroot(fun, c( 0 , 4 ))$root
uniroot(fun, lower = - 4 , upper = 0 )$root
|
Output:
[1] 3.449485
[1] -1.44949