[R] polyroot

Richard O'Keefe r@oknz @end|ng |rom gm@||@com
Fri Oct 3 13:28:12 CEST 2025


Take the leading terms: x^11 + 1000*x^10.  Set that equal to zero.
The roots are 0 and -1000.
The 1.1e-16 is clearly rounding error.  -999 looks like a good
approximation to a root.
Take the leading terms x^11 + 1000*x^10 + 500*x^9.  This is x^9*(x^2 +
1000x + 500)..
We get quadratic roots -999.499749749687 -and 0.5002502503129382
Root [11] is looking better and better.
For x close to -1000, the "1" in the polynomial is 1e-33 of x^11, so
this is ill-conditioned.


On Fri, 3 Oct 2025 at 04:56, tgs77m--- via R-help <r-help using r-project.org> wrote:
>
> Colleagues,
>
> f <- function(x) ( x^11 + 1000*x^10 + 500 *x^9 + 1 ) ^0.01
> coeffs <- c(1, rep(0, 8), 500, 1000, 1)
> roots <- polyroot(coeffs)
>
> # output
>
> [1]    0.25770068+3.958197e-01i
>  [2]   -0.34615184+3.782848e-01i
>  [3]   -0.04089779-4.838134e-01i
>  [4]    0.44124314-1.517731e-01i
>  [5]   -0.04089779+4.838134e-01i
>  [6]   -0.56201931-1.282822e-01i
>  [7]   -0.34615184-3.782848e-01i
>  [8]    0.44124314+1.517731e-01i
>  [9]   -0.56201931+1.282822e-01i
> [10]    0.25770068-3.958197e-01i
> [11] -999.49974975+1.110223e-16i
>
> [11] -999.49974975+1.110223e-16i makes no sense since f is always greater
> than 0
>
> why does polyroot output [11] -999.49974975+1.110223e-16i ?
>
> Thanks,
>
> Thomas Subia
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide https://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list