By any chance is anyone aware of an R function that duplicates Octave's poly
function?
Here is a description of Octave's poly function:
Function File: poly (A)
If A is a square N-by-N matrix, `poly (A)' is the row vector of
the coefficients of `det (z * eye (N) - a)', the characteristic
polynomial of A. As an example we can use this to find the
eigenvalues of A as the roots of `poly (A)'.
roots(poly(eye(3)))
=> 1.00000 + 0.00000i
=> 1.00000 - 0.00000i
=> 1.00000 + 0.00000i
In real-life examples you should, however, use the `eig'
function for computing eigenvalues.
If X is a vector, `poly (X)' is a vector of coefficients of the
polynomial whose roots are the elements of X. That is, of C is a
polynomial, then the elements of `D = roots (poly (C))' are
contained in C. The vectors C andD are, however, not equal due
to sorting and numerical errors.
Thanks again for any insights and feedback.
David Winsemius
2009-Nov-28 15:23 UTC
[R] R function that duplicates Octave's poly function?
On Nov 28, 2009, at 9:33 AM, Jason Rupert wrote:> > By any chance is anyone aware of an R function that duplicates > Octave's poly function? > > Here is a description of Octave's poly function: > > Function File: poly (A) > If A is a square N-by-N matrix, `poly (A)' is the row vector of > the coefficients of `det (z * eye (N) - a)', the characteristic > polynomial of A. As an example we can use this to find the > eigenvalues of A as the roots of `poly (A)'. > roots(poly(eye(3))) > => 1.00000 + 0.00000i > => 1.00000 - 0.00000i > => 1.00000 + 0.00000i > In real-life examples you should, however, use the `eig' > function for computing eigenvalues. > > If X is a vector, `poly (X)' is a vector of coefficients of the > polynomial whose roots are the elements of X. That is, of C is a > polynomial, then the elements of `D = roots (poly (C))' are > contained in C. The vectors C andD are, however, not equal due > to sorting and numerical errors. > > Thanks again for any insights and feedback.RSiteSearch("characteristic polynomial")> > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.David Winsemius, MD Heritage Laboratories West Hartford, CT