Search code examples
rpolynomials

Vectorize polynomial


How would you vectorize the coefficients of this polynomial? Polynomial

So far i´ve tried using seq(2-1,20) and rep(2-1,20), which is wrong.

Any suggestions?


Solution

  • Are you trying to evaluate a polynomial at x, giving its polynomial coefficients pc? Try PolyVal function defined here: https://stackoverflow.com/a/52658734/4891738.

    For your case, use

    pc <- rep.int(c(-1, 2), 20)
    x <- seq.int(-1, 1, length.out = 101)
    y <- PolyVal(x, pc, nderiv = 0L)
    plot(x, y, type = "l")