[R] complex conjugates roots from polyroot?

Spencer Graves spencer.graves at pdf.com
Fri Nov 23 18:07:59 CET 2007


Hi, All: 

      Is there a simple way to detect complex conjugates in the roots 
returned by 'polyroot'?  The obvious comparison of each root with the 
complex conjugate of the next sometimes produces roundoff error, and I 
don't know how to bound its magnitude: 

(tst <- polyroot(c(1, -.6, .4)))
tst[-1]-Conj(tst[-2])
[1] 3.108624e-15+2.22045e-16i
abs(tst[-1]-Conj(tst[-2]))/abs(tst[-1])
1.971076e-15
.Machine$double.neg.eps
1.110223e-16

      Testing (abs(tst[-1]-Conj(tst[-2]))/abs(tst[-1]) < 
(20*.Machine$double.neg.eps)) would catch this example, but it might not 
catch others. 
   
      The 'polyroot' help page says, "See Also ... the 'zero' example in 
the demos directory."  Unfortunately, I've so far been unable to find 
that. 

      Any suggestions? 
      Thanks in advance. 
      Spencer Graves



More information about the R-help mailing list