Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

predict.polynomial

Calculate the value of a ‘polynomial’ for real, complex and matrix argument


Description

The ‘polynom::predict.polynomial()’ method works for real, complex and matrix argument also. But in the case of matrix argument it uses the elementwise calculations instead the matrix multiplication. The ‘polyMatrix::predict.polynomial()’ calculate the result by the usual matrix product definition except the case, when the parameter meth equals by "as.in.the.polynom.package".

Usage

## S3 method for class 'polynomial'
predict(object,M,meth=c("as.matrix","as.in.the.polynom.package"),...)

Arguments

object

a numeric, matrix or polyMatrix class object

M

a polynomial class object

meth

If the value of this parameter as the default, "as.matrix" then calculate by matrix multiplications. Otherwise it calculate by elementwise multiplications.

...

additional arguments

Value

The is a numeric, numeric, matrix or polyMatrix class object depending on the class of the input

See Also

Examples

p <- polynom::polynomial(1:3)
p # 1 + 2*x + 3*x^2

# predict a polynom for real values
predict(p,1) # 6

# predict a polynom for complex values
predict(p,1i) # -2+2i

# predict a polynom for matrices
M <- matrix(c(1,-1),2,2);
M
predict(p,M) # 3,2 \ -2, -1

# mimiking the elementwise calculation of the masked "polynom::predict" method
predict(p,M,meth="as.in.") # 6, 6 \ 2, 2

# predict a polynom for a polynomial matrix
pM <- polyMgen.d(2,2, rawData=ch2pn(c("1","x^2","x","0")))
pM # 1, x \ x^2, 0
predict(p,pM) # method: predict.polyMatrix()
# 6 + 3*z^3  5*z
# 5*z^2      1 + 3*z^3

# ---
# predict the result of a linear model
x <- c(1,3,4,1,0);
y <- c(27,81,54,27,18)
predict(lm(y~x)) # method: predict.lm()
# 31 57 70 31 18

# clean up
# rm(p, M, pM, x, y)

polyMatrix

Infrastructure for Manipulation Polynomial Matrices

v0.3.1
MIT + file LICENSE
Authors
Tamas Prohle [aut], Peter Prohle [aut], Nikolai Ryzhkov [aut, cre], Ildiko Laszlo [aut] (<https://orcid.org/0000-0003-2324-8183>), Ulas Onat Alakent [ctb]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.