ABUJEAN
ABUJEAN

Reputation: 41

how to define a variable as an object of class polynom

I am trying to define my independent variable as an object of class "polynom" using polynum() function.

My function is: y = x^3 - 3x^2 - 2x +7

Can someone help me fix this I am a beginner in this language and any suggestion of a good source to learn more about R will be appreciated.

My code looks like the following.

library('PolynomF')
polynom(x)
p <- function(x){
  x^3 - 3*x^2 - 2*x +7
}

Upvotes: 1

Views: 150

Answers (1)

jay.sf
jay.sf

Reputation: 73272

We define the coefficients.

(p <- PolynomF::polynom(c(7, 2, 3, 1)))
# 7 + 2*x + 3*x^2 + x^3 

class(p)
# [1] "polynom"

Upvotes: 1

Related Questions