Skip to content
Prev 324752 / 398503 Next

how to compute maximum of fitted polynomial?

David Winsemius <dwinsemius <at> comcast.net> writes:
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
Sorry, yes of course, it should be `library(polynom)`.
Somehow I'm making this mistake again and again.
And one has to be a bit careful about complex roots.


Hans Werner