rnumerical-methods

Fastest numerical solution of a real cubic polynomial?


R question: Looking for the fastest way to NUMERICALLY solve a bunch of arbitrary cubics known to have real coeffs and three real roots. The polyroot function in R is reported to use Jenkins-Traub's algorithm 419 for complex polynomials, but for real polynomials the authors refer to their earlier work. What are the faster options for a real cubic, or more generally for a real polynomial?


Solution

  • Fleshing out Arietta's answer above:

    > a <- c(1,3,-4)
    > m <- matrix(c(0,0,-a[1],1,0,-a[2],0,1,-a[3]), byrow=T, nrow=3)
    > roots <- eigen(m, symm=F, only.values=T)$values
    

    Whether this is faster or slower than using the cubic solver in the GSL package (as suggested by knguyen above) is a matter of benchmarking it on your system.