Find roots or zeros of a Polynomial in R Programming – polyroot() Function
Last Updated :
12 Jun, 2020
polyroot()
function in R Language is used to calculate roots of a polynomial equation.
A polynomial equation is represented as,
p(x) = (z1) + (z2 * x) + (z3 * x2) +...+ (z[n] * xn-1)
Syntax: polyroot(z)
Parameters:
z: Vector of polynomial coefficients in Increasing order
Example 1:
x1 < - c( 1 , 2 , 3 )
x2 < - c( - 8 , 4 , - 2 )
x3 < - c( 12 , - 2 , 3 )
polyroot(x1)
polyroot(x2)
polyroot(x3)
|
Output:
[1] -0.3333333+0.4714045i -0.3333333-0.4714045i
[1] 1+1.732051i 1-1.732051i
[1] 0.333333+1.972027i 0.333333-1.972027i
Example 2:
polyroot(c( - 3 , 2 ))
polyroot(c( 5 , - 4 , 3 ))
polyroot(c( - 12 , - 3 , 0 , 2 ))
|
Output:
[1] 1.5+0i
[1] 0.666667+1.105542i 0.666667-1.105542i
[1] 2.090489+0.000000i -1.045244+1.333269i -1.045244-1.333269i
Share your thoughts in the comments
Please Login to comment...