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

Description Usage Arguments Details Value Author(s) References Examples

View source: R/findallroots.R

Description

find all roots of the equation,including complex roots

Usage

1
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

Details

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

Value

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

Author(s)

Bingpei Wu

References

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

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
##---- 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))
  }

FindAllRoots documentation built on May 2, 2019, 6:34 a.m.