# NOT RUN {
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)
# }
Run the code above in your browser using DataLab