[Rd] PR#751

Peter Dalgaard BSA p.dalgaard@biostat.ku.dk
17 Jan 2001 20:47:27 +0100


Peter Dalgaard BSA <p.dalgaard@biostat.ku.dk> writes:

> > [1]   0+0i   0+0i -10+0i
> > 
> > which aren't all roots of x^3.
> 
> That one is way out, however. Even more "fun":
> 
> > polyroot(c(-100,0,1))
> [1]  10+0i -10+0i
> > x<- polyroot(c(0,0,0,1))
> > x
> [1]   0+0i   0+0i -10+0i
> > x<-polyroot(c(2,1,1))
> > x<- polyroot(c(0,0,0,1))
> > x
> [1]  0.0+0.000000i  0.0+0.000000i -0.5-1.322876i
> 
> I.e. the result of polyroot(c(0,0,0,1)) depends on the previous
> polyroot calculation! So there's more to the problem than numerical
> instability.
> 
> Thanks for pointing it out.

Found and fixed. Unfortunately the code had just forgotten to test for
the case where you end with a zero-degree polynomial after zero-root
removal, so the fix has zero effect on the accuracy issue. 

The fix is simply 

--- src/appl/cpoly.c    2000/11/24 21:34:31     1.20
+++ src/appl/cpoly.c    2001/01/17 19:45:24
@@ -148,6 +148,8 @@
     nn++;
     /*-- Now, global var.  nn := #{coefficients} = (relevant degree)+1 */
 
+    if (nn == 1) return;
+
     /* make a copy of the coefficients and shr[] = | p[] | */
     for (i = 0; i < nn; i++) {
        pr[i] = opr[i];

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk)             FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._