Learn R Programming

FindAllRoots (version 1.0)

allroots: Find all roots of the equation,including complex roots.

Description

find all roots of the equation,including complex roots

Usage

allroots(a, b)

Arguments

a
vector of coefficients of the equation
b
vector of exponention of the equation,One one corresponding with a mentioned above

Value

all roots of the equation,including complex roots.Besides,the inaccuracy error of the roots is also given

Details

a should be one one corresponding with b,or there might lead to wrong results

References

a passage about finding all roots,whose author is Dequan Shang

Examples

Run this code
##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--	or do  help(data=index)  for the standard data sets.
a=c(2,-1,-13,-1,-5)
b=c(4:0)
allroots(a,b)

## The function is currently defined as
function (a, b) 
{
    a1 = a
    b1 = b
    n = length(b) - 1
    a = a/a[1]
    b = matrix(0, ncol = n, nrow = n)
    for (i in 1:(n - 1)) b[i, i + 1] = 1
    for (i in 1:n) b[n, i] = -a[n + 2 - i]
    c = eigen(b)
    print(c$values)
    print("inaccuracy error")
    print(f(c$values, a1, b1))
  }

Run the code above in your browser using DataLab