Skip to content
Prev 324734 / 398503 Next

how to compute maximum of fitted polynomial?

Bert Gunter <gunter.berton <at> gene.com> writes:
In the case of polynomials, "elementary math ... methods" can actually be
executed with R:

    library(polynomial)                 # -6 + 11*x - 6*x^2 + x^3
    p0 <- polynomial(c(-6, 11, -6, 1))  # has zeros at 1, 2, and 3
    p1 <- deriv(p0); p2 <- deriv(p1)    # first and second derivative
    xm <- solve(p1)                     # maxima and minima of p0
    xmax = xm[predict(p2, xm) < 0]      # select the maxima
    xmax                                # [1] 1.42265

Obviously, the same procedure will work for polynomials p0 of higher orders.

Hans Werner