0

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?

torvin
  • 43
  • 5

1 Answers1

0

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")

Zheyuan Li
  • 71,365
  • 17
  • 180
  • 248