[R] polyroot behaviour
Spencer Graves
@pencer@gr@ve@ @end|ng |rom e||ect|vede|en@e@org
Fri Oct 3 04:25:45 CEST 2025
I agree with Deepayan.
This example reveals an opportunity for improving the polyroot algorithm:
** Any polynomial of odd degree with real coefficients must have at
least one real root. This example has only one, which is reported as
-999.49974975+1.110223e-16i: The imaginary part is clearly round-off.
** Moreover, any complex roots must come in complex conjugate pairs. In
this example, roots [1] and [10] are complex conjugates, as are roots
[2] and [7], etc. It's interesting to me that the roots are not sorted
to put complex conjugates together.
However, improving this algorithm is probably not worth the time of
anyone who might know enough to actually do it with a reasonable effort ;-)
Spencer Graves
On 10/2/25 12:49, Deepayan Sarkar wrote:
> How can an odd degree polynomial be positive for all x?
>
>
> Deepayan
>
> On Thu, 2 Oct, 2025, 6:14 pm tgs77m--- via R-help, <r-help using r-project.org>
> wrote:
>
>> Colleagues,
>>
>> g <- function(x) ( x^11 + 1000*x^10 + 500 *x^9 + 1 )
>> 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>0 for all x
>>
>> Why does polyroot do this?
>>
>> 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.
>>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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